Esempio n. 1
0
 def getartwork(self, mediaitem, fsonly=False, skipexisting=True):
     services_hit = False
     error = None
     mediaitem.forcedart = self.get_forced_artwork(mediaitem,
                                                   not skipexisting)
     existingtypes = [key for key, url in mediaitem.art.iteritems() if url]
     existingtypes.extend(mediaitem.forcedart.keys())
     if skipexisting:
         if not fsonly and mediaitem.uniqueids and mediaitem.missingart:
             mediaitem.availableart, error = self.get_external_artwork(
                 mediaitem.mediatype, mediaitem.seasons,
                 mediaitem.uniqueids, mediaitem.missingart)
             services_hit = True
     elif mediaitem.uniqueids:
         mediaitem.availableart, error = self.get_external_artwork(
             mediaitem.mediatype, mediaitem.seasons, mediaitem.uniqueids)
         services_hit = True
     # combine keyart to poster if keyart disabled or 'prefer titlefree poster' option enabled
     if 'keyart' in mediaitem.availableart and (
             settings.titlefree_poster or not mediatypes.get_artinfo(
                 mediaitem.mediatype, 'keyart')['autolimit']):
         if 'poster' not in mediaitem.availableart:
             mediaitem.availableart['poster'] = []
         mediaitem.availableart['poster'].extend(
             mediaitem.availableart['keyart'])
     for arttype, imagelist in mediaitem.availableart.iteritems():
         _sort_images(arttype, imagelist, mediaitem.sourcemedia,
                      mediaitem.mediatype)
     return services_hit, error
Esempio n. 2
0
def prompt_for_artwork(mediatype, medialabel, availableart, monitor):
    if not availableart:
        return None, None

    arttypes = []
    for arttype, artlist in availableart.iteritems():
        if arttype.startswith('season.-1.'):
            # Ignore 'all' seasons artwork, as I can't set artwork for it with JSON
            continue
        label = arttype if not arttype.startswith('season.') else get_seasonlabel(arttype)
        for image in artlist:
            if image.get('existing'):
                arttypes.append({'arttype': arttype, 'label': label, 'count': len(artlist), 'url': image['url']})
                break
        if arttype not in (at['arttype'] for at in arttypes):
            arttypes.append({'arttype': arttype, 'label': label, 'count': len(artlist)})
    arttypes.sort(key=lambda art: sort_arttype(art['arttype']))
    typeselectwindow = ArtworkTypeSelector('DialogSelect.xml', settings.addon_path, arttypes=arttypes,
        medialabel=medialabel, show_refresh=mediatype in mediatypes.require_manualid)
    selectedarttype = None
    selectedart = None
    typelist = [at['arttype'] for at in arttypes]
    while selectedart is None and not monitor.abortRequested():
        # The loop shows the first window if viewer backs out of the second
        selectedarttype = typeselectwindow.prompt()
        if selectedarttype not in typelist:
            return selectedarttype, None
        if not selectedarttype:
            break
        multi = mediatypes.get_artinfo(mediatype, selectedarttype)['multiselect']
        artselectwindow = ArtworkSelector('FileBrowser.xml', settings.addon_path, artlist=availableart[selectedarttype],
            arttype=selectedarttype, medialabel=medialabel, multi=multi)
        selectedart = artselectwindow.prompt()
    return selectedarttype, selectedart
Esempio n. 3
0
    def get_top_missing_art(self, missingarts, mediatype, existingart,
                            availableart):
        # TODO: refactor to `get_top_artwork` that works on a single art type
        if not availableart:
            return {}
        newartwork = {}
        for missingart in missingarts:
            if missingart not in availableart:
                continue
            itemtype, artkey = mediatypes.hack_mediaarttype(
                mediatype, missingart)
            artinfo = mediatypes.get_artinfo(itemtype, artkey)
            if artinfo['multiselect']:
                existingurls = []
                existingartnames = []
                for art, url in existingart.iteritems():
                    if info.arttype_matches_base(art, missingart) and url:
                        existingurls.append(url)
                        existingartnames.append(art)

                newart = [
                    art
                    for art in availableart[missingart] if self._auto_filter(
                        missingart, art, mediatype, availableart[missingart],
                        existingurls)
                ]
                if not newart:
                    continue
                newartcount = 0
                for i in range(0, artinfo['autolimit']):
                    exacttype = '%s%s' % (artkey, i if i else '')
                    if exacttype not in existingartnames:
                        if newartcount >= len(newart):
                            break
                        if exacttype not in newartwork:
                            newartwork[exacttype] = []
                        newartwork[exacttype] = newart[newartcount]['url']
                        newartcount += 1
            else:
                newart = next((art for art in availableart[missingart]
                               if self._auto_filter(missingart, art, mediatype,
                                                    availableart[missingart])),
                              None)
                if newart:
                    newartwork[missingart] = newart['url']
        return newartwork
