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 = [] ### 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 = __localize__(32008) + "\n" + currentmedia['name'], background = setting['background']) log('########################################################') log('Processing media: %s' % currentmedia['name']) # MY MOD log('########################################################') log('Path MY: %s' % currentmedia['path'][0]) if setting['central_art_enable']: if currentmedia['mediatype'] == 'tvshow': currentmedia['path'][0] = xbmc.translatePath( setting['central_art_tvshows'] + '%s' % ( currentmedia['name'] ) ) elif currentmedia['mediatype'] == 'movie': currentmedia['path'][0] = xbmc.translatePath( setting['central_art_movies'] + '%s' % ( os.path.basename(currentmedia['path'][0]))) if not self.fileops._exists(currentmedia['path'][0]): if not self.fileops._mkdir(currentmedia['path'][0]): raise CreateDirectoryError(currentmedia['path'][0]) log('Path MY: %s' % currentmedia['path'][0]) log('########################################################') # !MY MOD # 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 currentmedia['missing_arttypes'] = [] if setting['files_local']: local_list = [] local_list, scan_more, currentmedia['missing_arttypes'], currentmedia['force_update'] = local().get_image_list(currentmedia) # append local artwork for item in local_list: image_list.append(item) else: for i in arttype_list: if i['bulk_enabled'] and currentmedia['mediatype'] == i['media_type']: if not currentmedia['art'].has_key(i['art_type']): currentmedia['missing_arttypes'].append(i['art_type']) # 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('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 or currentmedia['force_update']) and not startup['mode'] in ['gui', 'custom']: log('- Already have all files local') pass elif not (currentmedia['missing_arttypes'] or currentmedia['force_update']) and not startup['mode'] in ['gui', 'custom']: log('- Already have all artwork') pass # If correct ID found and don't already have all artwork retrieve from providers else: log('- Still missing some files') log(currentmedia['missing_arttypes']) 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 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 = [] ### check if XBMC is shutting down if xbmc.Monitor().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) * 100 // float(media_list_total)), message=__localize__(32008) + "\n" + currentmedia['name'], background=setting['background']) log('########################################################') log('Processing media: %s' % currentmedia['name']) 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 currentmedia['missing_arttypes'] = [] if setting['files_local']: local_list = [] local_list, scan_more, currentmedia[ 'missing_arttypes'], currentmedia['force_update'] = local( ).get_image_list(currentmedia) # append local artwork for item in local_list: image_list.append(item) else: for i in arttype_list: if i['bulk_enabled'] and currentmedia['mediatype'] == i[ 'media_type']: if not (i['art_type']) in currentmedia['art']: currentmedia['missing_arttypes'].append( i['art_type']) # 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('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 or currentmedia['force_update'] ) and not startup['mode'] in ['gui', 'custom']: log('- Already have all files local') pass elif not (currentmedia['missing_arttypes'] or currentmedia['force_update'] ) and not startup['mode'] in ['gui', 'custom']: log('- Already have all artwork') pass # If correct ID found and don't already have all artwork retrieve from providers else: log('- Still missing some files') log(currentmedia['missing_arttypes']) 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: errmsg = '404: File not found' artwork_result = 'skipping' except HTTP503Error: xmlfailcount += 1 errmsg = '503: API Limit Exceeded' artwork_result = 'retrying' except NoFanartError: errmsg = 'No artwork found' artwork_result = 'skipping' failed_items.append( '[%s] %s' % (currentmedia['name'], __localize__(32133))) except ItemNotFoundError: errmsg = '%s not found' % currentmedia['id'] artwork_result = 'skipping' except ExpatError as e: xmlfailcount += 1 errmsg = 'Error parsing xml: %s' % str(e) artwork_result = 'retrying' except HTTPTimeout: failcount += 1 errmsg = 'Timed out' artwork_result = 'skipping' except DownloadError as e: failcount += 1 errmsg = 'Possible network error: %s' % str(e) artwork_result = 'skipping' else: artwork_result = 'pass' for item in temp_image_list: image_list.append(item) if not xmlfailcount < setting['xmlfailthreshold']: artwork_result = 'skipping' if not artwork_result == 'pass': log('Error getting data from %s (%s): %s' % (self.provider.name, errmsg, artwork_result)) if len(image_list) > 0: if (limit['limit_artwork'] and limit['limit_extrafanart_max'] < len(image_list)): self.download_max = limit['limit_extrafanart_max'] else: self.download_max = len(image_list) # Check for GUI mode if startup['mode'] == 'gui': log('- Using GUI mode') self._gui_mode(currentmedia) elif startup['mode'] == 'custom': log('- Using custom mode') self._custom_mode(currentmedia) else: #log('- Using bulk mode') self._download_process(currentmedia) processeditems += 1