def collection(request): collection_id = request.GET.get("collection_id", None) if collection_id: content_discovery = ContentDiscovery() tmdb_collection = content_discovery.collections(collection_id) if not isinstance(tmdb_collection, dict) or not tmdb_collection: tmdb_collection = None else: set_many_availability(tmdb_collection["parts"]) context = generate_context({"collection": tmdb_collection}) template = loader.get_template("viewport/more_info_collection.html") return HttpResponse(template.render(context, request))
def recommended(request): tmdb_id = request.GET.get("tmdb_id", None) content_type = request.GET.get("content_type", None) if tmdb_id and content_type: content_discovery = ContentDiscovery() tmdb_recommended = content_discovery.similar_and_recommended( tmdb_id, content_type) if not isinstance(tmdb_recommended, dict) or not tmdb_recommended: tmdb_recommended = None else: set_many_availability(tmdb_recommended["results"]) context = generate_context({"recommended": tmdb_recommended}) template = loader.get_template("viewport/more_info_recommended.html") return HttpResponse(template.render(context, request))
def discover_movies(request): content_discovery = ContentDiscovery() template = loader.get_template("viewport/discover.html") # Get the page number from the URL page = int(request.GET.get("page", 1)) # Search for TV content tmdb_results = content_discovery.movies(page)["results"] # Set the availability for all cards set_many_availability(tmdb_results) context = generate_context({ "all_cards": tmdb_results, }) return HttpResponse(template.render(context, request))
def search(request): content_discovery = ContentDiscovery() searcher = Search() # Get the ID from the URL query = request.GET.get("query", "") content_type = request.GET.get("content_type", None) template = loader.get_template("viewport/search.html") # Determine which search method to use (tv/movie/all) if content_type == "tv": arr_results = searcher.television(query) elif content_type == "movie": arr_results = searcher.movie(query) else: arr_results = searcher.all(query) # Attempt to convert cards to TMDB equivalents thread_list = [] for index in range(0, len(arr_results)): thread = Thread(target=convert_card_to_tmdb, args=[index, arr_results]) thread.start() thread_list.append(thread) # Wait for computation to complete for thread in thread_list: thread.join() # Determine the availability content_discovery.determine_id_validity({"results": arr_results}) set_many_availability(arr_results) context = generate_context({ "all_cards": arr_results, }) 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))