Esempio n. 4
0
    def _manual_item_process(self, mediaitem, busy):
        self._process_item(mediaitem, True, False)
        busy.close()
        if mediaitem.availableart or mediaitem.forcedart:
            availableart = dict(mediaitem.availableart)
            if mediaitem.mediatype == mediatypes.TVSHOW and 'fanart' in availableart:
                # add unseasoned backdrops as manual-only options for each season fanart
                unseasoned_backdrops = [
                    dict(art) for art in availableart['fanart']
                    if not art.get('hasseason')
                ]
                if unseasoned_backdrops:
                    for season in mediaitem.seasons.keys():
                        key = 'season.{0}.fanart'.format(season)
                        if key in availableart:
                            availableart[key].extend(unseasoned_backdrops)
                        else:
                            availableart[key] = list(unseasoned_backdrops)
            if mediaitem.mediatype in (mediatypes.MOVIE, mediatypes.MOVIESET
                                       ) and 'poster' in availableart:
                # add no-language posters from TMDB as manual-only options for 'keyart'
                nolang_posters = [
                    dict(art) for art in availableart['poster']
                    if not art['language']
                ]
                for art in nolang_posters:
                    if art['provider'].sort == 'themoviedb.org':
                        if 'keyart' not in availableart:
                            availableart['keyart'] = []
                        availableart['keyart'].append(art)
            tag_forcedandexisting_art(availableart, mediaitem.forcedart,
                                      mediaitem.art)
            selectedarttype, selectedart = prompt_for_artwork(
                mediaitem.mediatype, mediaitem.label, availableart,
                self.monitor)
            if selectedarttype and selectedarttype not in availableart:
                self.manual_id(mediaitem)
                return
            if selectedarttype and selectedart:
                if mediatypes.get_artinfo(mediaitem.mediatype,
                                          selectedarttype)['multiselect']:
                    selectedart = info.fill_multiart(mediaitem.art,
                                                     selectedarttype,
                                                     selectedart)
                else:
                    selectedart = {selectedarttype: selectedart}

                selectedart = get_simpledict_updates(mediaitem.art,
                                                     selectedart)
                mediaitem.selectedart = selectedart
                toset = dict(selectedart)
                if settings.remove_deselected_files:
                    self.downloader.remove_deselected_files(mediaitem)
                if mediatypes.downloadanyartwork(mediaitem.mediatype):
                    try:
                        self.downloader.downloadfor(mediaitem, False)
                    except FileError as ex:
                        mediaitem.error = ex.message
                        log(ex.message, xbmc.LOGERROR)
                        xbmcgui.Dialog().notification(
                            "Artwork Beef", ex.message,
                            xbmcgui.NOTIFICATION_ERROR)
                    toset.update(mediaitem.downloadedart)
                if toset:
                    mediaitem.updatedart = toset.keys()
                    add_art_to_library(mediaitem.mediatype, mediaitem.seasons,
                                       mediaitem.dbid, toset)
                self.cachelocal(mediaitem, toset)

                reporting.report_item(mediaitem, True, True,
                                      self.downloader.size)
                if not mediaitem.error:
                    notifycount(len(toset))
        else:
            xbmcgui.Dialog().notification(
                L(NOT_AVAILABLE_MESSAGE),
                L(SOMETHING_MISSING) + ' ' + L(FINAL_MESSAGE), '-', 8000)
        self.finish_run()