예제 #1
0
파일: default.py 프로젝트: camster1/RTOTV
 def download_artwork(self, media_list, providers):
     global image_list
     global reportdata
     processeditems = 0
     media_list_total = len(media_list)
     for currentmedia in media_list:
         image_list = []
         # Declare some vars
         if not currentmedia.get('disctype'):
             currentmedia['disctype'] = 'n/a'
         ### check if XBMC is shutting down
         if xbmc.abortRequested:
             log('XBMC abort requested, aborting')
             reportdata += (
                 '\n - %s: %s' %
                 (__localize__(32150), time.strftime('%d %B %Y - %H:%M')))
             break
         ### check if script has been cancelled by user
         if dialog_msg('iscanceled', background=setting['background']):
             reportdata += ('\n - %s [%s]: %s' %
                            (__localize__(32151), currentmedia['mediatype'],
                             time.strftime('%d %B %Y - %H:%M')))
             break
         # abort script because of to many failures
         if not setting['failcount'] < setting['failthreshold']:
             reportdata += (
                 '\n - %s: %s' %
                 (__localize__(32152), time.strftime('%d %B %Y - %H:%M')))
             break
         dialog_msg('update',
                    percentage=int(
                        float(processeditems) / float(media_list_total) *
                        100.0),
                    line1=currentmedia['name'],
                    line2=__localize__(32008),
                    line3='',
                    background=setting['background'])
         log('########################################################')
         log('Processing media:  %s' % currentmedia['name'])
         # do some id conversions
         if (not currentmedia['mediatype'] == 'tvshow'
                 and currentmedia['id'] in ['', 'tt0000000', '0']):
             log('No IMDB ID found, trying to search themoviedb.org for matching title.'
                 )
             currentmedia['id'] = tmdb._search_movie(
                 currentmedia['name'], currentmedia['year'])
         elif (currentmedia['mediatype'] == 'movie'
               and not currentmedia['id'] == ''
               and not currentmedia['id'].startswith('tt')):
             log('No valid ID found, trying to search themoviedb.org for matching title.'
                 )
             currentmedia['id'] = tmdb._search_movie(
                 currentmedia['name'], currentmedia['year'])
         log('Provider ID:       %s' % currentmedia['id'])
         log('Media path:        %s' % currentmedia['path'])
         # Declare the target folders
         artworkdir = []
         extrafanartdirs = []
         extrathumbsdirs = []
         for item in currentmedia['path']:
             artwork_dir = os.path.join(item + '/')
             extrafanart_dir = os.path.join(artwork_dir + 'extrafanart' +
                                            '/')
             extrathumbs_dir = os.path.join(artwork_dir + 'extrathumbs' +
                                            '/')
             artworkdir.append(
                 artwork_dir.replace('BDMV/', '').replace('VIDEO_TS/', ''))
             extrafanartdirs.append(extrafanart_dir)
             extrathumbsdirs.append(extrathumbs_dir)
         # Check if using the centralize option
         if setting['centralize_enable']:
             if currentmedia['mediatype'] == 'tvshow':
                 extrafanartdirs.append(setting['centralfolder_tvshows'])
             elif currentmedia['mediatype'] == 'movie':
                 extrafanartdirs.append(setting['centralfolder_movies'])
         currentmedia['artworkdir'] = artworkdir
         currentmedia['extrafanartdirs'] = extrafanartdirs
         currentmedia['extrathumbsdirs'] = extrathumbsdirs
         # this part check for local files when enabled
         scan_more = True
         missing = False
         if setting['files_local']:
             local_list = []
             local_list, scan_more, missing = local().get_image_list(
                 currentmedia)
             # append local artwork
             for item in local_list:
                 image_list.append(item)
         # Check for presence of id used by source sites
         if (startup['mode'] == 'gui'
                 and ((currentmedia['id'] == '') or
                      (currentmedia['mediatype'] == 'tvshow'
                       and currentmedia['id'].startswith('tt')))):
             dialog_msg('close', background=setting['background'])
             dialog_msg('okdialog', '', currentmedia['name'],
                        __localize__(32030))
         elif currentmedia['id'] == '':
             log('- No ID found, skipping')
             failed_items.append(
                 '[%s] ID %s' % (currentmedia['name'], __localize__(32022)))
         elif currentmedia['mediatype'] == 'tvshow' and currentmedia[
                 'id'].startswith('tt'):
             log('- IMDB ID found for TV show, skipping')
             failed_items.append(
                 '[%s]: TVDB ID %s' %
                 (currentmedia['name'], __localize__(32022)))
         #skip scanning for more if local files have been found and not run in gui / custom mode
         elif not scan_more and not startup['mode'] in ['gui', 'custom']:
             log('- Already have all files local')
             pass
         # If correct ID found and don't already have all artwork retrieve from providers
         else:
             log('- Still missing some files')
             log(missing)
             temp_image_list = []
             # Run through all providers getting their imagelisting
             failcount = 0
             for self.provider in providers:
                 if not failcount < setting['failthreshold']:
                     break
                 artwork_result = ''
                 xmlfailcount = 0
                 while not artwork_result == 'pass' and not artwork_result == 'skipping':
                     if artwork_result == 'retrying':
                         xbmc.sleep(setting['api_timedelay'])
                     try:
                         temp_image_list = self.provider.get_image_list(
                             currentmedia['id'])
                         #pass
                     except HTTP404Error, e:
                         errmsg = '404: File not found'
                         artwork_result = 'skipping'
                     except HTTP503Error, e:
                         xmlfailcount += 1
                         errmsg = '503: API Limit Exceeded'
                         artwork_result = 'retrying'
                     except NoFanartError, e:
                         errmsg = 'No artwork found'
                         artwork_result = 'skipping'
                         failed_items.append(
                             '[%s] %s' %
                             (currentmedia['name'], __localize__(32133)))
                     except ItemNotFoundError, e:
                         errmsg = '%s not found' % currentmedia['id']
                         artwork_result = 'skipping'
                     except ExpatError, e:
                         xmlfailcount += 1
                         errmsg = 'Error parsing xml: %s' % str(e)
                         artwork_result = 'retrying'
    def download_artwork(self, media_list, providers):
        global image_list
        global reportdata
        processeditems = 0
        media_list_total = len(media_list)
        for currentmedia in media_list:
            image_list = []
            # Declare some vars
            if not currentmedia.get('disctype'):
                currentmedia['disctype'] = 'n/a'
            ### check if XBMC is shutting down
            if xbmc.abortRequested:
                log('XBMC abort requested, aborting')
                reportdata += ('\n - %s: %s' %(__localize__(32150), time.strftime('%d %B %Y - %H:%M')))
                break
            ### check if script has been cancelled by user
            if dialog_msg('iscanceled',
                          background = setting['background']):
                reportdata += ('\n - %s [%s]: %s' %(__localize__(32151), currentmedia['mediatype'], time.strftime('%d %B %Y - %H:%M')))
                break
            # abort script because of to many failures
            if not setting['failcount'] < setting['failthreshold']:
                reportdata += ('\n - %s: %s' %(__localize__(32152), time.strftime('%d %B %Y - %H:%M')))
                break
            dialog_msg('update',
                        percentage = int(float(processeditems) / float(media_list_total) * 100.0),
                        line1 = currentmedia['name'],
                        line2 = __localize__(32008),
                        line3 = '',
                        background = setting['background'])
            log('########################################################')
            log('Processing media:  %s' % currentmedia['name'])
            # do some id conversions
            if (not currentmedia['mediatype'] == 'tvshow' and
                currentmedia['id'] in ['','tt0000000','0']):
                log('No IMDB ID found, trying to search themoviedb.org for matching title.')
                currentmedia['id'] = tmdb._search_movie(currentmedia['name'],currentmedia['year'])
            elif (currentmedia['mediatype'] == 'movie' and not
                  currentmedia['id'] == '' and not
                  currentmedia['id'].startswith('tt')):
                log('No valid ID found, trying to search themoviedb.org for matching title.')
                currentmedia['id'] = tmdb._search_movie(currentmedia['name'],currentmedia['year'])
            log('Provider ID:       %s' % currentmedia['id'])
            log('Media path:        %s' % currentmedia['path'])
            # Declare the target folders
            artworkdir = []
            extrafanartdirs = []
            extrathumbsdirs = []
            for item in currentmedia['path']:
                artwork_dir = os.path.join(item + '/')
                extrafanart_dir = os.path.join(artwork_dir + 'extrafanart' + '/')
                extrathumbs_dir = os.path.join(artwork_dir + 'extrathumbs' + '/')
                artworkdir.append(artwork_dir.replace('BDMV/','').replace('VIDEO_TS/',''))
                extrafanartdirs.append(extrafanart_dir)
                extrathumbsdirs.append(extrathumbs_dir)
            # Check if using the centralize option
            if setting['centralize_enable']:
                if currentmedia['mediatype'] == 'tvshow':
                    extrafanartdirs.append(setting['centralfolder_tvshows'])
                elif currentmedia['mediatype'] == 'movie':
                    extrafanartdirs.append(setting['centralfolder_movies'])
            currentmedia['artworkdir'] = artworkdir
            currentmedia['extrafanartdirs'] = extrafanartdirs
            currentmedia['extrathumbsdirs'] = extrathumbsdirs
            # this part check for local files when enabled
            scan_more = True
            if setting['files_local']:
                local_list = []
                local_list, scan_more = local().get_image_list(currentmedia)
                # append local artwork
                for item in local_list:
                    image_list.append(item)
            # Check for presence of id used by source sites
            if (startup['mode'] == 'gui' and
                ((currentmedia['id'] == '') or
                (currentmedia['mediatype'] == 'tvshow' and
                currentmedia['id'].startswith('tt')))):
                dialog_msg('close',
                           background = setting['background'])
                dialog_msg('okdialog',
                           '',
                           currentmedia['name'],
                           __localize__(32030))
            elif currentmedia['id'] == '':
                log('- No ID found, skipping')
                failed_items.append('[%s] ID %s' %(currentmedia['name'], __localize__(32022)))
            elif currentmedia['mediatype'] == 'tvshow' and currentmedia['id'].startswith('tt'):
                log('- IMDB ID found for TV show, skipping')
                failed_items.append('[%s]: TVDB ID %s' %(currentmedia['name'], __localize__(32022)))

            # If correct ID found continue
            else:
                temp_image_list = []
                # Run through all providers getting their imagelisting
                failcount = 0
                for self.provider in providers:
                    if not failcount < setting['failthreshold']:
                        break
                    artwork_result = ''
                    xmlfailcount = 0
                    #skip skanning for more if local files have been found and not run in gui / custom mode
                    if not scan_more and not startup['mode'] in ['gui', 'custom']:
                        artwork_result = 'pass'
                    while not artwork_result == 'pass' and not artwork_result == 'skipping':
                        if artwork_result == 'retrying':
                            xbmc.sleep(setting['api_timedelay'])
                        try:
                            temp_image_list = self.provider.get_image_list(currentmedia['id'])
                            #pass
                        except HTTP404Error, e:
                            errmsg = '404: File not found'
                            artwork_result = 'skipping'
                        except HTTP503Error, e:
                            xmlfailcount += 1
                            errmsg = '503: API Limit Exceeded'
                            artwork_result = 'retrying'
                        except NoFanartError, e:
                            errmsg = 'No artwork found'
                            artwork_result = 'skipping'
                            failed_items.append('[%s] %s' %(currentmedia['name'], __localize__(32133)))
                        except ItemNotFoundError, e:
                            errmsg = '%s not found' % currentmedia['id']
                            artwork_result = 'skipping'
                        except ExpatError, e:
                            xmlfailcount += 1
                            errmsg = 'Error parsing xml: %s' % str(e)
                            artwork_result = 'retrying'
