def content_preview_modal(request): content_discovery = ContentDiscovery() # Get the ID from the URL tmdb_id = request.GET.get("tmdb_id", None) content_type = request.GET.get("content_type", None) if tmdb_id and content_type: # Fetch and process content = content_discovery.get_by_tmdb_id(tmdb_id, content_type, obtain_extras=False) set_single_availability(content) preprocess_tmdb_result(content) # Check if the user has already requested this requested = False if UserRequest.objects.filter( content_id=content["id"], source="tmdb", content_type=content["content_type"], ): requested = True context = generate_context({ "content": content, "requested": requested }) template = loader.get_template("modal/content_preview.html") return HttpResponse(template.render(context, request))
def more_info(request): content_discovery = ContentDiscovery() template = loader.get_template("viewport/more_info.html") thread_list = [] # Get the ID from the URL tmdb_id = request.GET.get("tmdb_id", None) tvdb_id = request.GET.get("tvdb_id", None) if tmdb_id: content_type = request.GET.get("content_type", None) # Get all the basic metadata for a given ID content = content_discovery.get_by_tmdb_id(tmdb_id, content_type) # Determine the availability of the current TMDB ID set_single_availability(content) # Pre-process data attributes within tmdb_result preprocess_tmdb_result(content) # Get collection information if (content.__contains__("belongs_to_collection") and content["belongs_to_collection"] is not None): tmdb_collection_id = content["belongs_to_collection"]["id"] else: tmdb_collection_id = None # Check if the user has already requested this requested = False if UserRequest.objects.filter( content_id=content["id"], source="tmdb", content_type=content["content_type"], ): requested = True # Generate context for page rendering context = generate_context({ "content": content, "collection_id": tmdb_collection_id, "content_type": content["content_type"], "requested": requested, }) elif tvdb_id: searcher = Search() # Fallback for TVDB content = searcher.television(tvdb_id)[0] thread_list = [] # Preprocess results preprocess_arr_result(content) # Determine the availability set_single_availability(content) # Generate context for page rendering context = generate_context({ "content": content, "content_type": content["contentType"], }) # Render the page return HttpResponse(template.render(context, request))
def more_info(request): content_discovery = ContentDiscovery() template = loader.get_template("viewport/more_info.html") thread_list = [] # Get the ID from the URL tmdb_id = request.GET.get("tmdb_id", None) tvdb_id = request.GET.get("tvdb_id", None) if tmdb_id: content_type = request.GET.get("content_type", None) # Get all the basic metadata for a given ID content = content_discovery.get_by_tmdb_id(tmdb_id, content_type) # Get recommended results similar_and_recommended_thread = ReturnThread( target=content_discovery.similar_and_recommended, args=[tmdb_id, content_type], ) similar_and_recommended_thread.start() # Determine the availability of the current TMDB ID thread = Thread(target=set_single_availability, args=[content]) thread.start() thread_list.append(thread) # Pre-process data attributes within tmdb_result thread = Thread(target=preprocess_tmdb_result, args=[content]) thread.start() thread_list.append(thread) # Get collection information if (content.__contains__("belongs_to_collection") and content["belongs_to_collection"] is not None): tmdb_collection = True tmdb_collection_thread = ReturnThread( target=content_discovery.collections, args=[content["belongs_to_collection"]["id"]], ) tmdb_collection_thread.start() else: tmdb_collection = None # Recommended content tmdb_recommended = similar_and_recommended_thread.join() if not isinstance(tmdb_recommended, dict) or len(tmdb_recommended) == 0: tmdb_recommended = None # Determine the availability for all recommended content thread = Thread(target=set_many_availability, args=[tmdb_recommended["results"]]) thread.start() thread_list.append(thread) # Wait for thread computation to complete for thread in thread_list: thread.join() if tmdb_collection is not None: tmdb_collection = tmdb_collection_thread.join() # Check if the user has already requested this requested = False if UserRequest.objects.filter( content_id=content["id"], source="tmdb", content_type=content["content_type"], ): requested = True # Generate context for page rendering context = generate_context({ "content": content, "recommended": tmdb_recommended, "collection": tmdb_collection, "content_type": content["content_type"], "requested": requested, }) elif tvdb_id: searcher = Search() # Fallback for TVDB content = searcher.television(tvdb_id)[0] thread_list = [] # Preprocess results thread = Thread(target=preprocess_arr_result, args=[content]) thread.start() thread_list.append(thread) # Determine the availability thread = Thread(target=set_single_availability, args=[content]) thread.start() thread_list.append(thread) # Wait for thread computation to complete for thread in thread_list: thread.join() # Generate context for page rendering context = generate_context({ "content": content, "content_type": content["contentType"], }) # Render the page return HttpResponse(template.render(context, request))
def all_requests(request): template = loader.get_template("viewport/requests.html") content_discovery = ContentDiscovery() content_manager = ContentManager() user_requests = UserRequest.objects.all().order_by("id").reverse() all_cards = [] request_dict = {} for entry in user_requests.values( "content_id", "source", "content_type", "requested_by__username", ): # Fetch TMDB entry if entry["source"] == "tmdb" and request_is_unique( entry, request_dict): card = content_discovery.get_by_tmdb_id( tmdb_id=entry["content_id"], content_type=entry["content_type"], obtain_extras=False, ) if card is not None: card["tmdbCard"] = True card["requested_by"] = entry["requested_by__username"] all_cards.append(card) # Fetch TVDB entry if entry["source"] == "tvdb" and request_is_unique( entry, request_dict): # Attempt to convert card to TMDB conversion = content_discovery.get_by_tvdb_id( tvdb_id=entry["content_id"]) # Conversion found if conversion.__contains__( "tv_results") and conversion["tv_results"]: card = conversion["tv_results"][0] card["tmdbCard"] = True card["requested_by"] = entry["requested_by__username"] all_cards.append(card) # Convert all requests to use this new ID old_requests = UserRequest.objects.filter( content_id=entry["content_id"], source="tvdb") old_requests.update(content_id=card["id"], source="tmdb") # Fallback to checking sonarr's database else: card = content_manager.get(tvdb_id=entry["content_id"]) # Determine if the card has a known poster image if isinstance(card, dict): card["contentType"] = entry["content_type"] if card.__contains__("images"): remote_poster = is_key_value_in_list("coverType", "poster", card["images"], return_item=True) if remote_poster: card["remotePoster"] = remote_poster["remoteUrl"] card["requested_by"] = entry["requested_by__username"] all_cards.append(card) if card is None and not request_is_unique(entry, request_dict): log.handler( entry["content_type"] + " from " + entry["source"] + " with ID " + entry["content_id"] + " no longer exists!", log.WARNING, __logger, ) # Set the availability content_discovery.determine_id_validity({"results": all_cards}) set_many_availability(all_cards) context = generate_context({"all_cards": all_cards}) return HttpResponse(template.render(context, request))
def generate_issue_cards(reported_issues): """Retruns a list of cards""" content_discovery = ContentDiscovery() content_manager = ContentManager() all_cards = [] for entry in reported_issues.values( "id", "reported_by__username", "content_id", "source", "resolved", "content_type", "issues", "seasons", "episodes", ): # Fetch TMDB entry if entry["source"] == "tmdb": card = content_discovery.get_by_tmdb_id( tmdb_id=entry["content_id"], content_type=entry["content_type"], obtain_extras=False, ) if card is not None: all_cards.append({**card, **entry}) # Fetch TVDB entry if entry["source"] == "tvdb": # Attempt to convert card to TMDB conversion = content_discovery.get_by_tvdb_id(tvdb_id=entry["content_id"]) # Conversion found if conversion.__contains__("tv_results") and conversion["tv_results"]: card = conversion["tv_results"][0] all_cards.append({**card, **entry}) # Convert all requests to use this new ID old_requests = ReportedIssue.objects.filter( content_id=entry["content_id"], source="tvdb" ) old_requests.update(content_id=card["id"], source="tmdb") log.handler( entry["content_type"] + " from " + entry["source"] + " with ID " + entry["content_id"] + " has been converted to TMDB", log.INFO, _logger, ) # Fallback to checking sonarr's database else: card = content_manager.get(tvdb_id=entry["content_id"]) all_cards.append({**card, **entry}) if card is None: log.handler( entry["content_type"] + " from " + entry["source"] + " with ID " + entry["content_id"] + " no longer exists!", log.WARNING, _logger, ) return all_cards
def my_issues(request): # Get the parameters from the URL content_discovery = ContentDiscovery() content_manager = ContentManager() reported_issues = ( ReportedIssue.objects.filter(reported_by=request.user).order_by("id").reverse() ) all_cards = [] for entry in reported_issues.values( "reported_by__username", "content_id", "source", "resolved", "content_type", "issues", "seasons", "episodes", ): # Fetch TMDB entry if entry["source"] == "tmdb": card = content_discovery.get_by_tmdb_id( tmdb_id=entry["content_id"], content_type=entry["content_type"], obtain_extras=False, ) if card is not None: card["tmdbCard"] = True all_cards.append({**card, **entry}) # Fetch TVDB entry if entry["source"] == "tvdb": # Attempt to convert card to TMDB conversion = content_discovery.get_by_tvdb_id(tvdb_id=entry["content_id"]) # Conversion found if conversion.__contains__("tv_results") and conversion["tv_results"]: card = conversion["tv_results"][0] card["tmdbCard"] = True all_cards.append({**card, **entry}) # Convert all requests to use this new ID old_requests = ReportedIssue.objects.filter( content_id=entry["content_id"], source="tvdb" ) old_requests.update(content_id=card["id"], source="tmdb") # Fallback to checking sonarr's database else: card = content_manager.get(tvdb_id=entry["content_id"]) all_cards.append({**card, **entry}) if card is None: log.handler( entry["content_type"] + " from " + entry["source"] + " with ID " + entry["content_id"] + " no longer exists!", log.WARNING, __logger, ) context = generate_context({"all_cards": all_cards}) template = loader.get_template("viewport/reported_issues.html") return HttpResponse(template.render(context, request))