Beispiel #1
0
    def _download_art(self, currentmedia, art_item, targetdirs):
        log('* Image type: %s' % art_item['art_type'])
        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
        missingfiles = False
        global download_list
        final_image_list = []
        if startup['mode'] in [
                'gui', 'customgui'
        ] and not art_item['art_type'] in ['extrafanart', 'extrathumbs']:
            final_image_list.append(image_list)
        else:
            final_image_list = 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'
                        % limit['limit_preferred_language'])
                # loop through image list
                for artwork in final_image_list:
                    if art_item['art_type'] in artwork['art_type']:
                        ### check if script has been cancelled by user
                        if dialog_msg('iscanceled',
                                      background=setting['background']):
                            #dialog('close', background = setting['background'])
                            break
                        # Create an image info list
                        item = {
                            'url': artwork['url'],
                            'targetdirs': targetdirs,
                            'media_name': currentmedia['name'],
                            'mediatype': currentmedia['mediatype'],
                            'artwork_string': art_item['gui_string'],
                            'artwork_details': artwork,
                            'dbid': currentmedia['dbid'],
                            'art': currentmedia['art'],
                            'art_type': art_item['art_type']
                        }
                        # raise artwork counter only on first loop
                        if i != 1:
                            current_artwork += 1

                        # File naming
                        if art_item['art_type'] == 'extrafanart':
                            item['filename'] = ('%s.jpg' % artwork['id'])
                        elif art_item['art_type'] == 'extrathumbs':
                            item['filename'] = (art_item['filename'] %
                                                str(limit_counter + 1))
                        elif art_item['art_type'] in ['seasonposter']:
                            if artwork['season'] == '0':
                                item['filename'] = "season-specials-poster.jpg"
                            elif artwork['season'] == 'all':
                                item['filename'] = "season-all-poster.jpg"
                            elif artwork['season'] == 'n/a':
                                break
                            else:
                                item['filename'] = (art_item['filename'] %
                                                    int(artwork['season']))
                        elif art_item['art_type'] in ['seasonbanner']:
                            if artwork['season'] == '0':
                                item['filename'] = "season-specials-banner.jpg"
                            elif artwork['season'] == 'all':
                                item['filename'] = "season-all-banner.jpg"
                            elif artwork['season'] == 'n/a':
                                break
                            else:
                                item['filename'] = (art_item['filename'] %
                                                    int(artwork['season']))
                        elif art_item['art_type'] in ['seasonlandscape']:
                            if artwork['season'] == 'all' or artwork[
                                    'season'] == '':
                                item['filename'] = "season-all-landscape.jpg"
                            else:
                                item['filename'] = (art_item['filename'] %
                                                    int(artwork['season']))
                        else:
                            item['filename'] = art_item['filename']
                        for targetdir in item['targetdirs']:
                            item['localfilename'] = os.path.join(
                                targetdir, item['filename']).encode('utf-8')
                            break

                        # Continue
                        if startup['mode'] in [
                                'gui', 'customgui'
                        ] and not art_item['art_type'] in [
                                'extrafanart', 'extrathumbs'
                        ]:
                            # Add image to download list
                            download_list.append(item)
                            # jump out of the loop
                            imagefound = True
                        else:
                            # Check for set limits
                            if (setting['files_local']
                                    and not item['url'].startswith('http')
                                    and not art_item['art_type']
                                    in ['extrafanart', 'extrathumbs']):
                                # if it's a local file use this first
                                limited = [False, 'This is your local file']
                            elif art_item['art_type'] == 'discart':
                                limited = filter(art_item['art_type'],
                                                 startup['mediatype'],
                                                 item['artwork_details'],
                                                 limit_counter, pref_language,
                                                 currentmedia['disctype'])
                            else:
                                limited = filter(art_item['art_type'],
                                                 startup['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_item[
                                    'art_type'] in [
                                        'extrafanart', 'extrathumbs'
                                    ]:
                                #self.fileops._delete_file_in_dirs(item['filename'], item['targetdirs'], limited[1],currentmedia['name'])
                                pass
                            # Just ignore image when it's below settings
                            elif limited[0]:
                                imageignore = True
                                log(' - Ignoring (%s): %s' %
                                    (limited[1], item['filename']))
                            else:
                                # Always add to list when set to overwrite
                                if setting['files_overwrite']:
                                    log(' - Adding to download list (overwrite enabled): %s'
                                        % item['filename'])
                                    download_list.append(item)
                                    imagefound = True
                                else:
                                    artcheck = item['art']
                                    # Check if extrathumbs/extrafanart image already exist local
                                    if art_item['art_type'] in [
                                            'extrathumbs', 'extrafanart'
                                    ]:
                                        for targetdir in item['targetdirs']:
                                            if not self.fileops._exists(
                                                    os.path.join(
                                                        targetdir,
                                                        item['filename'])):
                                                missingfiles = True
                                    # Check if image already exist in database
                                    elif not art_item['art_type'] in [
                                            'seasonlandscape', 'seasonbanner',
                                            'seasonposter'
                                    ]:
                                        if setting[
                                                'files_local'] and not self.fileops._exists(
                                                    item['localfilename']):
                                            missingfiles = True
                                        elif not artcheck.get(
                                                art_item['art_type']):
                                            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'])
                                        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
                                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_item['art_type'] in
                                            ['extrafanart', 'extrathumbs']):
                                            failed_items.append(
                                                '[%s] %s %s' %
                                                (currentmedia['name'],
                                                 art_item['art_type'],
                                                 __localize__(32147)))
                            # Do some special check on season artwork
                            if art_item[
                                    'art_type'] == 'seasonlandscape' or art_item[
                                        'art_type'] == 'seasonbanner' or art_item[
                                            'art_type'] == 'seasonposter':
                                # If already present in list set limit on 1 so it is skipped
                                limit_counter = 0
                                if artwork['season'] in seasonfile_presents:
                                    log('seasonnumber: %s' % artwork['season'])
                                    limit_counter = 1
                                # If not present in list but found image add it to list and reset counter limit
                                elif imagefound:
                                    seasonfile_presents.append(
                                        artwork['season'])
                                    log('Seasons present: %s' %
                                        seasonfile_presents)
                                # if not found and not already in list set limit to zero and image found false
                                else:
                                    imagefound = False
                # 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:
                failed_items.append(
                    '[%s] %s %s' % (currentmedia['name'], art_item['art_type'],
                                    __localize__(32022)))
            # Print log message number of found images per art type
            log(' - Found a total of: %s %s' %
                (current_artwork, art_item['art_type']))
    def _download_art(self, currentmedia, art_item, targetdirs):
        log('* Image type: %s' %art_item['art_type'])
        seasonfile_presents = []
        current_artwork = 0                     # Used in progras dialog
        limit_counter = 0                       # Used for limiting on number
        pref_language = get_abbrev(setting_limit['limit_preferred_language'])
        i = 0                                   # Set loop counter
        imagefound = False                      # Set found image false
        imageignore = False                     # Set ignaore image false
        missingfiles = False
        global download_list
        final_image_list = []
        if startup['mode'] in ['gui', 'customgui'] and not art_item['art_type'] in ['extrafanart', 'extrathumbs']:
            final_image_list.append(image_list)
        else:
            final_image_list = 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' %limit['limit_preferred_language'])
                # loop through image list
                for artwork in final_image_list:
                    if art_item['art_type'] in artwork['art_type']:
                        ### check if script has been cancelled by user
                        if xbmc.abortRequested or dialog_msg('iscanceled',
                                                             background = setting['background']):
                            dialog_msg('close',
                                       background = setting['background'])
                            break
                        # Add need info to artwork item
                        artwork['targetdirs'] = targetdirs
                        artwork['media_name'] = currentmedia['name']
                        artwork['mediatype'] = currentmedia['mediatype']
                        artwork['artwork_string'] = art_item['gui_string']
                        artwork['dbid'] = currentmedia['dbid']
                        artwork['art'] = currentmedia['art']
                        # raise artwork counter only on first loop
                        if i != 1:
                            current_artwork += 1

                        # File naming
                        if art_item['art_type']   == 'extrafanart':
                            artwork['filename'] = ('%s.jpg'% artwork['id'])
                        elif art_item['art_type'] == 'extrathumbs':
                            artwork['filename'] = (art_item['filename'] % str(limit_counter + 1))
                        elif art_item['art_type'] in ['seasonposter']:
                            if artwork['season'] == '0':
                                artwork['filename'] = "season-specials-poster.jpg"
                            elif artwork['season'] == 'all':
                                artwork['filename'] = "season-all-poster.jpg"
                            elif artwork['season'] == 'n/a':
                                break
                            else:
                                artwork['filename'] = (art_item['filename'] % int(artwork['season']))
                        elif art_item['art_type'] in ['seasonbanner']:
                            if artwork['season'] == '0':
                                artwork['filename'] = "season-specials-banner.jpg"
                            elif artwork['season'] == 'all':
                                artwork['filename'] = "season-all-banner.jpg"
                            elif artwork['season'] == 'n/a':
                                break
                            else:
                                artwork['filename'] = (art_item['filename'] % int(artwork['season']))
                        elif art_item['art_type'] in ['seasonlandscape']:
                            if artwork['season'] == 'all' or artwork['season'] == '':
                                artwork['filename'] = "season-all-landscape.jpg"
                            else:
                                artwork['filename'] = (art_item['filename'] % int(artwork['season']))
                        else:
                            # only use <movie_filename>-<art_type>.ext for movies
                            if artwork['mediatype'] == 'movie':
                                artwork['filename'] = currentmedia['base_name'] + '-' + art_item['filename']
                            else:
                                artwork['filename'] = art_item['filename']

                        for targetdir in artwork['targetdirs']:
                            artwork['localfilename'] = os.path.join(targetdir, artwork['filename']).encode('utf-8')
                            break

                        # Continue
                        if startup['mode'] in ['gui', 'customgui'] and not art_item['art_type'] in ['extrafanart', 'extrathumbs']:
                            # Add image to download list
                            download_list.append(artwork)
                            # jump out of the loop
                            imagefound = True
                        else:
                            # Check for set limits
                            if (setting['files_local'] and not
                                artwork['url'].startswith('http') and not
                                art_item['art_type'] in ['extrafanart', 'extrathumbs']):
                                # if it's a local file use this first
                                limited = [False, 'This is your local file']
                            elif art_item['art_type'] == 'discart':
                                limited = filter(art_item['art_type'],
                                                 startup['mediatype'],
                                                 artwork,
                                                 limit_counter,
                                                 pref_language,
                                                 currentmedia['disctype'])
                            else:
                                limited = filter(art_item['art_type'],
                                                 startup['mediatype'],
                                                 artwork,
                                                 limit_counter,
                                                 pref_language)
                            # Delete extrafanart when below settings and parsing the reason message
                            if limited[0] and not i == 1 and art_item['art_type'] in ['extrafanart', 'extrathumbs']:
                                #self.fileops._delete_file_in_dirs(artwork['filename'], artwork['targetdirs'], limited[1],currentmedia['name'])
                                pass
                            # Just ignore image when it's below settings
                            elif limited[0]:
                                imageignore = True
                                log(' - Ignoring (%s): %s' % (limited[1], artwork['filename']))
                            else:
                                # Always add to list when set to overwrite
                                if setting['files_overwrite']:
                                    log(' - Adding to download list (overwrite enabled): %s' % artwork['filename'])
                                    download_list.append(artwork)
                                    imagefound = True
                                elif currentmedia['force_update']:
                                    log(' - Adding to download list (rename detected): %s' % artwork['filename'])
                                    download_list.append(artwork)
                                    imagefound = True
                                else:
                                    artcheck = artwork['art']
                                    # Check if extrathumbs/extrafanart image already exist local
                                    if art_item['art_type'] in ['extrathumbs','extrafanart']:
                                        for targetdir in artwork['targetdirs']:
                                            if not self.fileops._exists(os.path.join(targetdir, artwork['filename'])):
                                                missingfiles = True
                                    # Check if image already exist in database
                                    elif not art_item['art_type'] in ['seasonlandscape','seasonbanner','seasonposter']:
                                        if setting['files_local']and not self.fileops._exists(artwork['localfilename']):
                                            missingfiles = True
                                        elif not artcheck.get(art_item['art_type']):
                                            missingfiles = True
                                    if missingfiles:
                                        # If missing add to list
                                        imagefound = True
                                        log(' - Adding to download list (does not exist in all target directories): %s' % artwork['filename'])
                                        download_list.append(artwork)
                                    else:
                                        imagefound = True
                                        log(' - Ignoring (Exists in all target directories): %s' % artwork['filename'])
                                # Raise limit counter because image was added to list or it already existed
                                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 artwork['targetdirs']:
                                        if (not self.fileops._exists(os.path.join (targetdir, artwork['filename'])) and not
                                            art_item['art_type'] in ['extrafanart', 'extrathumbs']):
                                            failed_items.append('[%s] %s %s' % (currentmedia['name'], art_item['art_type'], __localize__(32147)))
                            # Do some special check on season artwork
                            if art_item['art_type'] == 'seasonlandscape' or art_item['art_type'] == 'seasonbanner' or art_item['art_type']   == 'seasonposter':
                                # If already present in list set limit on 1 so it is skipped
                                limit_counter = 0
                                if artwork['season'] in seasonfile_presents:
                                    log('seasonnumber: %s' %artwork['season'])
                                    limit_counter = 1
                                # If not present in list but found image add it to list and reset counter limit
                                elif imagefound:
                                    seasonfile_presents.append(artwork['season'])
                                    log('Seasons present: %s' %seasonfile_presents)
                                # if not found and not already in list set limit to zero and image found false
                                else:
                                    imagefound = False
                # 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:
                failed_items.append('[%s] %s %s' % (currentmedia['name'], art_item['art_type'], __localize__(32022)))
            # Print log message number of found images per art type
            log(' - Found a total of: %s %s' % (current_artwork, art_item['art_type']))