예제 #3
0
def _media_listing(media_type):
    log('Using JSON for retrieving %s info' % media_type)
    Medialist = []
    if media_type == 'tvshow':
        json_query = xbmc.executeJSONRPC(
            '{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": {"properties": ["file", "imdbnumber", "art"], "sort": { "method": "label" } }, "id": 1}'
        )
        json_query = unicode(json_query, 'utf-8', errors='ignore')
        jsonobject = simplejson.loads(json_query)
        if jsonobject.has_key('result') and jsonobject['result'].has_key(
                'tvshows'):
            for item in jsonobject['result']['tvshows']:
                # Search for season information
                json_query_season = xbmc.executeJSONRPC(
                    '{"jsonrpc": "2.0", "method": "VideoLibrary.GetSeasons", "params": {"properties": ["season", "art"], "sort": { "method": "label" }, "tvshowid":%s }, "id": 1}'
                    % item.get('tvshowid', ''))
                jsonobject_season = simplejson.loads(json_query_season)
                # Get start/end and total seasons
                if jsonobject_season['result'].has_key('limits'):
                    season_limit = jsonobject_season['result']['limits']
                # Get the season numbers
                seasons_list = []
                if jsonobject_season['result'].has_key('seasons'):
                    seasons = jsonobject_season['result']['seasons']
                    for season in seasons:
                        seasons_list.append(season.get('season'))
                Medialist.append({
                    'id': item.get('imdbnumber', ''),
                    'dbid': item.get('tvshowid', ''),
                    'name': item.get('label', ''),
                    'base_name': media_path(item.get('file', '')),
                    'path': media_path(item.get('file', '')),
                    'seasontotal': season_limit.get('total', ''),
                    'seasonstart': season_limit.get('start', ''),
                    'seasonend': season_limit.get('end', ''),
                    'seasons': seasons_list,
                    'disctype': 'n/a',
                    'art': item.get('art', ''),
                    'mediatype': media_type
                })

    elif media_type == 'movie':
        json_query = xbmc.executeJSONRPC(
            '{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": {"properties": ["file", "imdbnumber", "year", "trailer", "streamdetails", "art"], "sort": { "method": "label" } }, "id": 1}'
        )
        json_query = unicode(json_query, 'utf-8', errors='ignore')
        jsonobject = simplejson.loads(json_query)
        if jsonobject.has_key('result') and jsonobject['result'].has_key(
                'movies'):
            for item in jsonobject['result']['movies']:
                imdbnumber = item.get('imdbnumber', '')
                if imdbnumber in ['', 'tt0000000', '0']:
                    from lib.provider import tmdb  # import on behalf of searching when there's no ID
                    log('No valid ID found, trying to search themoviedb.org for matching title.'
                        )
                    imdbnumber = tmdb._search_movie(item.get('label', ''),
                                                    item.get('year', ''))
                disctype = media_disctype(
                    item.get('file', '').encode('utf-8').lower(),
                    item['streamdetails']['video'])
                Medialist.append({
                    'dbid': item.get('movieid', ''),
                    'id': imdbnumber,
                    'name': item.get('label', ''),
                    'year': item.get('year', ''),
                    'file': item.get('file', ''),
                    'base_name': base_name(item.get('file', '')),
                    'path': media_path(item.get('file', '')),
                    'trailer': item.get('trailer', ''),
                    'disctype': disctype,
                    'art': item.get('art', ''),
                    'mediatype': media_type
                })

    elif media_type == 'musicvideo':
        json_query = xbmc.executeJSONRPC(
            '{"jsonrpc": "2.0", "method": "VideoLibrary.GetMusicVideos", "params": {"properties": ["file", "artist", "album", "track", "runtime", "year", "genre", "art"], "sort": { "method": "album" } }, "id": 1}'
        )
        json_query = unicode(json_query, 'utf-8', errors='ignore')
        jsonobject = simplejson.loads(json_query)
        if jsonobject.has_key('result') and jsonobject['result'].has_key(
                'musicvideos'):
            for item in jsonobject['result']['musicvideos']:
                Medialist.append({
                    'dbid': item.get('musicvideoid', ''),
                    'id': '',
                    'name': item.get('label', ''),
                    'artist': item.get('artist', ''),
                    'album': item.get('album', ''),
                    'track': item.get('track', ''),
                    'runtime': item.get('runtime', ''),
                    'year': item.get('year', ''),
                    'base_name': base_name(item.get('file', '')),
                    'path': media_path(item.get('file', '')),
                    'disctype': 'n/a',
                    'art': item.get('art', ''),
                    'mediatype': media_type
                })
    else:
        log('No JSON results found')
    return Medialist
