Exemple #1
0
def get_profile_list():
    apikey_radarr = settings.radarr.apikey
    profiles_list = []
    # Get profiles data from radarr
    if get_radarr_info.is_legacy():
        url_radarr_api_movies = url_radarr() + "/api/profile?apikey=" + apikey_radarr
    else:
        url_radarr_api_movies = url_radarr() + "/api/v3/qualityprofile?apikey=" + apikey_radarr

    try:
        profiles_json = requests.get(url_radarr_api_movies, timeout=60, verify=False, headers=headers)
    except requests.exceptions.ConnectionError as errc:
        logging.exception("BAZARR Error trying to get profiles from Radarr. Connection Error.")
    except requests.exceptions.Timeout as errt:
        logging.exception("BAZARR Error trying to get profiles from Radarr. Timeout Error.")
    except requests.exceptions.RequestException as err:
        logging.exception("BAZARR Error trying to get profiles from Radarr.")
    else:
        # Parsing data returned from radarr
        if get_radarr_info.is_legacy():
            for profile in profiles_json.json():
                profiles_list.append([profile['id'], profile['language'].capitalize()])
        else:
            for profile in profiles_json.json():
                profiles_list.append([profile['id'], profile['language']['name'].capitalize()])

        return profiles_list

    return None
Exemple #2
0
def browse_radarr_filesystem(path='#'):
    if path == '#':
        path = ''

    if get_radarr_info.is_legacy():
        url_radarr_api_filesystem = url_radarr() + "/api/filesystem?path=" + path + \
                                    "&allowFoldersWithoutTrailingSlashes=true&includeFiles=false&apikey=" + \
                                    settings.radarr.apikey
    else:
        url_radarr_api_filesystem = url_radarr() + "/api/v3/filesystem?path=" + path + \
                                    "&allowFoldersWithoutTrailingSlashes=true&includeFiles=false&apikey=" + \
                                    settings.radarr.apikey
    try:
        r = requests.get(url_radarr_api_filesystem, timeout=60, verify=False, headers=headers)
        r.raise_for_status()
    except requests.exceptions.HTTPError:
        logging.exception("BAZARR Error trying to get series from Radarr. Http error.")
        return
    except requests.exceptions.ConnectionError:
        logging.exception("BAZARR Error trying to get series from Radarr. Connection Error.")
        return
    except requests.exceptions.Timeout:
        logging.exception("BAZARR Error trying to get series from Radarr. Timeout Error.")
        return
    except requests.exceptions.RequestException:
        logging.exception("BAZARR Error trying to get series from Radarr.")
        return

    return r.json()
Exemple #3
0
def get_movies_from_radarr_api(url, apikey_radarr, radarr_id=None):
    if get_radarr_info.is_legacy():
        url_radarr_api_movies = url + "/api/movie" + ("/{}".format(radarr_id) if radarr_id else "") + "?apikey=" + \
                                apikey_radarr
    else:
        url_radarr_api_movies = url + "/api/v3/movie" + ("/{}".format(radarr_id) if radarr_id else "") + "?apikey=" + \
                                apikey_radarr

    try:
        r = requests.get(url_radarr_api_movies,
                         timeout=60,
                         verify=False,
                         headers=headers)
        if r.status_code == 404:
            return
        r.raise_for_status()
    except requests.exceptions.HTTPError:
        logging.exception(
            "BAZARR Error trying to get movies from Radarr. Http error.")
        return
    except requests.exceptions.ConnectionError:
        logging.exception(
            "BAZARR Error trying to get movies from Radarr. Connection Error.")
        return
    except requests.exceptions.Timeout:
        logging.exception(
            "BAZARR Error trying to get movies from Radarr. Timeout Error.")
        return
    except requests.exceptions.RequestException:
        logging.exception("BAZARR Error trying to get movies from Radarr.")
        return
    else:
        return r.json()
Exemple #4
0
def movies_images(url):
    apikey = settings.radarr.apikey
    baseUrl = settings.radarr.base_url
    if get_radarr_info.is_legacy():
        url_image = url_radarr() + '/api/' + url.lstrip(baseUrl) + '?apikey=' + apikey
    else:
        url_image = url_radarr() + '/api/v3/' + url.lstrip(baseUrl) + '?apikey=' + apikey
    try:
        req = requests.get(url_image, stream=True, timeout=15, verify=False, headers=headers)
    except:
        return '', 404
    else:
        return Response(stream_with_context(req.iter_content(2048)), content_type=req.headers['content-type'])
