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