コード例 #1
0
ファイル: nfo.py プロジェクト: ChrisOboe/mediasort
def get_identificator(guess, identificator, callback):
    """ tries to find imdb ids in nfo """

    nfofile = os.path.splitext(guess['filepath'])[0] + ".nfo"
    try:
        with open(nfofile, 'r') as nfo:
            for line in nfo:
                imdb_id = re.search(r'tt\d{7}', line)
                if imdb_id is not None:
                    identificator['imdb'] = imdb_id.group(0)
                    break
    except FileNotFoundError:
        raise error.NotEnoughData("nfo not found")
    except UnicodeDecodeError:
        raise error.NotEnoughData("Invalid char in nfo")

    return identificator
コード例 #2
0
ファイル: filename.py プロジェクト: ChrisOboe/mediasort
def get_guess(filepath):
    """ returns a guess based on the filename """

    guess = {
        'filepath': filepath,
    }

    nameguess = guessit(filepath)

    if "title" in nameguess:
        if isinstance(nameguess['title'], list):
            guess["title"] = nameguess["title"][0]
        else:
            guess["title"] = nameguess["title"]
        logger.debug("Guessed title: {0}".format(guess['title']))

    if nameguess["type"] == "movie":
        guess["type"] = MediaType.movie
        if "year" in nameguess:
            guess["year"] = datetime.strptime(str(nameguess["year"]), "%Y")
    elif nameguess["type"] == "episode":
        if 'episode' not in nameguess:
            raise error.NotEnoughData("No episode number found")
        if 'season' not in nameguess:
            raise error.NotEnoughData("No season number found")
        guess["type"] = MediaType.episode
        if isinstance(nameguess['episode'], list):
            guess["episode"] = nameguess["episode"][0]
        else:
            guess["episode"] = nameguess["episode"]
        guess["season"] = nameguess["season"]

    if "format" in nameguess:
        guess["source"] = nameguess["format"]

    if "release_group" in nameguess:
        guess["releasegroup"] = nameguess["release_group"]

    return guess
コード例 #3
0
ファイル: nfo.py プロジェクト: ChrisOboe/mediasort
def get_guess(filepath):
    """ returns a guess based on a nfo """

    guess = {
        'filepath': filepath,
    }

    nfofile = os.path.splitext(filepath)[0] + ".nfo"

    try:
        xmlfile = xml.etree.ElementTree.parse(nfofile)
    except xml.etree.ElementTree.ParseError:
        raise error.NotEnoughData("no xml based nfo")
    except FileNotFoundError:
        raise error.NotEnoughData("nfo not found")

    root = xmlfile.getroot()

    if root.tag == "movie":
        guess["type"] = MediaType.movie
        entry = root.find('title')
        if entry is not None:
            guess['title'] = entry.text
    elif root.tag == "episodedetails":
        guess["type"] = MediaType.episode
        entry = root.find('showtitle')
        if entry is not None:
            guess['title'] = entry.text

    wanted = ["releasegroup", "source", "episode", "season"]
    for i in wanted:
        entry = root.find(i)
        if entry is not None:
            guess[i] = entry.text

    return guess
コード例 #4
0
def get_episode_metadata(identificator, metadatatype, language):
    """ returns episode metadata """

    try:
        episode_cache = CACHE['metadata']['episode'][identificator['tmdb']][identificator['season']][identificator['episode']]
    except KeyError:
        episode_cache = None

    # use value from cache if cache exists
    if episode_cache:
        return episode_cache[metadatatype]

    try:
        episode = tmdbsimple.TV_Episodes(
            identificator['tmdb'],
            identificator['season'],
            identificator['episode']
        ).info(language=language)
    except requests.exceptions.HTTPError:
        raise error.NotEnoughData("Problem with accessing TMDb")

    metadata = {
        'showtitle': get_tvshow_metadata(identificator, 'showtitle', language),
        'title': episode.get('name'),
        'premiered': episode.get('air_date'),
        'show_premiered': get_tvshow_metadata(identificator, 'premiered', language),
        'plot': episode.get('overview'),
        'rating': episode.get('vote_average'),
        'votes': episode.get('vote_count'),
        'studios': get_tvshow_metadata(identificator, 'studios', language),
        'networks': get_tvshow_metadata(identificator, 'networks', language),
        'certification': get_tvshow_metadata(identificator, 'certification', language),
    }

    metadata['directors'] = []
    metadata['scriptwriters'] = []

    if 'crew' in episode:
        for crewmember in episode['crew']:
            if crewmember['job'] == 'Director':
                metadata['directors'].append(crewmember['name'])
            elif crewmember['job'] == 'Writer':
                metadata['scriptwriters'].append(crewmember['name'])

    metadata['actors'] = get_tvshow_metadata(identificator, 'actors', language)
    if 'guest_stars' in episode:
        for guest_star in episode['guest_stars']:
            if guest_star['character']:
                metadata['actors'].append(
                    {'name': guest_star['name'],
                     'role': guest_star['character']})


    # write metadata to cache
    tmdb = identificator['tmdb']
    episode = identificator['episode']
    season = identificator['season']
    if tmdb not in CACHE['metadata']['episode']:
        CACHE['metadata']['episode'][tmdb] = {}
    if season not in CACHE['metadata']['episode'][tmdb]:
        CACHE['metadata']['episode'][tmdb][season] = {}

    CACHE['metadata']['episode'][tmdb][season][episode] = metadata

    return metadata[metadatatype]
