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) )
示例#2
0
    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))