def _batch_download(self, image_list): log('########################################################') # If image list is empty print log message if len(image_list) == 0: log('- Nothing to download') # If not empty process the image list else: log('- Starting download') # Download artwork that passed the limit check for item in image_list: # Check if cancel has been called to break the loop if xbmc.abortRequested: log('XBMC abort requested, aborting') self.reportdata += ( '\n - %s: %s' %( __localize__(32150), time.strftime('%d %B %Y - %H:%M')) ) break ### check if script has been cancelled by user if dialog('iscanceled', background = self.settings.background): self.reportdata += ( '\n - %s: %s' %(__localize__(32153), time.strftime('%d %B %Y - %H:%M')) ) break # Update the dialog dialog('update', percentage = int(float(self.download_counter['Total Artwork']) / float(len(image_list)) * 100.0), line1 = item['media_name'], line2 = __localize__(32009) + ' ' + item['artwork_string'], line3 = item['filename'], background = self.settings.background) # Try downloading the file and catch errors while trying to try: self.fileops._downloadfile(item['url'], item['filename'], item['targetdirs'], item['media_name'], self.mode) except HTTP404Error, e: log("URL not found: %s" % str(e), xbmc.LOGERROR) self._download_art_succes = False except HTTPTimeout, e: self.settings.failcount += 1 log("Download timed out: %s" % str(e), xbmc.LOGERROR) self._download_art_succes = False except CreateDirectoryError, e: log("Could not create directory, skipping: %s" % str(e), xbmc.LOGWARNING) self._download_art_succes = False
def play(): """ Start up playback_starter in main Python thread """ request = '%s&handle=%s' % (argv[2], HANDLE) # Put the request into the 'queue' utils.plex_command('PLAY-%s' % request) if HANDLE == -1: # Handle -1 received, not waiting for main thread return # Wait for the result while not pickler.pickl_window('plex_result'): sleep(50) result = pickler.unpickle_me() if result is None: log.error('Error encountered, aborting') utils.dialog('notification', heading='{plex}', message=utils.lang(30128), icon='{error}', time=3000) setResolvedUrl(HANDLE, False, ListItem()) elif result.listitem: listitem = pkc_listitem.convert_pkc_to_listitem(result.listitem) setResolvedUrl(HANDLE, True, listitem)
def play(): """ Start up playback_starter in main Python thread """ request = '%s&handle=%s' % (argv[2], HANDLE) # Put the request into the 'queue' transfer.plex_command('PLAY-%s' % request) if HANDLE == -1: # Handle -1 received, not waiting for main thread return # Wait for the result from the main PKC thread result = transfer.wait_for_transfer() if result is None: LOG.error('Error encountered, aborting') utils.dialog('notification', heading='{plex}', message=utils.lang(30128), icon='{error}', time=3000) xbmcplugin.setResolvedUrl(HANDLE, False, xbmcgui.ListItem()) elif result is True: pass else: # Received a xbmcgui.ListItem() xbmcplugin.setResolvedUrl(HANDLE, True, result)
def _custom_mode(self): self.download_arttypes = [] # Look for argument matching artwork types for item in sys.argv: for type in self.settings.available_arttypes: if item == type['art_type'] and self.mediatype == type[ 'media_type']: log('- Custom %s mode arttype: %s' % (type['media_type'], type['art_type'])) self.download_arttypes.append(item) # If only one specified and not extrafanart/extrathumbs if ( len(self.download_arttypes) == 1 ) and not self.medianame == '' and not 'extrathumbs' in self.download_arttypes and not 'extrafanart' in self.download_arttypes: # Get image list for that specific imagetype for gui_arttype in self.download_arttypes: imagelist = self._gui_imagelist(gui_arttype) log('- Number of images: %s' % len(imagelist)) # If more images than 1 found show GUI selection if len(imagelist) > 1: self.mode = 'customgui' log('- Image list larger than 1') if self._choose_image(imagelist): log('- Chosen: %s' % self.image_item) for item in self.settings.available_arttypes: if gui_arttype == item['art_type']: self._download_art(item['art_type'], item['filename'], self.target_artworkdir, item['gui_string']) break self._batch_download(self.download_list) if not self._download_art_succes: dialog('okdialog', line1=__localize__(32006), line2=__localize__(32007)) if self._download_art_succes: log('- Download succesfull') else: log('- Cancelled') dialog('okdialog', line1=__localize__(32017), line2=__localize__(32018)) else: self._download_process() log('- More than 1 image available') # If more than one specified else: log('- Start custom bulkmode') self._download_process()
def _gui_mode(self): # Close the 'checking for artwork' dialog before opening the GUI list dialog('close', background = self.settings.background) self.GUI_type_list = [] imagelist = False # Fill GUI art type list for item in self.settings.available_arttypes: if item['solo_enabled'] == 'true' and self.mediatype == item['media_type']: gui = item['gui_string'] self.GUI_type_list.append (gui) # if len(self.GUI_type_list) == 1: self.GUI_type_list[0] = "True" if ( len(self.GUI_type_list) == 1 ) or self._choice_type(): imagelist = self._gui_imagelist(self.gui_selected_type) # Some debug log output for item in imagelist: log('- Image put to GUI: %s' %item) # Download the selected image if imagelist: if self._choose_image(imagelist): self._download_art(self.gui_selected_type, self.gui_selected_filename, self.target_artworkdir, self.gui_selected_msg) self._batch_download(self.download_list) if not self._download_art_succes: dialog('okdialog', line1 = __localize__(32006) , line2 = __localize__(32007) ) if not imagelist and not self.gui_selected_type == '': log('- No artwork found') dialog('okdialog', line1 = self.media_name , line2 = self.gui_selected_msg + ' ' + __localize__(32022) ) elif self._download_art_succes: log('- Download succesfull') else: log('- Cancelled') dialog('okdialog', line1 = __localize__(32017) , line2 = __localize__(32018) )
def _check(self): settings_faulty = True while settings_faulty: settings_faulty = True check_movie = check_tvshow = check_musicvideo = check_centralize = True # re-check settings after posible change self._get_general() self._get_artwork() # Check if faulty setting in movie section if self.movie_enable: if not self.movie_fanart and not self.movie_extrafanart and not self.movie_extrathumbs and not self.movie_poster: check_movie = False log('Setting check: No subsetting of movies enabled') else: check_movie = True # Check if faulty setting in tvshow section if self.tvshow_enable: if not self.tvshow_poster and not self.tvshow_fanart and not self.tvshow_extrafanart and not self.tvshow_showbanner and not self.tvshow_seasonbanner and not self.tvshow_clearart and not self.tvshow_logo and not self.tvshow_showbanner and not self.tvshow_thumb and not self.tvshow_characterart: check_tvshow = False log('Setting check: No subsetting of tv shows enabled') else: check_tvshow = True # Check if faulty setting in musicvideo section if self.musicvideo_enable: if not self.musicvideo_fanart and not self.musicvideo_extrafanart and not self.musicvideo_extrathumbs and not self.musicvideo_poster: check_musicvideo = False log('Setting check: No subsetting of musicvideo enabled') else: check_musicvideo = True # Check if faulty setting in centralize section if self.centralize_enable: if self.centralfolder_movies == '' and self.centralfolder_tvshows == '': check_centralize = False log('Setting check: No centralized folder chosen') else: check_centralize = True # Compare all setting check if check_movie and check_tvshow and check_musicvideo and check_centralize: settings_faulty = False else: settings_faulty = True # Faulty setting found if settings_faulty: log('Faulty setting combination found') if dialog('yesno', line1=__localize__(32003), line2=__localize__(32004), background=False, nolabel=__localize__(32026), yeslabel=__localize__(32025)): __addon__.openSettings() else: xbmc.abortRequested = True break
def _custom_mode(self): self.download_arttypes = [] # Look for argument matching artwork types for item in sys.argv: for type in self.settings.available_arttypes: if item == type['art_type'] and self.mediatype == type['media_type']: log( '- Custom %s mode arttype: %s' %(type['media_type'],type['art_type']) ) self.download_arttypes.append(item) # If only one specified and not extrafanart/extrathumbs if (len(self.download_arttypes) == 1) and not self.medianame == '' and not 'extrathumbs' in self.download_arttypes and not 'extrafanart' in self.download_arttypes: # Get image list for that specific imagetype for gui_arttype in self.download_arttypes: imagelist = self._gui_imagelist(gui_arttype) log('- Number of images: %s' %len(imagelist)) # If more images than 1 found show GUI selection if len(imagelist) > 1: self.mode = 'customgui' log('- Image list larger than 1') if self._choose_image(imagelist): log('- Chosen: %s'%self.image_item) for item in self.settings.available_arttypes: if gui_arttype == item['art_type']: self._download_art(item['art_type'], item['filename'], self.target_artworkdir, item['gui_string']) break self._batch_download(self.download_list) if not self._download_art_succes: dialog('okdialog', line1 = __localize__(32006) , line2 = __localize__(32007) ) if self._download_art_succes: log('- Download succesfull') else: log('- Cancelled') dialog('okdialog', line1 = __localize__(32017) , line2 = __localize__(32018) ) else: self._download_process() log('- More than 1 image available') # If more than one specified else: log('- Start custom bulkmode') self._download_process()
def _batch_download(self, image_list): log('########################################################') # If image list is empty print log message if len(image_list) == 0: log('- Nothing to download') # If not empty process the image list else: log('- Starting download') # Download artwork that passed the limit check for item in image_list: # Check if cancel has been called to break the loop if dialog('iscanceled', background=self.settings.background): break # Update the dialog dialog('update', percentage=int( float(self.download_counter['Total Artwork']) / float(len(image_list)) * 100.0), line1=item['media_name'], line2=__localize__(32009) + ' ' + item['artwork_string'], line3=item['filename'], background=self.settings.background) # Try downloading the file and catch errors while trying to try: self.fileops._downloadfile(item['url'], item['filename'], item['targetdirs'], item['media_name']) except HTTP404Error, e: log("URL not found: %s" % str(e), xbmc.LOGERROR) self._download_art_succes = False except HTTPTimeout, e: self.settings.failcount += 1 log("Download timed out: %s" % str(e), xbmc.LOGERROR) self._download_art_succes = False except CreateDirectoryError, e: log("Could not create directory, skipping: %s" % str(e), xbmc.LOGWARNING) self._download_art_succes = False
def _gui_mode(self): # Close the 'checking for artwork' dialog before opening the GUI list dialog('close', background=self.settings.background) self.GUI_type_list = [] imagelist = False # Fill GUI art type list for item in self.settings.available_arttypes: if item['solo_enabled'] == 'true' and self.mediatype == item[ 'media_type']: gui = item['gui_string'] self.GUI_type_list.append(gui) # if len(self.GUI_type_list) == 1: self.GUI_type_list[0] = "True" if (len(self.GUI_type_list) == 1) or self._choice_type(): imagelist = self._gui_imagelist(self.gui_selected_type) # Some debug log output for item in imagelist: log('- Image put to GUI: %s' % item) # Download the selected image if imagelist: if self._choose_image(imagelist): self._download_art(self.gui_selected_type, self.gui_selected_filename, self.target_artworkdir, self.gui_selected_msg) self._batch_download(self.download_list) if not self._download_art_succes: dialog('okdialog', line1=__localize__(32006), line2=__localize__(32007)) if not imagelist and not self.gui_selected_type == '': log('- No artwork found') dialog('okdialog', line1=self.media_name, line2=self.gui_selected_msg + ' ' + __localize__(32022)) elif self._download_art_succes: log('- Download succesfull') else: log('- Cancelled') dialog('okdialog', line1=__localize__(32017), line2=__localize__(32018))
def _check(self): settings_faulty = True while settings_faulty: settings_faulty = True check_movie = check_tvshow = check_musicvideo = check_centralize = True # re-check settings after posible change self._get_general() self._get_artwork() # Check if faulty setting in movie section if self.movie_enable: if not self.movie_fanart and not self.movie_extrafanart and not self.movie_extrathumbs and not self.movie_poster: check_movie = False log('Setting check: No subsetting of movies enabled') else: check_movie = True # Check if faulty setting in tvshow section if self.tvshow_enable: if not self.tvshow_poster and not self.tvshow_fanart and not self.tvshow_extrafanart and not self.tvshow_showbanner and not self.tvshow_seasonbanner and not self.tvshow_clearart and not self.tvshow_logo and not self.tvshow_showbanner and not self.tvshow_thumb and not self.tvshow_characterart: check_tvshow = False log('Setting check: No subsetting of tv shows enabled') else: check_tvshow = True # Check if faulty setting in musicvideo section if self.musicvideo_enable: if not self.musicvideo_fanart and not self.musicvideo_extrafanart and not self.musicvideo_extrathumbs and not self.musicvideo_poster: check_musicvideo = False log('Setting check: No subsetting of musicvideo enabled') else: check_musicvideo = True # Check if faulty setting in centralize section if self.centralize_enable: if self.centralfolder_movies == '' and self.centralfolder_tvshows == '': check_centralize = False log('Setting check: No centralized folder chosen') else: check_centralize = True # Compare all setting check if check_movie and check_tvshow and check_musicvideo and check_centralize: settings_faulty = False else: settings_faulty = True # Faulty setting found if settings_faulty: log('Faulty setting combination found') if dialog('yesno', line1 = __localize__(32003), line2 = __localize__(32004), background = False, nolabel = __localize__(32026), yeslabel = __localize__(32025)): __addon__.openSettings() else: xbmc.abortRequested = True break
def _download_art(self, art_type, filename, targetdirs, msg): log('* Image type: %s' %art_type) self.settings.failcount = 0 seasonfile_presents = [] current_artwork = 0 # Used in progras dialog limit_counter = 0 # Used for limiting on number pref_language = language.get_abbrev() # get abbreviation i = 0 # Set loop counter imagefound = False # Set found image false imageignore = False # Set ignaore image false final_image_list = [] if self.mode in ['gui', 'customgui'] and not art_type in ['extrafanart', 'extrathumbs']: final_image_list.append(self.image_item) else: final_image_list = self.image_list if len(final_image_list) == 0: log(' - Nothing to download') else: # Do some language shit # loop two times than skip while ( i < 2 and not imagefound): # when no image found found after one imagelist loop set to english if not imagefound and i == 1: pref_language = 'en' log('! No matching %s artwork found. Searching for English backup' %self.settings.limit_preferred_language, xbmc.LOGNOTICE) # loop through image list for artwork in final_image_list: if art_type in artwork['type']: ### check if script has been cancelled by user if dialog('iscanceled', background = self.settings.background): #dialog('close', background = self.settings.background) break if not self.settings.failcount < self.settings.failthreshold: break # Create an image info list item = {} item['url'] = artwork['url'] item['targetdirs'] = targetdirs item['media_name'] = self.media_name item['artwork_string'] = msg item['artwork_details'] = artwork if i != 1: current_artwork += 1 # File naming if art_type == 'extrafanart': item['filename'] = ('%s.jpg'% artwork['id']) elif art_type == 'extrathumbs': item['filename'] = ( filename % str(limit_counter + 1) ) elif art_type == 'seasonthumb' or art_type == 'seasonbanner' or art_type == 'seasonposter': item['filename'] = ( filename % artwork['season'] ) else: item['filename'] = filename # Continue if self.mode in ['gui', 'customgui'] and not art_type in ['extrafanart', 'extrathumbs']: # Add image to download list self.download_list.append(item) # jump out of the loop imagefound = True else: # Check for set limits limited = self.filters.do_filter( art_type, self.mediatype, item['artwork_details'], limit_counter, pref_language ) # Delete extrafanart when below settings and parsing the reason message if limited[0] and not i == 1 and art_type in [ 'extrafanart', 'extrathumbs' ]: self.fileops._delete_file_in_dirs( item['filename'], item['targetdirs'], limited[1],self.media_name ) # Just ignore image when it's below settings elif limited[0]: imageignore = True log( " - Ignoring (%s): %s" % ( limited[1], item['filename']) ) else: imageignore = False # Always add to list when set to overwrite if self.settings.files_overwrite: log(" - Adding to download list (overwrite enabled): %s" % item['filename'] ) self.download_list.append(item) imagefound = True else: # Check if image already exist missingfiles = False for targetdir in item['targetdirs']: if not self.fileops._exists( os.path.join(targetdir, item['filename']) ): missingfiles = True if missingfiles: # If missing add to list imagefound = True log(" - Adding to download list (does not exist in all target directories): %s" % item['filename'] ) self.download_list.append(item) else: imagefound = True log(" - Ignoring (Exists in all target directories): %s" % item['filename'] ) # Raise limit counter because image was added to list or it already existed # Do some special check on season artwork if art_type == 'seasonthumbs' or art_type == 'seasonbanner' or art_type == 'seasonposter': if artwork['season'] in seasonfile_presents: log('seasonnumber: %s' %artwork['season'] ) limit_counter += 1 else: seasonfile_presents.append( artwork['season'] ) log('Seasons present: %s' %seasonfile_presents ) limit_counter = 0 else: limit_counter += 1 # Check if artwork doesn't exist and the ones available are below settings even after searching for English fallback if limited[0] and imageignore and i == 1: for targetdir in item['targetdirs']: if not self.fileops._exists(os.path.join (targetdir, item['filename']) ) and not art_type in ['extrafanart', 'extrathumbs']: self.failed_items.append('[%s] %s %s' % (self.media_name, art_type, __localize__(32147)) ) # Counter to make the loop twice when nothing found i += 1 # Not loop when preferred language is English because that the same as the backup if pref_language == 'en': i += 2 # Add to failed items if 0 if current_artwork == 0: self.failed_items.append('[%s] %s %s' % (self.media_name, art_type, __localize__(32022)) ) # Print log message number of found images per art type log(' - Found a total of: %s %s' % (current_artwork, art_type) )
def __init__(self): self.initial_vars() self.settings._get_general() # Get settings from settings.xml self.settings._get_artwork() # Get settings from settings.xml self.settings._get_limit() # Get settings from settings.xml self.settings._check() # Check if there are some faulty combinations present self.settings._initiallog() # Create debug log for settings self.settings._vars() # Get some settings vars self.settings._artype_list() # Fill out the GUI and Arttype lists with enabled options if self.initialise(): # Check for silent background mode if self.silent: log('Silent mode') self.settings.background = True self.settings.notify = False # Check for gui mode elif self.mode == 'gui': log('Set dialog and file overwrite true') self.settings.background = False self.settings.notify = False self.settings.files_overwrite = True dialog('create', line1 = __localize__(32008), background = self.settings.background) # Check if mediatype is specified if not self.mediatype == '': # Check if medianame is specified if not self.medianame == '': if self.mode == 'gui': # GUI mode check is at the end of: 'def download_artwork' self.solo_mode(self.mediatype, self.medianame, self.mediapath) else: self.solo_mode(self.mediatype, self.medianame, self.mediapath) if not dialog('iscanceled', background = self.settings.background) and not self.mode == 'customgui': self._batch_download(self.download_list) # No medianame specified else: if self.mediatype == 'movie': log("Bulk mode: movie") self.Medialist = media_listing('movie') self.settings.movie_enable = 'true' self.settings.tvshow_enable = 'false' self.settings.musicvideo_enable = 'false' self.download_artwork(self.Medialist, self.movie_providers) elif self.mediatype == 'tvshow': log("Bulk mode: TV Shows") self.settings.movie_enable = 'false' self.settings.tvshow_enable = 'true' self.settings.musicvideo_enable = 'false' self.Medialist = media_listing('tvshow') self.download_artwork(self.Medialist, self.tv_providers) elif self.mediatype == 'musicvideo': log("Bulk mode: musicvideo") self.Medialist = media_listing('musicvideo') self.settings.movie_enable = 'false' self.settings.tvshow_enable = 'false' self.settings.musicvideo_enable = 'true' self.download_artwork(self.Medialist, self.musicvideo_providers) if not dialog('iscanceled', background = self.settings.background): self._batch_download(self.download_list) # No mediatype is specified else: # activate movie/tvshow/musicvideo for custom run if self.mode == 'custom': self.settings.movie_enable = True self.settings.tvshow_enable = True self.settings.musicvideo_enable = True # Normal oprations check if self.settings.movie_enable and not dialog('iscanceled', background = True): self.Medialist = media_listing('movie') self.mediatype = 'movie' self.download_artwork(self.Medialist, self.movie_providers) else: log('Movie fanart disabled, skipping', xbmc.LOGINFO) if self.settings.tvshow_enable and not dialog('iscanceled', background = True): self.Medialist = media_listing('tvshow') self.mediatype = 'tvshow' self.download_artwork(self.Medialist, self.tv_providers) else: log('TV fanart disabled, skipping', xbmc.LOGINFO) if self.settings.musicvideo_enable and not dialog('iscanceled', background = True): self.Medialist = media_listing('musicvideo') self.mediatype = 'musicvideo' self.download_artwork(self.Medialist, self.musicvideo_providers) else: log('Musicvideo fanart disabled, skipping', xbmc.LOGINFO) if not dialog('iscanceled', background = self.settings.background): self._batch_download(self.download_list) else: log('Initialisation error, script aborting', xbmc.LOGERROR) # Make sure that files_overwrite option get's reset after downloading __addon__.setSetting(id="files_overwrite", value='false') # Cleaning up self.cleanup()
def download_artwork(self, media_list, providers): self.processeditems = 0 for currentmedia in media_list: ### check if XBMC is shutting down if xbmc.abortRequested: log('XBMC abort requested, aborting') self.reportdata += ( '\n - %s: %s' %( __localize__(32150), time.strftime('%d %B %Y - %H:%M')) ) break ### check if script has been cancelled by user if dialog('iscanceled', background = self.settings.background): self.reportdata += ( '\n - %s [%s]: %s' %(__localize__(32151), self.mediatype, time.strftime('%d %B %Y - %H:%M')) ) break # abort script because of to many failures if not self.settings.failcount < self.settings.failthreshold: self.reportdata += ( '\n - %s: %s' %( __localize__(32152), time.strftime('%d %B %Y - %H:%M')) ) break # Declare some vars self.media_id = currentmedia["id"] self.media_name = currentmedia["name"] self.media_path = currentmedia["path"] dialog('update', percentage = int(float(self.processeditems) / float(len(media_list)) * 100.0), line1 = self.media_name, line2 = __localize__(32008), line3 = '', background = self.settings.background) log('########################################################') log('Processing media: %s' % self.media_name, xbmc.LOGNOTICE) # do some id conversions if not self.mediatype == 'tvshow' and self.media_id in ['','tt0000000','0']: log('No IMDB ID found, trying to search themoviedb.org for matching title.', xbmc.LOGNOTICE) self.media_id = tmdb._search_movie(self.media_name,currentmedia["year"]) elif self.mediatype == 'movie' and not self.media_id == '' and not self.media_id.startswith('tt'): log('No valid ID found, trying to search themoviedb.org for matching title.', xbmc.LOGNOTICE) self.media_id = tmdb._search_movie(self.media_name,currentmedia["year"]) ''' elif self.mediatype == 'movie' and not self.media_id == '' and not self.media_id.startswith('tt'): self.media_id_old = self.media_id self.media_id = "tt%.7d" % int(self.media_id) log('No IMDB ID found, try ID conversion: %s -> %s' % (self.media_id_old,self.media_id), xbmc.LOGNOTICE) ''' log('Provider ID: %s' % self.media_id) log('Media path: %s' % self.media_path) # Declare the target folders self.target_extrafanartdirs = [] self.target_extrathumbsdirs = [] self.target_artworkdir = [] artwork_dir = os.path.join(self.media_path + '/') extrafanart_dir = os.path.join(artwork_dir + 'extrafanart' + '/') extrathumbs_dir = os.path.join(artwork_dir + 'extrathumbs' + '/') self.target_artworkdir.append(artwork_dir) self.target_extrafanartdirs.append(extrafanart_dir) self.target_extrathumbsdirs.append(extrathumbs_dir) # Check if using the centralize option if self.settings.centralize_enable: if self.mediatype == 'tvshow': self.target_extrafanartdirs.append(self.settings.centralfolder_tvshows) elif self.mediatype == 'movie': self.target_extrafanartdirs.append(self.settings.centralfolder_movies) # Check for presence of id used by source sites if self.mode == 'gui' and ((self.media_id == '') or (self.mediatype == 'tvshow' and self.media_id.startswith('tt'))): dialog('close', background = self.settings.background) dialog('okdialog','' ,self.media_name , __localize__(32030)) elif self.media_id == '': log('- No ID found, skipping', xbmc.LOGNOTICE) self.failed_items.append('[%s] ID %s' %( self.media_name, __localize__(32022) )) elif self.mediatype == 'tvshow' and self.media_id.startswith('tt'): log('- IMDB ID found for TV show, skipping', xbmc.LOGNOTICE) self.failed_items.append('[%s]: TVDB ID %s' %( self.media_name, __localize__(32022) )) # If correct ID found continue else: self.temp_image_list = [] self.image_list = [] # Run through all providers getting their imagelisting for self.provider in providers: if not self.settings.failcount < self.settings.failthreshold: break artwork_result = '' xmlfailcount = 0 while not artwork_result == 'pass' and not artwork_result == 'skipping': if artwork_result == 'retrying': xbmc.sleep(self.settings.api_timedelay) try: self.temp_image_list = self.provider.get_image_list(self.media_id) 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' self.failed_items.append('[%s] %s' %(self.media_name, __localize__(32133)) ) except ItemNotFoundError, e: errmsg = '%s not found' % self.media_id artwork_result = 'skipping' except ExpatError, e: xmlfailcount += 1 errmsg = 'Error parsing xml: %s' % str(e) artwork_result = 'retrying'
def cleanup(self): if self.fileops._exists(self.fileops.tempdir): dialog('update', percentage = 100, line1 = __localize__(32005), background = self.settings.background) log('Cleaning up temp files') for x in os.listdir(self.fileops.tempdir): tempfile = os.path.join(self.fileops.tempdir, x) self.fileops._delete(tempfile) if self.fileops._exists(tempfile): log('Error deleting temp file: %s' % tempfile, xbmc.LOGERROR) self.fileops._rmdir(self.fileops.tempdir) if self.fileops._exists(self.fileops.tempdir): log('Error deleting temp directory: %s' % self.fileops.tempdir, xbmc.LOGERROR) else: log('Deleted temp directory: %s' % self.fileops.tempdir) ### log results and notify user # Download totals to log and to download report self.reportdata += ( '\n - %s: %s' %(__localize__(32148), time.strftime('%d %B %Y - %H:%M')) ) # Time of finish self.reportdata += ( '\n[B]%s:[/B]' %(__localize__(32020)) ) # Download total header self.reportdata += ( '\n - %s: %s' % (__localize__(32014), self.download_counter['Total Artwork']) )# Total downloaded items # Cycle through the download totals for artwork_type in self.download_counter: if not artwork_type == 'Total Artwork': self.reportdata += '\n - %s: %s' % ( artwork_type, self.download_counter[artwork_type] ) self.reportdata += '\n[B]%s:[/B]' %__localize__(32016) # Failed items header # Cycle through the download totals if not self.failed_items: self.reportdata += '\n - %s' %__localize__(32149) # No failed or missing items found else: for item in getUniq(self.failed_items): self.reportdata += '\n - %s' %item # Build dialog messages summary = __localize__(32012) + ': %s ' % self.download_counter['Total Artwork'] + __localize__(32020) summary_notify = ': %s ' % self.download_counter['Total Artwork'] + __localize__(32020) provider_msg1 = __localize__(32001) provider_msg2 = __localize__(32184) + " | " + __localize__(32185) + " | " + __localize__(32186) # Close dialog in case it was open before doing a notification time.sleep(2) dialog('close', background = self.settings.background) # Print the self.reportdata log message log('Failed items report: %s' % self.reportdata.replace('[B]', '').replace('[/B]', '') ) # Safe the downloadreport to settings folder using save function save_nfo_file(self.reportdata, os.path.join( __addondir__ , 'downloadreport.txt' ) ) # Some dialog checks if self.settings.notify: log('Notify on finished/error enabled') self.settings.background = False if xbmc.Player().isPlayingVideo() or self.silent or self.mode == 'gui' or self.mode == 'customgui' or self.mode == 'custom': log('Silent finish because of playing a video or silent mode') self.settings.background = True if not self.settings.failcount < self.settings.failthreshold: log('Network error detected, script aborted', xbmc.LOGERROR) dialog('okdialog', line1 = __localize__(32010), line2 = __localize__(32011), background = self.settings.background) if not xbmc.abortRequested: # Show dialog/notification if self.settings.background: dialog('okdialog', line0 = summary_notify, line1 = provider_msg1 + ' ' + provider_msg2, background = self.settings.background) else: # When chosen no in the 'yes/no' dialog exicute the viewer.py and parse 'downloadreport' if dialog('yesno', line1 = summary, line2 = provider_msg1, line3 = provider_msg2, background = self.settings.background, nolabel = __localize__(32027), yeslabel = __localize__(32028)): runcmd = os.path.join(__addonpath__, 'resources/lib/viewer.py') xbmc.executebuiltin('XBMC.RunScript (%s,%s) '%(runcmd, 'downloadreport') ) else: dialog('okdialog', line1 = __localize__(32010), line2 = summary, background = self.settings.background) # Container refresh if self.mode in ['gui','customgui']: if self._download_art_succes: xbmc.executebuiltin( "Container.Refresh" )
def cleanup(self): if self.fileops._exists(self.fileops.tempdir): dialog('update', percentage=100, line1=__localize__(32005), background=self.settings.background) log('Cleaning up temp files') for x in os.listdir(self.fileops.tempdir): tempfile = os.path.join(self.fileops.tempdir, x) self.fileops._delete(tempfile) if self.fileops._exists(tempfile): log('Error deleting temp file: %s' % tempfile, xbmc.LOGERROR) self.fileops._rmdir(self.fileops.tempdir) if self.fileops._exists(self.fileops.tempdir): log('Error deleting temp directory: %s' % self.fileops.tempdir, xbmc.LOGERROR) else: log('Deleted temp directory: %s' % self.fileops.tempdir) ### log results and notify user # Download totals to log and to download report self.reportdata += ('\n - Time of finish: %s' % time.strftime('%d %B %Y - %H:%M')) self.reportdata += ('\n[B]Download totaliser:[/B]') self.reportdata += ('\n - Total Artwork: %s' % self.download_counter['Total Artwork']) # Cycle through the download totals for artwork_type in self.download_counter: if not artwork_type == 'Total Artwork': self.reportdata += '\n - %s: %s' % ( artwork_type, self.download_counter[artwork_type]) self.reportdata += '\n[B]Failed items:[/B]' # Cycle through the download totals if not self.failed_items: self.reportdata += '\n - No failed or missing items found' else: for item in getUniq(self.failed_items): self.reportdata += '\n - %s' % item # Build dialog messages summary = __localize__(32012) + ': %s ' % self.download_counter[ 'Total Artwork'] + __localize__(32016) summary_notify = ': %s ' % self.download_counter[ 'Total Artwork'] + __localize__(32016) provider_msg1 = __localize__(32001) provider_msg2 = __localize__(32184) + " | " + __localize__( 32185) + " | " + __localize__(32186) # Close dialog in case it was open before doing a notification time.sleep(2) dialog('close', background=self.settings.background) # Print the self.reportdata log message log('Failed items report: %s' % self.reportdata.replace('[B]', '').replace('[/B]', '')) # Safe the downloadreport to settings folder using save function save_nfo_file(self.reportdata, os.path.join(__addondir__, 'downloadreport.txt')) # Some dialog checks if self.settings.notify: log('Notify on finished/error enabled') self.settings.background = False if xbmc.Player().isPlayingVideo( ) or self.silent or self.mode == 'gui' or self.mode == 'customgui' or self.mode == 'custom': log('Silent finish because of playing a video or silent mode') self.settings.background = True if not self.settings.failcount < self.settings.failthreshold: log('Network error detected, script aborted', xbmc.LOGERROR) dialog('okdialog', line1=__localize__(32010), line2=__localize__(32011), background=self.settings.background) if not xbmc.abortRequested: # Show dialog/notification if self.settings.background: dialog('okdialog', line0=summary_notify, line1=provider_msg1 + ' ' + provider_msg2, background=self.settings.background) else: # When chosen no in the 'yes/no' dialog exicute the viewer.py and parse 'downloadreport' if dialog('yesno', line1=summary, line2=provider_msg1, line3=provider_msg2, background=self.settings.background, nolabel=__localize__(32027), yeslabel=__localize__(32028)): runcmd = os.path.join(__addonpath__, 'resources/lib/viewer.py') xbmc.executebuiltin('XBMC.RunScript (%s,%s) ' % (runcmd, 'downloadreport')) else: dialog('okdialog', line1=__localize__(32010), line2=summary, background=self.settings.background) # Container refresh if self.mode in ['gui', 'customgui']: if self._download_art_succes: xbmc.executebuiltin("Container.Refresh")
def _download_art(self, art_type, filename, targetdirs, msg): log('* Image type: %s' % art_type) self.settings.failcount = 0 seasonfile_presents = [] current_artwork = 0 # Used in progras dialog limit_counter = 0 # Used for limiting on number pref_language = language.get_abbrev() # get abbreviation i = 0 # Set loop counter imagefound = False # Set found image false final_image_list = [] if self.mode in ['gui', 'customgui' ] and not art_type in ['extrafanart', 'extrathumbs']: final_image_list.append(self.image_item) else: final_image_list = self.image_list if len(final_image_list) == 0: log(' - Nothing to download') else: # Do some language shit # loop two times than skip while (i < 2 and not imagefound): # when no image found found after one imagelist loop set to english if not imagefound and i == 1: pref_language = 'en' log( '! No matching %s artwork found. Searching for English backup' % self.settings.limit_preferred_language, xbmc.LOGNOTICE) # loop through image list for artwork in final_image_list: if art_type in artwork['type']: ### check if script has been cancelled by user if dialog('iscanceled', background=self.settings.background): dialog('close', background=self.settings.background) break if not self.settings.failcount < self.settings.failthreshold: break # Create an image info list item = {} item['url'] = artwork['url'] item['targetdirs'] = targetdirs item['media_name'] = self.media_name item['artwork_string'] = msg item['artwork_details'] = artwork if i != 1: current_artwork += 1 # File naming if art_type == 'extrafanart': item['filename'] = ('%s.jpg' % artwork['id']) elif art_type == 'extrathumbs': item['filename'] = (filename % str(limit_counter + 1)) elif art_type == 'seasonthumb' or art_type == 'seasonbanner' or art_type == 'seasonposter': item['filename'] = (filename % artwork['season']) else: item['filename'] = filename # Continue if self.mode in [ 'gui', 'customgui' ] and not art_type in ['extrafanart', 'extrathumbs']: # Add image to download list self.download_list.append(item) # jump out of the loop imagefound = True else: # Check for set limits limited = self.filters.do_filter( art_type, self.mediatype, item['artwork_details'], limit_counter, pref_language) # Delete extrafanart when below settings and parsing the reason message if limited[0] and not i == 1 and art_type in [ 'extrafanart', 'extrathumbs' ]: self.fileops._delete_file_in_dirs( item['filename'], item['targetdirs'], limited[1], self.media_name) # Just ignore image when it's below settings elif limited[0]: log(" - Ignoring (%s): %s" % (limited[1], item['filename'])) # Check if artwork doesn't exist and the ones available are below settings for targetdir in item['targetdirs']: if not self.fileops._exists( os.path.join( targetdir, item['filename']) ) and not art_type in [ 'extrafanart', 'extrathumbs' ]: self.failed_items.append( '[%s] Skipping %s - Below limit setting' % (self.media_name, art_type)) else: # Always add to list when set to overwrite if self.settings.files_overwrite: log(" - Adding to download list (overwrite enabled): %s" % item['filename']) self.download_list.append(item) imagefound = True else: # Check if image already exist missingfiles = False for targetdir in item['targetdirs']: if not self.fileops._exists( os.path.join( targetdir, item['filename'])): missingfiles = True if missingfiles: # If missing add to list imagefound = True log(" - Adding to download list (does not exist in all target directories): %s" % item['filename']) self.download_list.append(item) else: imagefound = True log(" - Ignoring (Exists in all target directories): %s" % item['filename']) # Raise limit counter because image was added to list or it already existed # Do some special check on season artwork if art_type == 'seasonthumbs' or art_type == 'seasonbanner' or art_type == 'seasonposter': if artwork[ 'season'] in seasonfile_presents: log('seasonnumber: %s' % artwork['season']) limit_counter += 1 else: seasonfile_presents.append( artwork['season']) log('Seasons present: %s' % seasonfile_presents) limit_counter = 0 else: limit_counter += 1 # Counter to make the loop twice when nothing found i += 1 # Add to failed items if 0 if current_artwork == 0: self.failed_items.append('[%s] No %s found' % (self.media_name, art_type)) # Print log message number of found images per art type log(' - Found a total of: %s %s' % (current_artwork, art_type))
def __init__(self): self.initial_vars() self.settings._get_general() # Get settings from settings.xml self.settings._get_artwork() # Get settings from settings.xml self.settings._get_limit() # Get settings from settings.xml self.settings._check( ) # Check if there are some faulty combinations present self.settings._initiallog() # Create debug log for settings self.settings._vars() # Get some settings vars self.settings._artype_list( ) # Fill out the GUI and Arttype lists with enabled options if self.initialise(): # Check for silent background mode if self.silent: log('Silent mode') self.settings.background = True self.settings.notify = False # Check for gui mode elif self.mode == 'gui': log('Set dialog and file overwrite true') self.settings.background = False self.settings.notify = False self.settings.files_overwrite = True dialog('create', line1=__localize__(32008), background=self.settings.background) # Check if mediatype is specified if not self.mediatype == '': # Check if medianame is specified if not self.medianame == '': if self.mode == 'gui': # GUI mode check is at the end of: 'def download_artwork' self.solo_mode(self.mediatype, self.medianame, self.mediapath) else: self.solo_mode(self.mediatype, self.medianame, self.mediapath) if not dialog('iscanceled', background=self.settings.background ) and not self.mode == 'customgui': self._batch_download(self.download_list) # No medianame specified else: if self.mediatype == 'movie': log("Bulk mode: movie") self.Medialist = media_listing('movie') self.settings.movie_enable = 'true' self.settings.tvshow_enable = 'false' self.settings.musicvideo_enable = 'false' self.download_artwork(self.Medialist, self.movie_providers) elif self.mediatype == 'tvshow': log("Bulk mode: TV Shows") self.settings.movie_enable = 'false' self.settings.tvshow_enable = 'true' self.settings.musicvideo_enable = 'false' self.Medialist = media_listing('tvshow') self.download_artwork(self.Medialist, self.tv_providers) elif self.mediatype == 'musicvideo': log("Bulk mode: musicvideo") self.Medialist = media_listing('musicvideo') self.settings.movie_enable = 'false' self.settings.tvshow_enable = 'false' self.settings.musicvideo_enable = 'true' self.download_artwork(self.Medialist, self.musicvideo_providers) if not dialog('iscanceled', background=self.settings.background): self._batch_download(self.download_list) # No mediatype is specified else: # activate movie/tvshow/musicvideo for custom run if self.mode == 'custom': self.settings.movie_enable = True self.settings.tvshow_enable = True self.settings.musicvideo_enable = True # Normal oprations check if self.settings.movie_enable and not dialog('iscanceled', background=True): self.Medialist = media_listing('movie') self.mediatype = 'movie' self.download_artwork(self.Medialist, self.movie_providers) else: log('Movie fanart disabled, skipping', xbmc.LOGINFO) if self.settings.tvshow_enable and not dialog('iscanceled', background=True): self.Medialist = media_listing('tvshow') self.mediatype = 'tvshow' self.download_artwork(self.Medialist, self.tv_providers) else: log('TV fanart disabled, skipping', xbmc.LOGINFO) if self.settings.musicvideo_enable and not dialog( 'iscanceled', background=True): self.Medialist = media_listing('musicvideo') self.mediatype = 'musicvideo' self.download_artwork(self.Medialist, self.musicvideo_providers) else: log('Musicvideo fanart disabled, skipping', xbmc.LOGINFO) if not dialog('iscanceled', background=self.settings.background): self._batch_download(self.download_list) else: log('Initialisation error, script aborting', xbmc.LOGERROR) # Make sure that files_overwrite option get's reset after downloading __addon__.setSetting(id="files_overwrite", value='false') # Cleaning up self.cleanup()
def download_artwork(self, media_list, providers): self.processeditems = 0 for currentmedia in media_list: ### check if XBMC is shutting down if xbmc.abortRequested: log('XBMC abort requested, aborting') break ### check if script has been cancelled by user if dialog('iscanceled', background=self.settings.background): self.reportdata += ('\n - add-on cancelled: %s' % time.strftime('%d %B %Y - %H:%M')) break if not self.settings.failcount < self.settings.failthreshold: self.reportdata += ( '\n - add-on aborted because of problems. Check the log: %s' % time.strftime('%d %B %Y - %H:%M')) break # Declare some vars self.media_id = currentmedia["id"] self.media_name = currentmedia["name"] self.media_path = currentmedia["path"] dialog('update', percentage=int( float(self.processeditems) / float(len(media_list)) * 100.0), line1=self.media_name, line2=__localize__(32008), line3='', background=self.settings.background) log('########################################################') log('Processing media: %s' % self.media_name, xbmc.LOGNOTICE) # do some id conversions if not self.mediatype == 'tvshow' and self.media_id in [ '', 'tt0000000', '0' ]: self.media_id = tmdb._search_movie(self.media_name, currentmedia["year"]) log( 'No IMDB ID found, try searching themoviedb.org. Found TMDB ID: %s' % self.media_id, xbmc.LOGNOTICE) elif self.mediatype == 'movie' and not self.media_id == '' and not self.media_id.startswith( 'tt'): self.media_id_old = self.media_id self.media_id = "tt%.7d" % int(self.media_id) log( 'No IMDB ID found, try ID conversion: %s -> %s' % (self.media_id_old, self.media_id), xbmc.LOGNOTICE) log('Provider ID: %s' % self.media_id) log('Media path: %s' % self.media_path) # Declare the target folders self.target_extrafanartdirs = [] self.target_extrathumbsdirs = [] self.target_artworkdir = [] artwork_dir = os.path.join(self.media_path + '/') extrafanart_dir = os.path.join(artwork_dir + 'extrafanart' + '/') extrathumbs_dir = os.path.join(artwork_dir + 'extrathumbs' + '/') self.target_artworkdir.append(artwork_dir) self.target_extrafanartdirs.append(extrafanart_dir) self.target_extrathumbsdirs.append(extrathumbs_dir) # Check if using the centralize option if self.settings.centralize_enable: if self.mediatype == 'tvshow': self.target_extrafanartdirs.append( self.settings.centralfolder_tvshows) elif self.mediatype == 'movie': self.target_extrafanartdirs.append( self.settings.centralfolder_movies) # Check for presence of id used by source sites if self.mode == 'gui' and ((self.media_id == '') or (self.mediatype == 'tvshow' and self.media_id.startswith('tt'))): dialog('close', background=self.settings.background) dialog('okdialog', '', self.media_name, __localize__(32030)) elif self.media_id == '': log('- No ID found, skipping', xbmc.LOGNOTICE) self.failed_items.append('[%s] No ID found, skipping' % self.media_name) elif self.mediatype == 'tvshow' and self.media_id.startswith('tt'): log('- IMDB ID found for TV show, skipping', xbmc.LOGNOTICE) self.failed_items.append( '[%s]: IMDB ID found for TV show, skipping' % self.media_name) # If correct ID found continue else: self.temp_image_list = [] self.image_list = [] # Run through all providers getting their imagelisting for self.provider in providers: if not self.settings.failcount < self.settings.failthreshold: break artwork_result = '' xmlfailcount = 0 while not artwork_result == 'pass' and not artwork_result == 'skipping': if artwork_result == 'retrying': xbmc.sleep(self.settings.api_timedelay) try: self.temp_image_list = self.provider.get_image_list( self.media_id) 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' self.failed_items.append('[%s] No fanart found' % self.media_name) except ItemNotFoundError, e: errmsg = '%s not found' % self.media_id artwork_result = 'skipping' except ExpatError, e: xmlfailcount += 1 errmsg = 'Error parsing xml: %s' % str(e) artwork_result = 'retrying'