def _media_listing(media_type):
    log('Using JSON for retrieving %s info' %media_type)
    Medialist = []
    if media_type == 'tvshow':
        json_query = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": {"properties": ["file", "imdbnumber", "art"], "sort": { "method": "label" } }, "id": 1}')
        json_query = unicode(json_query, 'utf-8', errors='ignore')
        jsonobject = simplejson.loads(json_query)
        if jsonobject.has_key('result') and jsonobject['result'].has_key('tvshows'):
            for item in jsonobject['result']['tvshows']:
                # Search for season information
                json_query_season = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetSeasons", "params": {"properties": ["season", "art"], "sort": { "method": "label" }, "tvshowid":%s }, "id": 1}' %item.get('tvshowid',''))
                jsonobject_season = simplejson.loads(json_query_season)
                # Get start/end and total seasons
                if jsonobject_season['result'].has_key('limits'):
                    season_limit = jsonobject_season['result']['limits']
                # Get the season numbers
                seasons_list = {}
                if jsonobject_season['result'].has_key('seasons'):
                    seasons = jsonobject_season['result']['seasons']
                    for season in seasons:
                        seasons_list[season.get('season')] = season.get('seasonid')
                Medialist.append({'id': item.get('imdbnumber',''),
                                  'dbid': item.get('tvshowid',''),
                                  'name': item.get('label',''),
                                  'base_name': media_path(item.get('file','')),
                                  'path': media_path(item.get('file','')),
                                  'seasontotal': season_limit.get('total',''),
                                  'seasonstart': season_limit.get('start',''),
                                  'seasonend': season_limit.get('end',''),
                                  'seasons': seasons_list,
                                  'disctype': 'n/a',
                                  'art' : item.get('art',''),
                                  'mediatype': media_type})

    elif media_type == 'movie':
        json_query = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": {"properties": ["file", "imdbnumber", "year", "trailer", "streamdetails", "art"], "sort": { "method": "label" } }, "id": 1}')
        json_query = unicode(json_query, 'utf-8', errors='ignore')
        jsonobject = simplejson.loads(json_query)
        if jsonobject.has_key('result') and jsonobject['result'].has_key('movies'):
            for item in jsonobject['result']['movies']:
                imdbnumber = item.get('imdbnumber','')
                if imdbnumber in ['','tt0000000','0']:
                    from lib.provider import tmdb # import on behalf of searching when there's no ID
                    log('No valid ID found, trying to search themoviedb.org for matching title.')
                    imdbnumber = tmdb._search_movie(item.get('label',''),item.get('year',''))
                disctype = media_disctype(item.get('file','').encode('utf-8').lower(),
                                          item['streamdetails']['video'])
                Medialist.append({'dbid': item.get('movieid',''),
                                  'id': imdbnumber,
                                  'name': item.get('label',''),
                                  'year': item.get('year',''),
                                  'file': item.get('file',''),
                                  'base_name': base_name(item.get('file','')),
                                  'path': media_path(item.get('file','')),
                                  'trailer': item.get('trailer',''),
                                  'disctype': disctype,
                                  'art' : item.get('art',''),
                                  'mediatype': media_type})

    elif media_type == 'musicvideo':
        json_query = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMusicVideos", "params": {"properties": ["file", "artist", "album", "track", "runtime", "year", "genre", "art"], "sort": { "method": "album" } }, "id": 1}')
        json_query = unicode(json_query, 'utf-8', errors='ignore')
        jsonobject = simplejson.loads(json_query)
        if jsonobject.has_key('result') and jsonobject['result'].has_key('musicvideos'):
            for item in jsonobject['result']['musicvideos']:
                Medialist.append({'dbid': item.get('musicvideoid',''),
                                  'id': '',
                                  'name': item.get('label',''),
                                  'artist': item.get('artist',''),
                                  'album': item.get('album',''),
                                  'track': item.get('track',''),
                                  'runtime': item.get('runtime',''),
                                  'year': item.get('year',''),
                                  'base_name': base_name(item.get('file','')),
                                  'path': media_path(item.get('file','')),
                                  'disctype': 'n/a',
                                  'art' : item.get('art',''),
                                  'mediatype': media_type})
    else:
            log('No JSON results found')
    return Medialist