Exemple #5
0
def get_radarr_rootfolder():
    apikey_radarr = settings.radarr.apikey
    radarr_rootfolder = []

    # Get root folder data from Radarr
    if get_radarr_info.is_legacy():
        url_radarr_api_rootfolder = url_radarr() + "/api/rootfolder?apikey=" + apikey_radarr
    else:
        url_radarr_api_rootfolder = url_radarr() + "/api/v3/rootfolder?apikey=" + apikey_radarr

    try:
        rootfolder = requests.get(url_radarr_api_rootfolder, timeout=60, verify=False, headers=headers)
    except requests.exceptions.ConnectionError:
        logging.exception("BAZARR Error trying to get rootfolder from Radarr. Connection Error.")
        return []
    except requests.exceptions.Timeout:
        logging.exception("BAZARR Error trying to get rootfolder from Radarr. Timeout Error.")
        return []
    except requests.exceptions.RequestException:
        logging.exception("BAZARR Error trying to get rootfolder from Radarr.")
        return []
    else:
        radarr_movies_paths = list(TableMovies.select(TableMovies.path).dicts())
        for folder in rootfolder.json():
            if any(item['path'].startswith(folder['path']) for item in radarr_movies_paths):
                radarr_rootfolder.append({'id': folder['id'], 'path': folder['path']})
        db_rootfolder = TableMoviesRootfolder.select(TableMoviesRootfolder.id, TableMoviesRootfolder.path).dicts()
        rootfolder_to_remove = [x for x in db_rootfolder if not
                                next((item for item in radarr_rootfolder if item['id'] == x['id']), False)]
        rootfolder_to_update = [x for x in radarr_rootfolder if
                                next((item for item in db_rootfolder if item['id'] == x['id']), False)]
        rootfolder_to_insert = [x for x in radarr_rootfolder if not
                                next((item for item in db_rootfolder if item['id'] == x['id']), False)]

        for item in rootfolder_to_remove:
            TableMoviesRootfolder.delete().where(TableMoviesRootfolder.id == item['id']).execute()
        for item in rootfolder_to_update:
            TableMoviesRootfolder.update({TableMoviesRootfolder.path: item['path']})\
                .where(TableMoviesRootfolder.id == item['id']).execute()
        for item in rootfolder_to_insert:
            TableMoviesRootfolder.insert({TableMoviesRootfolder.id: item['id'],
                                          TableMoviesRootfolder.path: item['path']}).execute()
Exemple #6
0
def get_tags():
    apikey_radarr = settings.radarr.apikey
    tagsDict = []

    # Get tags data from Radarr
    if get_radarr_info.is_legacy():
        url_radarr_api_series = url_radarr() + "/api/tag?apikey=" + apikey_radarr
    else:
        url_radarr_api_series = url_radarr() + "/api/v3/tag?apikey=" + apikey_radarr

    try:
        tagsDict = requests.get(url_radarr_api_series, timeout=60, verify=False, headers=headers)
    except requests.exceptions.ConnectionError:
        logging.exception("BAZARR Error trying to get tags from Radarr. Connection Error.")
        return []
    except requests.exceptions.Timeout:
        logging.exception("BAZARR Error trying to get tags from Radarr. Timeout Error.")
        return []
    except requests.exceptions.RequestException:
        logging.exception("BAZARR Error trying to get tags from Radarr.")
        return []
    else:
        return tagsDict.json()
