def series_modal(request): content_discovery = ContentDiscovery() content_manager = ContentManager() report_modal = request.GET.get("report_modal", False) # Get the ID from the URL tmdb_id = request.GET.get("tmdb_id", None) tvdb_id = request.GET.get("tvdb_id", None) # Determine the TVDB ID if tvdb_id: pass elif tmdb_id: tvdb_id = content_discovery.get_external_ids(tmdb_id, "tv")["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 = content_manager.get(tvdb_id=tvdb_id, obtain_season_info=True, force_update_cache=True) if series is None: series_fetch_retries = 0 while series is None: if series_fetch_retries > MAX_SERIES_FETCH_RETRIES: break series_fetch_retries = series_fetch_retries + 1 series = content_manager.get(tvdb_id=tvdb_id, obtain_season_info=True, force_update_cache=True) log.handler( "Sonarr did not have the series information! Conreq is waiting...", log.INFO, __logger, ) context = generate_context({ "seasons": series["seasons"], "tvdb_id": tvdb_id, "report_modal": report_modal }) template = loader.get_template("modal/series_selection.html") return HttpResponse(template.render(context, request))
def series_modal(user, tmdb_id=None, tvdb_id=None): # Validate login status if user.is_authenticated: content_discovery = ContentDiscovery() content_manager = ContentManager() # Determine the TVDB ID if tvdb_id is not None: pass elif tmdb_id is not None: tvdb_id = content_discovery.get_external_ids(tmdb_id, "tv")["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 = content_manager.get(tvdb_id=tvdb_id, obtain_season_info=True) if series is None: series_fetch_retries = 0 while series is None: if series_fetch_retries > MAX_SERIES_FETCH_RETRIES: break series_fetch_retries = series_fetch_retries + 1 sleep(0.5) series = content_manager.get(tvdb_id=tvdb_id, obtain_season_info=True, force_update_cache=True) log.handler( "Retrying content fetch!", log.INFO, __logger, ) context = generate_context({"seasons": series["seasons"]}) return render_to_string("modal/series_selection.html", context)
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 = ContentManager() content_discovery = ContentDiscovery() # TV show was requested if request_parameters["content_type"] == "tv": # Try to obtain a TVDB ID (from params or fetch it from TMDB) tvdb_id = None tmdb_id = None if request_parameters.__contains__("tvdb_id"): tvdb_id = request_parameters["tvdb_id"] if request_parameters.__contains__("tmdb_id"): tmdb_id = request_parameters["tmdb_id"] if not tvdb_id and tmdb_id: tvdb_id = content_discovery.get_external_ids(tmdb_id, "tv")["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 set_single_availability(card): """Sets the availabily on a single card.""" content_manager = ContentManager() content_discovery = ContentDiscovery() 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 set_single_conreq_status(card): content_manager = ContentManager() content_discovery = ContentDiscovery() try: # Compute conreq status of a Sonarr card if card.__contains__("tvdbId"): content = content_manager.get(tvdb_id=card["tvdbId"]) if content is not None: card["conreqStatus"] = content["conreqStatus"] # Compute conreq status of a Radarr card elif card.__contains__("tmdbId"): content = content_manager.get(tmdb_id=card["tmdbId"]) if content is not None: card["conreqStatus"] = content["conreqStatus"] # Compute conreq status 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["conreqStatus"] = content["conreqStatus"] # Compute conreq status of movie elif card.__contains__("title"): content = content_manager.get(tmdb_id=card["id"]) if content is not None: card["conreqStatus"] = content["conreqStatus"] # Something unexpected was passed in else: log.handler( "Card did not contain contentType, title, or name!", log.WARNING, __logger, ) return card except: log.handler( "Could not determine Conreq Status of card!\n" + card, log.ERROR, __logger, ) return card
async def __request_content(self, content): content_manager = await database_sync_to_async(ContentManager)() content_discovery = ContentDiscovery() # TV show was requested if content["parameters"]["content_type"] == "tv": # Obtain the TVDB ID if needed tvdb_id = content["parameters"]["tvdb_id"] tmdb_id = content["parameters"]["tmdb_id"] if tvdb_id is None and tmdb_id is not None: tvdb_id = content_discovery.get_external_ids(tmdb_id, "tv")["tvdb_id"] # Request the show by the TVDB ID if tvdb_id is not None: # Check if the show is already within Sonarr's collection preexisting_show = content_manager.get(tvdb_id=tvdb_id) # If it doesn't already exists, add then request it if preexisting_show is None: sonarr_params = await database_sync_to_async( obtain_sonarr_parameters)(content_discovery, content_manager, tmdb_id, tvdb_id) new_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"], ) if new_show.__contains__("id"): content_manager.request( sonarr_id=new_show["id"], seasons=content["parameters"]["seasons"], episode_ids=content["parameters"]["episode_ids"], ) else: log.handler( "Show was added to Sonarr, but Sonarr did not return an ID!", log.ERROR, self.__logger, ) else: content_manager.request( sonarr_id=preexisting_show["id"], seasons=content["parameters"]["seasons"], episode_ids=content["parameters"]["episode_ids"], ) # Movie was requested elif content["parameters"]["content_type"] == "movie": radarr_params = await database_sync_to_async( obtain_radarr_parameters)(content_discovery, content_manager, content["parameters"]["tmdb_id"]) # Check if the movie is already within Radarr's collection preexisting_movie = content_manager.get( tmdb_id=content["parameters"]["tmdb_id"]) # If it doesn't already exists, add then request it if preexisting_movie is None: new_movie = content_manager.add( tmdb_id=content["parameters"]["tmdb_id"], quality_profile_id=radarr_params["radarr_profile_id"], root_dir=radarr_params["radarr_root"], ) if new_movie.__contains__("id"): content_manager.request(radarr_id=new_movie["id"]) else: log.handler( "Movie was added to Radarr, but Radarr did not return an ID!", log.ERROR, self.__logger, ) # If it already existed, just request it else: content_manager.request(radarr_id=preexisting_movie["id"])
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 = ContentManager() content_discovery = ContentDiscovery() # TV show was requested if request_parameters["content_type"] == "tv": # Obtain the TVDB ID if needed tvdb_id = None tmdb_id = None if request_parameters.__contains__("tvdb_id"): tvdb_id = request_parameters["tvdb_id"] if request_parameters.__contains__("tmdb_id"): tmdb_id = request_parameters["tmdb_id"] if not tvdb_id and tmdb_id: tvdb_id = content_discovery.get_external_ids(tmdb_id, "tv")["tvdb_id"] # Request the show by the TVDB ID if tvdb_id: # Check if the show is already within Sonarr's collection show = content_manager.get(tvdb_id=tvdb_id) # If it doesn't already exists, add then request it if show is None: 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"], ) # Save and request if tmdb_id: add_unique_to_db( UserRequest, content_id=tmdb_id, source="tmdb", content_type="tv", requested_by=request.user, ) else: add_unique_to_db( UserRequest, content_id=tvdb_id, source="tvdb", content_type="tv", requested_by=request.user, ) content_manager.request( sonarr_id=show["id"], seasons=request_parameters["seasons"], episode_ids=request_parameters["episode_ids"], ) log.handler( request.user.username + " requested TV series " + show["title"], log.INFO, __logger, ) # Movie was requested elif request_parameters["content_type"] == "movie": tmdb_id = request_parameters["tmdb_id"] radarr_params = obtain_radarr_parameters(content_discovery, content_manager, tmdb_id) # Check if the movie is already within Radarr's collection movie = content_manager.get(tmdb_id=tmdb_id) # If it doesn't already exists, add then request it if movie is None: movie = content_manager.add( tmdb_id=tmdb_id, quality_profile_id=radarr_params["radarr_profile_id"], root_dir=radarr_params["radarr_root"], ) # Save and request add_unique_to_db( UserRequest, content_id=tmdb_id, source="tmdb", content_type="movie", requested_by=request.user, ) content_manager.request(radarr_id=movie["id"]) log.handler( request.user.username + " requested movie " + movie["title"], log.INFO, __logger, ) return JsonResponse({}) return HttpResponseForbidden()