예제 #1
0
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))
예제 #2
0
파일: views.py 프로젝트: austincorum/Conreq
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))