def sonarr_settings(request): template = loader.get_template("viewport/components/server_settings_sonarr.html") # Database values conreq_config = ConreqConfig.get_solo() # Obtain sonarr and radarr information content_manger = ArrManager() sonarr_quality_profiles = [] current_sonarr_anime_quality_profile = "" current_sonarr_tv_quality_profile = "" sonarr_folders = [] current_sonarr_anime_folder = "" current_sonarr_tv_folder = "" if conreq_config.sonarr_enabled: # Sonarr Quality Profiles try: for profile in content_manger.sonarr_quality_profiles(): # Current anime profile if conreq_config.sonarr_anime_quality_profile == profile["id"]: current_sonarr_anime_quality_profile = profile["name"] # Current TV profile if conreq_config.sonarr_tv_quality_profile == profile["id"]: current_sonarr_tv_quality_profile = profile["name"] # List of all dropdown entries sonarr_quality_profiles.append( {"id": profile["id"], "label": profile["name"]} ) except: log.handler("Failed to obtain Sonarr Quality Profiles!", log.ERROR, _logger) # Sonarr Folder Paths try: for path in content_manger.sonarr_root_dirs(): # Current anime dirs if conreq_config.sonarr_anime_folder == path["id"]: current_sonarr_anime_folder = path["path"] # Current TV dirs if conreq_config.sonarr_tv_folder == path["id"]: current_sonarr_tv_folder = path["path"] # List of all dropdown entries sonarr_folders.append({"id": path["id"], "label": path["path"]}) except: log.handler("Failed to obtain Sonarr Folder Paths!", log.ERROR, _logger) context = { "sonarr_quality_profiles": sonarr_quality_profiles, "current_sonarr_anime_quality_profile": current_sonarr_anime_quality_profile, "current_sonarr_tv_quality_profile": current_sonarr_tv_quality_profile, "sonarr_folders": sonarr_folders, "current_sonarr_anime_folder": current_sonarr_anime_folder, "current_sonarr_tv_folder": current_sonarr_tv_folder, } return HttpResponse(template.render(context, request))
def arr_auto_resolve_movie(issue_id, tmdb_id, resolutions): """Queues a background task to automatically resolve a reported issue.""" # TODO: Intelligently resolve based on "resolutions" # Check if auto resolution is turned on conreq_config = ConreqConfig.get_solo() if conreq_config.conreq_auto_resolve_issues: content_manager = ArrManager() content_discovery = TmdbDiscovery() # Grab the movie from Radarr movie = content_manager.get(force_update_cache=True, tmdb_id=tmdb_id) # Delete if movie if it exists if movie: content_manager.delete(radarr_id=movie["id"]) # Add or re-add the movie radarr_params = obtain_radarr_parameters(content_discovery, content_manager, tmdb_id) movie = content_manager.add( tmdb_id=tmdb_id, quality_profile_id=radarr_params["radarr_profile_id"], root_dir=radarr_params["radarr_root"], ) # Search for a replacement content_manager.request(radarr_id=movie["id"]) issue = ReportedIssue.objects.get(pk=issue_id) issue.auto_resolve_in_progress = True issue.save()
def series_modal(request): content_discovery = TmdbDiscovery() content_manager = ArrManager() report_modal = str_to_bool(request.GET.get("report_modal", "false")) # Get the ID from the URL tmdb_id = request.GET.get("tmdb_id", None) tvdb_id = content_discovery.get_external_ids(tmdb_id, "tv").get("tvdb_id") # Check if the show is already within Sonarr's collection requested_show = content_manager.get(tvdb_id=tvdb_id) # If it doesn't already exists, add then add it if requested_show is None: sonarr_params = obtain_sonarr_parameters(content_discovery, content_manager, tmdb_id, tvdb_id) requested_show = content_manager.add( tvdb_id=tvdb_id, quality_profile_id=sonarr_params["sonarr_profile_id"], root_dir=sonarr_params["sonarr_root"], series_type=sonarr_params["series_type"], season_folders=sonarr_params["season_folders"], ) # Keep refreshing until we get the series from Sonarr series = wait_for_series_info(tvdb_id, content_manager) # Series successfully obtained from Sonarr if series: context = { "seasons": series["seasons"], "tmdb_id": tmdb_id, "report_modal": report_modal, } template = loader.get_template("modal/series_selection.html") return HttpResponse(template.render(context, request)) # Sonarr couldn't process this request return HttpResponseNotFound()
def post(self, request, tmdb_id): """Request a movie by TMDB ID.""" content_manager = ArrManager() content_discovery = TmdbDiscovery() # Request the show by the TMDB ID radarr_request( tmdb_id, request, content_manager, content_discovery, ) return Response(self.msg)
def auto_resolve_watchdog(): """Checks to see if an auto resolution has finished completely.""" # Check if auto resolution is turned on conreq_config = ConreqConfig.get_solo() if conreq_config.conreq_auto_resolve_issues: content_manager = ArrManager() issues = ReportedIssue.objects.filter(auto_resolve_in_progress=True) newly_resolved_issues = [] for issue in issues: # Check if TV issues have been resolved if issue.content_type == "tv": content_discovery = TmdbDiscovery() tvdb_id = content_discovery.get_external_ids( issue.content_id, "tv").get("tvdb_id") show = content_manager.get(tvdb_id=tvdb_id) if show and show.get("availability") == "available": issue.auto_resolve_in_progress = False issue.auto_resolved = True issue.resolved = True newly_resolved_issues.append(issue) # Check if movie issues have been resolved if issue.content_type == "movie": movie = content_manager.get(tmdb_id=issue.content_id) if movie and movie.get("hasFile"): issue.auto_resolve_in_progress = False issue.auto_resolved = True issue.resolved = True newly_resolved_issues.append(issue) # Save the resolution status if newly_resolved_issues: ReportedIssue.objects.bulk_update( newly_resolved_issues, ["auto_resolve_in_progress", "auto_resolved", "resolved"], )
def request_content(request): # User submitted a new request if request.method == "POST": request_parameters = json.loads(request.body.decode("utf-8")) log.handler( "Request received: " + str(request_parameters), log.INFO, _logger, ) content_manager = ArrManager() content_discovery = TmdbDiscovery() # TV show was requested if request_parameters["content_type"] == "tv": # Try to obtain a TVDB ID (from params or fetch it from TMDB) tmdb_id = request_parameters["tmdb_id"] tvdb_id = content_discovery.get_external_ids(tmdb_id, "tv").get("tvdb_id") # Request the show by the TVDB ID if tvdb_id: sonarr_request( tvdb_id, tmdb_id, request, request_parameters, content_manager, content_discovery, ) else: return HttpResponseForbidden() # Movie was requested elif request_parameters["content_type"] == "movie": tmdb_id = request_parameters["tmdb_id"] radarr_request(tmdb_id, request, content_manager, content_discovery) # The request succeeded return JsonResponse({"success": True}) return HttpResponseForbidden()
def post(self, request, tmdb_id): """Request a TV show by TMDB ID. Optionally, you can request specific seasons or episodes.""" content_manager = ArrManager() content_discovery = TmdbDiscovery() tvdb_id = content_discovery.get_external_ids(tmdb_id, "tv") request_parameters = json.loads(request.body.decode("utf-8")) # Request the show by the TVDB ID if tvdb_id: sonarr_request( tvdb_id["tvdb_id"], tmdb_id, request, request_parameters, content_manager, content_discovery, ) return Response(self.msg) return Response({ "success": False, "detail": "Could not determine TVDB ID." })
def set_single_availability(card): """Sets the availabily on a single card.""" content_manager = ArrManager() content_discovery = TmdbDiscovery() try: # Compute the availability of a Sonarr card if card.__contains__("tvdbId"): content = content_manager.get(tvdb_id=card["tvdbId"]) if content is not None: card["availability"] = content["availability"] # Compute the availability of a Radarr card elif card.__contains__("tmdbId"): content = content_manager.get(tmdb_id=card["tmdbId"]) if content is not None: card["availability"] = content["availability"] # Compute the availability of TV show elif card.__contains__("name"): external_id = content_discovery.get_external_ids(card["id"], "tv") content = content_manager.get(tvdb_id=external_id["tvdb_id"]) if content is not None: card["availability"] = content["availability"] # Compute the availability of movie elif card.__contains__("title"): content = content_manager.get(tmdb_id=card["id"]) if content is not None: card["availability"] = content["availability"] # Something unexpected was passed in else: log.handler( "Card did not contain content_type, title, or name!", log.WARNING, _logger, ) return card except: log.handler( "Could not determine the availability of card!\n" + str(card), log.ERROR, _logger, ) return card
def arr_auto_resolve_tv(issue_id, tmdb_id, seasons, episode_ids, resolutions): """Queues a background task to automatically resolve a reported issue.""" # TODO: Intelligently resolve based on "resolutions" # Check if auto resolution is turned on conreq_config = ConreqConfig.get_solo() if conreq_config.conreq_auto_resolve_issues: content_manager = ArrManager() content_discovery = TmdbDiscovery() tvdb_id = content_discovery.get_external_ids(tmdb_id, "tv").get("tvdb_id") # Grab the show from Sonarr show = content_manager.get(force_update_cache=True, obtain_season_info=True, tvdb_id=tvdb_id) # Show doesn't exist, add it if not show: # Add the show sonarr_params = obtain_sonarr_parameters(content_discovery, content_manager, tmdb_id) show = content_manager.add( tvdb_id=tvdb_id, quality_profile_id=sonarr_params["sonarr_profile_id"], root_dir=sonarr_params["sonarr_root"], series_type=sonarr_params["series_type"], season_folders=sonarr_params["season_folders"], ) # Show already exists, handle whole show if show and not seasons and not episode_ids: # Delete the whole show content_manager.delete(sonarr_id=show.get("id")) # Re-add the show sonarr_params = obtain_sonarr_parameters(content_discovery, content_manager, tmdb_id, tvdb_id) show = content_manager.add( tvdb_id=tvdb_id, quality_profile_id=sonarr_params["sonarr_profile_id"], root_dir=sonarr_params["sonarr_root"], series_type=sonarr_params["series_type"], season_folders=sonarr_params["season_folders"], ) # Show already exists, handle individual seasons/episodes if show and seasons or episode_ids: # Obtain the seasons and episodes for season in show.get("seasons", []): for episode in season.get("episodes"): if ( # User reported an episode, check if the episode has a file episode.get("id") in episode_ids and episode.get("hasFile") ) or ( # User reported a season, check if the season has episode files to be deleted season.get("seasonNumber") in seasons and episode.get("hasFile")): content_manager.delete( episode_file_id=episode.get("episodeFileId")) # Keep refreshing until we get the series from Sonarr show = wait_for_series_info(tvdb_id, content_manager) # Download new copies content_manager.request(sonarr_id=show.get("id"), seasons=seasons, episode_ids=episode_ids) issue = ReportedIssue.objects.get(pk=issue_id) issue.auto_resolve_in_progress = True issue.save()