Exemple #7
0
def movieParser(movie, action, tags_dict, movie_default_profile,
                audio_profiles):
    if 'movieFile' in movie:
        # Detect file separator
        if movie['path'][0] == "/":
            separator = "/"
        else:
            separator = "\\"

        try:
            overview = str(movie['overview'])
        except Exception:
            overview = ""
        try:
            poster_big = movie['images'][0]['url']
            poster = os.path.splitext(
                poster_big)[0] + '-500' + os.path.splitext(poster_big)[1]
        except Exception:
            poster = ""
        try:
            fanart = movie['images'][1]['url']
        except Exception:
            fanart = ""

        if 'sceneName' in movie['movieFile']:
            sceneName = movie['movieFile']['sceneName']
        else:
            sceneName = None

        alternativeTitles = None
        if get_radarr_info.is_legacy():
            if 'alternativeTitles' in movie:
                alternativeTitles = str(
                    [item['title'] for item in movie['alternativeTitles']])
        else:
            if 'alternateTitles' in movie:
                alternativeTitles = str(
                    [item['title'] for item in movie['alternateTitles']])

        if 'imdbId' in movie:
            imdbId = movie['imdbId']
        else:
            imdbId = None

        try:
            format, resolution = movie['movieFile']['quality']['quality'][
                'name'].split('-')
        except Exception:
            format = movie['movieFile']['quality']['quality']['name']
            try:
                resolution = str(movie['movieFile']['quality']['quality']
                                 ['resolution']) + 'p'
            except Exception:
                resolution = None

        if 'mediaInfo' in movie['movieFile']:
            videoFormat = videoCodecID = videoCodecLibrary = None
            if get_radarr_info.is_legacy():
                if 'videoFormat' in movie['movieFile']['mediaInfo']:
                    videoFormat = movie['movieFile']['mediaInfo'][
                        'videoFormat']
            else:
                if 'videoCodec' in movie['movieFile']['mediaInfo']:
                    videoFormat = movie['movieFile']['mediaInfo']['videoCodec']
            if 'videoCodecID' in movie['movieFile']['mediaInfo']:
                videoCodecID = movie['movieFile']['mediaInfo']['videoCodecID']
            if 'videoCodecLibrary' in movie['movieFile']['mediaInfo']:
                videoCodecLibrary = movie['movieFile']['mediaInfo'][
                    'videoCodecLibrary']
            videoCodec = RadarrFormatVideoCodec(videoFormat, videoCodecID,
                                                videoCodecLibrary)

            audioFormat = audioCodecID = audioProfile = audioAdditionalFeatures = None
            if get_radarr_info.is_legacy():
                if 'audioFormat' in movie['movieFile']['mediaInfo']:
                    audioFormat = movie['movieFile']['mediaInfo'][
                        'audioFormat']
            else:
                if 'audioCodec' in movie['movieFile']['mediaInfo']:
                    audioFormat = movie['movieFile']['mediaInfo']['audioCodec']
            if 'audioCodecID' in movie['movieFile']['mediaInfo']:
                audioCodecID = movie['movieFile']['mediaInfo']['audioCodecID']
            if 'audioProfile' in movie['movieFile']['mediaInfo']:
                audioProfile = movie['movieFile']['mediaInfo']['audioProfile']
            if 'audioAdditionalFeatures' in movie['movieFile']['mediaInfo']:
                audioAdditionalFeatures = movie['movieFile']['mediaInfo'][
                    'audioAdditionalFeatures']
            audioCodec = RadarrFormatAudioCodec(audioFormat, audioCodecID,
                                                audioProfile,
                                                audioAdditionalFeatures)
        else:
            videoCodec = None
            audioCodec = None

        audio_language = []
        if get_radarr_info.is_legacy():
            if 'mediaInfo' in movie['movieFile']:
                if 'audioLanguages' in movie['movieFile']['mediaInfo']:
                    audio_languages_list = movie['movieFile']['mediaInfo'][
                        'audioLanguages'].split('/')
                    if len(audio_languages_list):
                        for audio_language_list in audio_languages_list:
                            audio_language.append(audio_language_list.strip())
            if not audio_language:
                audio_language = profile_id_to_language(
                    movie['qualityProfileId'], audio_profiles)
        else:
            if 'languages' in movie['movieFile'] and len(
                    movie['movieFile']['languages']):
                for item in movie['movieFile']['languages']:
                    if isinstance(item, dict):
                        if 'name' in item:
                            language = item['name']
                            if item['name'] == 'Portuguese (Brazil)':
                                language = language_from_alpha2('pb')
                            audio_language.append(language)

        tags = [d['label'] for d in tags_dict if d['id'] in movie['tags']]

        if action == 'update':
            return {
                'radarrId':
                int(movie["id"]),
                'title':
                movie["title"],
                'path':
                movie["path"] + separator + movie['movieFile']['relativePath'],
                'tmdbId':
                str(movie["tmdbId"]),
                'poster':
                poster,
                'fanart':
                fanart,
                'audio_language':
                str(audio_language),
                'sceneName':
                sceneName,
                'monitored':
                str(bool(movie['monitored'])),
                'year':
                str(movie['year']),
                'sortTitle':
                movie['sortTitle'],
                'alternativeTitles':
                alternativeTitles,
                'format':
                format,
                'resolution':
                resolution,
                'video_codec':
                videoCodec,
                'audio_codec':
                audioCodec,
                'overview':
                overview,
                'imdbId':
                imdbId,
                'movie_file_id':
                int(movie['movieFile']['id']),
                'tags':
                str(tags),
                'file_size':
                movie['movieFile']['size']
            }
        else:
            return {
                'radarrId':
                int(movie["id"]),
                'title':
                movie["title"],
                'path':
                movie["path"] + separator + movie['movieFile']['relativePath'],
                'tmdbId':
                str(movie["tmdbId"]),
                'subtitles':
                '[]',
                'overview':
                overview,
                'poster':
                poster,
                'fanart':
                fanart,
                'audio_language':
                str(audio_language),
                'sceneName':
                sceneName,
                'monitored':
                str(bool(movie['monitored'])),
                'sortTitle':
                movie['sortTitle'],
                'year':
                str(movie['year']),
                'alternativeTitles':
                alternativeTitles,
                'format':
                format,
                'resolution':
                resolution,
                'video_codec':
                videoCodec,
                'audio_codec':
                audioCodec,
                'imdbId':
                imdbId,
                'movie_file_id':
                int(movie['movieFile']['id']),
                'tags':
                str(tags),
                'profileId':
                movie_default_profile,
                'file_size':
                movie['movieFile']['size']
            }