예제 #1
0
def get_show_meta(name):
    tvdb = xbmcaddon.Addon('script.module.metahandler')
    __cwd__ = xbmc.translatePath(tvdb.getAddonInfo('path')).decode("utf-8")
    BASE_RESOURCE_PATH = os.path.join(__cwd__, 'lib', 'metahandler')
    sys.path.append(BASE_RESOURCE_PATH)
    from thetvdbapi import TheTVDB
    try:
        tv = TheTVDB(language='en')

        split = name.split(" ")
        if len(split) > 1:
            name = split[0] + " " + split[1]

        show_list = tv.get_matching_shows(name, language='all')
        #print "Searching %s" % (name)
        if len(show_list) > 0:
            show_id = show_list[0][0]
            images = tv.get_show_image_choices(show_id)
            res = {}
            for im in images:
                if 'fanart' in im[1]:
                    res['fanart'] = im[0]
                if 'poster' in im[1]:
                    res['poster'] = im[0]
            return res
    except Exception as e:
        return None
    return None
예제 #2
0
    def _get_tvdb_meta(self, imdb_id, name, year=''):
        """
        Requests meta data from TVDB and creates proper dict to send back

        Args:
            imdb_id (str): IMDB ID
            name (str): full name of tvshow you are searching
        Kwargs:
            year (str): 4 digit year of tvshow, when imdb_id is not available it is recommended
                        to include the year whenever possible to maximize correct search results.

        Returns:
            DICT. It must also return an empty dict when
            no movie meta info was found from tvdb because we should cache
            these "None found" entries otherwise we hit tvdb alot.
        """
        xbmc.log('Starting TVDB Lookup', 0)
        tvdb = TheTVDB()
        tvdb_id = ''

        try:
            if imdb_id:
                tvdb_id = tvdb.get_show_by_imdb(imdb_id)
        except Exception as e:
            xbmc.log(
                '************* Error retreiving from thetvdb.com1: %s ' % e, 4)
            tvdb_id = ''

        # Intialize tvshow meta dictionary
        meta = self._init_tvshow_meta(imdb_id, tvdb_id, name, year)

        # if not found by imdb, try by name
        if tvdb_id == '':
            try:
                # If year is passed in, add it to the name for better TVDB search results
                # if year:
                #    name = name + ' ' + year
                show_list = tvdb.get_matching_shows(name)
            except Exception as e:
                xbmc.log(
                    '************* Error retreiving from thetvdb.com2: %s ' %
                    e, 4)
                show_list = []

            xbmc.log('Found TV Show List: %s' % show_list, 0)
            tvdb_id = ''
            for show in show_list:
                (junk1, junk2, junk3) = show
                try:
                    # if we match imdb_id or full name (with year) then we know for sure it is the right show
                    if (imdb_id and junk3
                            == imdb_id) or (year and self._string_compare(
                                self._clean_string(junk2),
                                self._clean_string(name + year))):
                        tvdb_id = self._clean_string(junk1)
                        if not imdb_id:
                            imdb_id = self._clean_string(junk3)
                        name = junk2
                        break
                    # if we match just the cleaned name (without year) keep the tvdb_id
                    elif self._string_compare(self._clean_string(junk2),
                                              self._clean_string(name)):
                        tvdb_id = self._clean_string(junk1)
                        if not imdb_id:
                            imdb_id = self._clean_string(junk3)
                        break

                except Exception as e:
                    xbmc.log(
                        '************* Error retreiving from thetvdb.com3: %s '
                        % e, 4)

        if tvdb_id:
            xbmc.log(
                'Show *** ' + name + ' *** found in TVdb. Getting details...',
                0)

            try:
                show = tvdb.get_show(tvdb_id)
            except Exception as e:
                xbmc.log(
                    '************* Error retreiving from thetvdb.com: %s ' % e,
                    4)
                show = None

            if show is not None:
                meta['imdb_id'] = imdb_id
                meta['tvdb_id'] = tvdb_id
                meta['title'] = name
                if str(show.rating) != '' and show.rating is not None:
                    meta['rating'] = float(show.rating)
                # "Soft Focus with Jena Friedman" had an empty runtime, killing metadata routines
                if str(show.runtime) != '':
                    meta['duration'] = int(show.runtime) * 60
                else:
                    meta['duration'] = 99999
                meta['plot'] = show.overview
                meta['mpaa'] = show.content_rating
                meta['premiered'] = str(show.first_aired)

                # Do whatever we can to set a year, if we don't have one lets try to strip it from
                # show.first_aired/premiered
                if not year and show.first_aired:
                    # meta['year'] = int(self._convert_date(meta['premiered'], '%Y-%m-%d', '%Y'))
                    meta['year'] = int(meta['premiered'][:4])

                if show.genre != '':
                    temp = show.genre.replace("|", ",")
                    temp = temp[1:(len(temp) - 1)]
                    meta['genre'] = temp
                meta['studio'] = show.network
                meta['status'] = show.status
                if show.actors:
                    for actor in show.actors:
                        meta['cast'].append(actor)
                meta['banner_url'] = show.banner_url
                meta['cover_url'] = show.poster_url
                meta['backdrop_url'] = show.fanart_url
                meta['overlay'] = 6

                return meta
        else:
            return meta
예제 #3
0
#!/usr/bin/python

from thetvdbapi import TheTVDB

moo = TheTVDB('273A29FB654AC4D2')
showid = moo.get_matching_shows('House')[0][0]
print moo.get_show(showid).