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() # Generate conreq status content_discovery.determine_id_validity({"results": arr_results}) set_many_conreq_status(arr_results) context = generate_context( { "all_cards": arr_results, } ) 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))