Example #1
0
 def get_image_list(self, media_id):
     data = get_data(API_URL_TV%(API_KEY,media_id), 'json')
     image_list = []
     if data == 'Empty' or not data:
         return image_list
     else:
         # split 'name' and 'data'
         for title, value in data.iteritems():
             for art in IMAGE_TYPES:
                 if value.has_key(art):
                     for item in value[art]:
                         # Check on what type and use the general tag
                         arttypes = {'clearlogo': 'clearlogo',
                                     'hdtvlogo': 'clearlogo',
                                     'clearart': 'clearart',
                                     'hdclearart': 'clearart',
                                     'tvthumb': 'landscape',
                                     'seasonthumb': 'seasonlandscape',
                                     'characterart': 'characterart',
                                     'tvbanner': 'banner',
                                     'seasonbanner': 'seasonbanner',
                                     }
                         if art in ['hdtvlogo', 'hdclearart']:
                             size = 'HD'
                         elif art in ['clearlogo', 'clearart']:
                             size = 'SD'
                         else:
                             size = ''
                         # Create GUI info tag
                         generalinfo = '%s: %s  |  ' %( __localize__(32141), get_language(item.get('lang')).capitalize())
                         if item.get('season'):
                             generalinfo += '%s: %s  |  ' %( __localize__(32144), item.get('season'))
                         generalinfo += '%s: %s  |  ' %( __localize__(32143), item.get('likes'))
                         if art in ['hdtvlogo', 'hdclearart', 'clearlogo', 'clearart']:
                             generalinfo += '%s: %s  |  ' %( __localize__(32145), size)
                         # Fill list
                         image_list.append({'url': urllib.quote(item.get('url'), ':/'),
                                            'preview': item.get('url') + '/preview',
                                            'id': item.get('id'),
                                            'art_type': [arttypes[art]],
                                            'size': size,
                                            'season': item.get('season','n/a'),
                                            'language': item.get('lang'),
                                            'votes': item.get('likes'),
                                            'generalinfo': generalinfo})
         if image_list == []:
             raise NoFanartError(media_id)
         else:
             # Sort the list before return. Last sort method is primary
             image_list = sorted(image_list, key=itemgetter('votes'), reverse=True)
             image_list = sorted(image_list, key=itemgetter('size'), reverse=False)
             image_list = sorted(image_list, key=itemgetter('language'))
             return image_list
 def get_image_list(self, media_id):
     data = get_data(API_URL_MOVIE%(media_id, API_KEY), 'json')
     image_list = []
     if data == 'Empty' or not data:
         return image_list
     else:
         for value in data.iteritems():
             for art in IMAGE_TYPES_MOVIES:
                 if art == value[0]:
                     for item in value[1]:
                         # Check on what type and use the general tag
                         arttypes = {'movielogo': 'clearlogo',
                                     'moviedisc': 'discart',
                                     'movieart': 'clearart',
                                     'hdmovielogo': 'clearlogo',
                                     'hdmovieclearart': 'clearart',
                                     'moviebanner': 'banner',
                                     'moviethumb': 'landscape'}
                         if art in ['hdmovielogo', 'hdmovieclearart']:
                             size = 'HD'
                         elif art in ['movielogo', 'movieart']:
                             size = 'SD'
                         else:
                             size = ''
                         # Create GUI info tag
                         generalinfo = '%s: %s  |  ' %( __localize__(32141), get_language(item.get('lang')).capitalize())
                         if item.get('disc_type'):
                             generalinfo += '%s: %s (%s)  |  ' %( __localize__(32146), item.get('disc'), item.get('disc_type'))
                         if art in ['hdmovielogo', 'hdmovieclearart', 'movielogo', 'movieclearart']:
                             generalinfo += '%s: %s  |  ' %( __localize__(32145), size)
                         generalinfo += '%s: %s  |  ' %( __localize__(32143), item.get('likes'))
                         # Fill list
                         image_list.append({'url': urllib.quote(item.get('url'), ':/'),
                                            'preview': item.get('url') + '/preview',
                                            'id': item.get('id'),
                                            'art_type': [arttypes[art]],
                                            'size': size,
                                            'season': item.get('season','n/a'),
                                            'language': item.get('lang'),
                                            'votes': int(item.get('likes')),
                                            'disctype': item.get('disc_type','n/a'),
                                            'discnumber': item.get('disc','n/a'),
                                            'generalinfo': generalinfo})
         if image_list == []:
             raise NoFanartError(media_id)
         else:
             # Sort the list before return. Last sort method is primary
             image_list = sorted(image_list, key=itemgetter('votes'), reverse=True)
             image_list = sorted(image_list, key=itemgetter('size'), reverse=False)
             image_list = sorted(image_list, key=itemgetter('language'))
             return image_list