コード例 #5
0
def get_identificator(guess, identificator, callback):
    """ returns ids for the guessed videofile """

    # get episode and season from guessed
    if guess['type'] == MediaType.episode or \
       guess['type'] == MediaType.season:
        if not identificator['season']:
            identificator['season'] = guess['season']

    if guess['type'] == MediaType.episode and \
       not identificator['episode']:
        identificator['episode'] = guess['episode']

    # get tmdb id from imdb id
    if guess['type'] == MediaType.movie and identificator['imdb']:
        info = tmdbsimple.Find(
            identificator['imdb']
        ).info(external_source='imdb_id')

        if guess['type'] == MediaType.movie:
            identificator['tmdb'] = info['movie_results'][0]['id']
            identificator['tmdb'] = callback(
                [{'title': info['movie_results'][0]['title'],
                  'description': info['movie_results'][0]['overview'],
                  'id': info['movie_results'][0]['id']}],
                guess['type'].name
            )

        elif guess['type'] == MediaType.episode:
            identificator['tmdb'] = info['tv_results'][0]['id']
            tvshow = tmdbsimple.TV(identificator['tmdb']).external_ids()
            identificator['tvdb'] = tvshow['tvdb_id']
            identificator['tmdb'] = callback(
                [{'title': info['tv_results'][0]['name'],
                  'description': info['tv_results'][0]['overview'],
                  'id': info['tv_results'][0]['id']}],
                guess['type'].name
            )

    # get tmdb id from title
    if not identificator['tmdb']:
        args = {'query': guess['title'], 'language': CONFIG['search_language']}
        if guess['type'] == MediaType.movie and guess['year']:
            args['year'] = guess['year']
        search = tmdbsimple.Search()
        if guess['type'] == MediaType.movie:
            search.movie(**args)
        elif guess['type'] == MediaType.episode:
            search.tv(**args)

        if not search.results:
            raise error.NotEnoughData("TMDb search didn't found anything.")

        if callback is None and len(search.results) == 1:
            identificator['tmdb'] = search.results[0]['id']
        else:
            # call callback function
            callback_list = []
            for result in search.results:
                if guess['type'] == MediaType.movie:
                    movie = tmdbsimple.Movies(result['id']).info(
                        language=CONFIG['search_language'])

                    callback_list.append(
                        {'title': "{0} ({1})".format(movie['title'], movie['release_date']),
                         'descprition': result['overview'],
                         'id': result['id']}
                    )
                elif guess['type'] == MediaType.episode or \
                     guess['type'] == MediaType.tvshow or \
                     guess['type'] == MediaType.season:
                    callback_list.append(
                        {'title': result['name'],
                         'descprition': result['overview'],
                         'id': result['id']}
                    )
            identificator['tmdb'] = callback(callback_list,
                                             guess['type'].name)

    # now we should have a tmdb id. get the rest of ids
    if guess['type'] == MediaType.movie and not identificator['imdb']:
        identificator['imdb'] = tmdbsimple.Movies(identificator['tmdb']).info()['imdb_id']
    elif guess['type'] == MediaType.episode:
        tvshow = tmdbsimple.TV(identificator['tmdb']).external_ids()
        identificator['imdb'] = tvshow['imdb_id']
        identificator['tvdb'] = tvshow['tvdb_id']

    return identificator