Example #3
0
File: tmdb.py Project: roeiba/xbmc
                        'votes':
                        votes,
                        # Create Gui string to display
                        'generalinfo':
                        ('%s: %s  |  %s: %s  |  %s: %s  |  %s: %sx%s  |  ' %
                         (__localize__(32141),
                          get_language(item.get('iso_639_1',
                                                'n/a')).capitalize(),
                          __localize__(32142), rating, __localize__(32143),
                          votes, __localize__(32145), item.get('width'),
                          item.get('height')))
                    })
            except Exception, e:
                log('Problem report: %s' % str(e), xbmc.LOGNOTICE)
            if image_list == []:
                raise NoFanartError(media_id)
            else:
                # Sort the list before return. Last sort method is primary
                image_list = sorted(image_list,
                                    key=itemgetter('rating'),
                                    reverse=True)
                image_list = sorted(image_list, key=itemgetter('language'))
                return image_list


def _search_movie(medianame, year=''):
    medianame = normalize_string(medianame)
    log('TMDB API search criteria: Title['
        '%s'
        '] | Year['
        '%s'
    def get_image_list(self, media_id):
        image_list = []
        data = get_data(API_URL % (self.api_key, media_id), 'xml')
        try:
            tree = ET.fromstring(data)
            for image in tree.findall('Banner'):
                info = {}
                if image.findtext('BannerPath'):
                    info['url'] = self.url_prefix + image.findtext(
                        'BannerPath')
                    if image.findtext('ThumbnailPath'):
                        info['preview'] = self.url_prefix + image.findtext(
                            'ThumbnailPath')
                    else:
                        info['preview'] = self.url_prefix + image.findtext(
                            'BannerPath')
                    info['language'] = image.findtext('Language')
                    info['id'] = image.findtext('id')
                    # process fanarts
                    if image.findtext('BannerType') == 'fanart':
                        info['art_type'] = 'fanart'
                        info['art_type'] = 'extrafanart'
                    # process posters
                    elif image.findtext('BannerType') == 'poster':
                        info['art_type'] = 'poster'
                    # process banners
                    elif image.findtext(
                            'BannerType') == 'series' and image.findtext(
                                'BannerType2') == 'graphical':
                        info['art_type'] = 'banner'
                    # process seasonposters
                    elif image.findtext(
                            'BannerType') == 'season' and image.findtext(
                                'BannerType2') == 'season':
                        info['art_type'] = 'seasonposter'
                    # process seasonfanarts
                    elif image.findtext(
                            'BannerType') == 'season' and image.findtext(
                                'BannerType2') == 'season':
                        info['art_type'] = 'seasonfanart'
                    # process seasonbanners
                    elif image.findtext(
                            'BannerType') == 'season' and image.findtext(
                                'BannerType2') == 'seasonwide':
                        info['art_type'] = 'seasonbanner'
                    else:
                        info['art_type'] = ['']
                    # convert image size ...x... in Bannertype2
                    if image.findtext('BannerType2'):
                        try:
                            x, y = image.findtext('BannerType2').split('x')
                            info['width'] = int(x)
                            info['height'] = int(y)
                        except:
                            info['type2'] = image.findtext('BannerType2')

                    # check if fanart has text
                    info['series_name'] = image.findtext(
                        'SeriesName') == 'true'

                    # find image ratings
                    if int(image.findtext('RatingCount')) >= 1:
                        info['rating'] = float(
                            "%.1f" % float(image.findtext('Rating'))
                        )  #output string with one decimal
                        info['votes'] = image.findtext('RatingCount')
                    else:
                        info['rating'] = 'n/a'
                        info['votes'] = 'n/a'

                    # find season info
                    if image.findtext('Season'):
                        info['season'] = image.findtext('Season')
                    else:
                        info['season'] = 'n/a'

                    # Create Gui string to display
                    info['generalinfo'] = '%s: %s  |  ' % (__localize__(
                        32141), get_language(info['language']).capitalize())
                    if info['season'] != 'n/a':
                        info['generalinfo'] += '%s: %s  |  ' % (
                            __localize__(32144), info['season'])
                    if 'height' in info:
                        info['generalinfo'] += '%s: %sx%s  |  ' % (
                            __localize__(32145), info['height'], info['width'])
                    info['generalinfo'] += '%s: %s  |  %s: %s  |  ' % (
                        __localize__(32142), info['rating'],
                        __localize__(32143), info['votes'])

                if info:
                    image_list.append(info)
        except:
            raise NoFanartError(media_id)
        if image_list == []:
            raise NoFanartError(media_id)
        else:
            # Sort the list before return. Last sort method is primary
            return image_list
 def get_image_list(self, media_id):
     image_list = []
     api_cfg = get_data(API_CFG % (API_KEY), 'json')
     if api_cfg == "Empty" or not api_cfg:
         return image_list
     BASE_IMAGEURL = api_cfg['images'].get('base_url')
     data = get_data(API_URL % (media_id, API_KEY), 'json')
     if data == "Empty" or not data:
         return image_list
     else:
         # Get fanart
         try:
             for item in data['backdrops']:
                 if int(item.get('vote_count')) >= 1:
                     rating = float("%.1f" % float(item.get('vote_average'))
                                    )  #output string with one decimal
                     votes = item.get('vote_count', 'n/a')
                 else:
                     rating = 'n/a'
                     votes = 'n/a'
                 image_list.append({
                     'url':
                     BASE_IMAGEURL + 'original' + item['file_path'],
                     'preview':
                     BASE_IMAGEURL + 'w300' + item['file_path'],
                     'id':
                     item.get('file_path').lstrip('/').replace('.jpg', ''),
                     'art_type':
                     'fanart',
                     'height':
                     item.get('height'),
                     'width':
                     item.get('width'),
                     'language':
                     item.get('iso_639_1', 'n/a'),
                     'rating':
                     rating,
                     'votes':
                     votes,
                     # Create Gui string to display
                     'generalinfo':
                     ('%s: %s  |  %s: %s  |  %s: %s  |  %s: %sx%s  |  ' %
                      (__localize__(32141),
                       get_language(item.get('iso_639_1',
                                             'n/a')).capitalize(),
                       __localize__(32142), rating, __localize__(32143),
                       votes, __localize__(32145), item.get('width'),
                       item.get('height')))
                 })
         except Exception as e:
             log('Problem report: %s' % str(e), xbmc.LOGDEBUG)
         # Get extrafanart
         try:
             for item in data['backdrops']:
                 if int(item.get('vote_count')) >= 1:
                     rating = float("%.1f" % float(item.get('vote_average'))
                                    )  #output string with one decimal
                     votes = item.get('vote_count', 'n/a')
                 else:
                     rating = 'n/a'
                     votes = 'n/a'
                 image_list.append({
                     'url':
                     BASE_IMAGEURL + 'original' + item['file_path'],
                     'preview':
                     BASE_IMAGEURL + 'w300' + item['file_path'],
                     'id':
                     item.get('file_path').lstrip('/').replace('.jpg', ''),
                     'art_type':
                     'extrafanart',
                     'height':
                     item.get('height'),
                     'width':
                     item.get('width'),
                     'language':
                     item.get('iso_639_1', 'n/a'),
                     'rating':
                     rating,
                     'votes':
                     votes,
                     # Create Gui string to display
                     'generalinfo':
                     ('%s: %s  |  %s: %s  |  %s: %s  |  %s: %sx%s  |  ' %
                      (__localize__(32141),
                       get_language(item.get('iso_639_1',
                                             'n/a')).capitalize(),
                       __localize__(32142), rating, __localize__(32143),
                       votes, __localize__(32145), item.get('width'),
                       item.get('height')))
                 })
         except Exception as e:
             log('Problem report: %s' % str(e), xbmc.LOGDEBUG)
         # Get thumbs
         try:
             for item in data['backdrops']:
                 if int(item.get('vote_count')) >= 1:
                     rating = float("%.1f" % float(item.get('vote_average'))
                                    )  #output string with one decimal
                     votes = item.get('vote_count', 'n/a')
                 else:
                     rating = 'n/a'
                     votes = 'n/a'
                 # Fill list
                 image_list.append({
                     'url':
                     BASE_IMAGEURL + 'w780' + item['file_path'],
                     'preview':
                     BASE_IMAGEURL + 'w300' + item['file_path'],
                     'id':
                     item.get('file_path').lstrip('/').replace('.jpg', ''),
                     'art_type':
                     'extrathumbs',
                     'height':
                     item.get('height'),
                     'width':
                     item.get('width'),
                     'language':
                     item.get('iso_639_1', 'n/a'),
                     'rating':
                     rating,
                     'votes':
                     votes,
                     # Create Gui string to display
                     'generalinfo':
                     ('%s: %s  |  %s: %s  |  %s: %s  |  %s: %sx%s  |  ' %
                      (__localize__(32141),
                       get_language(item.get('iso_639_1',
                                             'n/a')).capitalize(),
                       __localize__(32142), rating, __localize__(32143),
                       votes, __localize__(32145), item.get('width'),
                       item.get('height')))
                 })
         except Exception as e:
             log('Problem report: %s' % str(e), xbmc.LOGDEBUG)
         # Get posters
         try:
             for item in data['posters']:
                 if int(item.get('vote_count')) >= 1:
                     rating = float("%.1f" % float(item.get('vote_average'))
                                    )  #output string with one decimal
                     votes = item.get('vote_count', 'n/a')
                 else:
                     rating = 'n/a'
                     votes = 'n/a'
                 # Fill list
                 image_list.append({
                     'url':
                     BASE_IMAGEURL + 'original' + item['file_path'],
                     'preview':
                     BASE_IMAGEURL + 'w185' + item['file_path'],
                     'id':
                     item.get('file_path').lstrip('/').replace('.jpg', ''),
                     'art_type':
                     'poster',
                     'height':
                     item.get('height'),
                     'width':
                     item.get('width'),
                     'language':
                     item.get('iso_639_1', 'n/a'),
                     'rating':
                     rating,
                     'votes':
                     votes,
                     # Create Gui string to display
                     'generalinfo':
                     ('%s: %s  |  %s: %s  |  %s: %s  |  %s: %sx%s  |  ' %
                      (__localize__(32141),
                       get_language(item.get('iso_639_1',
                                             'n/a')).capitalize(),
                       __localize__(32142), rating, __localize__(32143),
                       votes, __localize__(32145), item.get('width'),
                       item.get('height')))
                 })
         except Exception as e:
             log('Problem report: %s' % str(e), xbmc.LOGDEBUG)
         if image_list == []:
             raise NoFanartError(media_id)
         else:
             # Sort the list before return. Last sort method is primary
             image_list = image_list
             return image_list