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()
def _process_item(self, mediaitem, singleitem=False, auto=True): log("Processing {0} '{1}' automatically.".format( mediaitem.mediatype, mediaitem.label)) mediatype = mediaitem.mediatype onlyfs = self.localmode or mediatypes.only_filesystem( mediaitem.mediatype) if not mediaitem.uniqueids and not onlyfs: mediaitem.missingid = True if singleitem: header = L(NO_IDS_MESSAGE) message = "{0} '{1}'".format(mediatype, mediaitem.label) log(header + ": " + message, xbmc.LOGNOTICE) xbmcgui.Dialog().notification("Artwork Beef: " + header, message, xbmcgui.NOTIFICATION_INFO) if auto: cleaned = get_simpledict_updates(mediaitem.art, cleaner.clean_artwork(mediaitem)) if cleaned: if not self.debug: add_art_to_library(mediatype, mediaitem.seasons, mediaitem.dbid, cleaned) mediaitem.art.update(cleaned) mediaitem.art = dict(item for item in mediaitem.art.iteritems() if item[1]) mediaitem.missingart = list( info.iter_missing_arttypes(mediaitem, mediaitem.art)) services_hit, error = self.gatherer.getartwork(mediaitem, onlyfs, auto) if auto: existingart = dict(mediaitem.art) selectedart = dict( (key, image['url']) for key, image in mediaitem.forcedart.iteritems()) existingart.update(selectedart) # Then add the rest of the missing art selectedart.update( self.get_top_missing_art( info.iter_missing_arttypes(mediaitem, existingart), mediatype, existingart, mediaitem.availableart)) selectedart = get_simpledict_updates(mediaitem.art, selectedart) mediaitem.selectedart = selectedart toset = dict(selectedart) if not self.localmode and mediatypes.downloadanyartwork( mediaitem.mediatype): sh, er = self.downloader.downloadfor(mediaitem) services_hit = services_hit or sh error = error or er toset.update(mediaitem.downloadedart) if toset: mediaitem.updatedart = list( set(mediaitem.updatedart + toset.keys())) if not self.debug: add_art_to_library(mediatype, mediaitem.seasons, mediaitem.dbid, toset) self.cachelocal(mediaitem, toset) if error: if isinstance(error, dict): header = L(PROVIDER_ERROR_MESSAGE).format( error['providername']) error = '{0}: {1}'.format(header, error['message']) mediaitem.error = error log(error, xbmc.LOGWARNING) self.notify_warning(error) elif auto and not self.debug and not self.localmode: if not (mediatype == mediatypes.EPISODE and 'fanart' in mediaitem.skip_artwork) and \ mediatype != mediatypes.SONG: self.processed.set_nextdate( mediaitem.dbid, mediatype, mediaitem.label, datetime_now() + timedelta(days=self.get_nextcheckdelay(mediaitem))) if mediatype == mediatypes.TVSHOW: self.processed.set_data(mediaitem.dbid, mediatype, mediaitem.label, mediaitem.season) if mediaitem.borked_filename: msg = L(FILENAME_ENCODING_ERROR).format(mediaitem.file) if not mediaitem.error: mediaitem.error = msg log(msg, xbmc.LOGWARNING) if self.debug: log(mediaitem, xbmc.LOGNOTICE) return services_hit
def get_seasonlabel(arttype): season = arttype.split('.') if season[1] == '0': return '{0}: {1}'.format(L(SPECIALS), season[2]) elif season[1] != '-1': return '{0}: {1}'.format(L(SEASON_NUMBER).format(season[1]), season[2])
def process_item(self, mediatype, dbid, mode): if self.processor_busy: return if mode == MODE_DEBUG: mode = MODE_AUTO self.set_debug(True) if mode == MODE_GUI: busy = pykodi.get_busydialog() busy.create() if mediatype in mediatypes.artinfo and (mediatype not in mediatypes.audiotypes or get_kodi_version() >= 18): mediaitem = info.MediaItem( quickjson.get_item_details(dbid, mediatype)) log("Processing {0} '{1}' {2}.".format( mediatype, mediaitem.label, 'automatically' if mode == MODE_AUTO else 'manually')) else: if mode == MODE_GUI: busy.close() xbmcgui.Dialog().notification( "Artwork Beef", L(NOT_SUPPORTED_MESSAGE).format(mediatype), '-', 6500) return self.init_run() if mediatype == mediatypes.EPISODE: series = quickjson.get_item_details(mediaitem.tvshowid, mediatypes.TVSHOW) if not any(uniqueid in settings.autoadd_episodes for uniqueid in series['uniqueid'].itervalues()): mediaitem.skip_artwork = ['fanart'] info.add_additional_iteminfo(mediaitem, self.processed, search) if not mediaitem.uniqueids and not mediatypes.only_filesystem( mediaitem.mediatype): if mediatype in mediatypes.require_manualid: self.manual_id(mediaitem) if mode == MODE_GUI: self._manual_item_process(mediaitem, busy) else: medialist = [mediaitem] if mediatype == mediatypes.TVSHOW and not mediatypes.disabled( mediatypes.EPISODE): gen_epthumb = mediatypes.generatethumb(mediatypes.EPISODE) download_ep = mediatypes.downloadanyartwork(mediatypes.EPISODE) if mediaitem.uniqueids and any( x in mediaitem.uniqueids.values() for x in settings.autoadd_episodes): medialist.extend( info.MediaItem(ep) for ep in quickjson.get_episodes(dbid)) elif gen_epthumb or download_ep: for episode in quickjson.get_episodes(dbid): if gen_epthumb and not info.has_generated_thumbnail(episode) \ or download_ep and info.has_art_todownload(episode['art'], mediatypes.EPISODE): episode = info.MediaItem(episode) episode.skip_artwork = ['fanart'] medialist.append(episode) elif mediatype == mediatypes.ARTIST and not mediatypes.disabled( mediatypes.ALBUM): medialist.extend( info.MediaItem(album) for album in quickjson.get_albums( mediaitem.label, mediaitem.dbid)) if mediatype in (mediatypes.ALBUM, mediatypes.ARTIST) and not mediatypes.disabled(mediatypes.ALBUM) \ and not mediatypes.disabled(mediatypes.SONG): medialist.extend( info.MediaItem(song) for song in quickjson.get_songs( mediaitem.mediatype, mediaitem.dbid)) self.process_medialist(medialist, True)
def add_additional_iteminfo(mediaitem, processed, search=None): '''Get more data from the Kodi library, processed items, and look up web service IDs.''' if search and mediaitem.mediatype in search: search = search[mediaitem.mediatype] if mediaitem.mediatype == mediatypes.TVSHOW: # TODO: Split seasons out to separate items if not mediaitem.seasons: mediaitem.seasons, seasonart = _get_seasons_artwork(quickjson.get_seasons(mediaitem.dbid)) mediaitem.art.update(seasonart) if search and settings.default_tvidsource == 'tmdb' and 'tvdb' not in mediaitem.uniqueids: # TODO: Set to the Kodi library if found resultids = search.get_more_uniqueids(mediaitem.uniqueids, mediaitem.mediatype) if 'tvdb' in resultids: mediaitem.uniqueids['tvdb'] = resultids['tvdb'] elif mediaitem.mediatype == mediatypes.SEASON: tvshow = quickjson.get_item_details(mediaitem.tvshowid, mediatypes.TVSHOW) mediaitem.file = tvshow['file'] elif mediaitem.mediatype == mediatypes.EPISODE: if settings.default_tvidsource == 'tmdb': # TheMovieDB scraper sets episode IDs that can't be used in the API, but seriesID/season/episode works uniqueids = quickjson.get_item_details(mediaitem.tvshowid, mediatypes.TVSHOW)['uniqueid'] uniqueid = uniqueids.get('tmdb', uniqueids.get('unknown')) if uniqueid: mediaitem.uniqueids['tmdbse'] = '{0}/{1}/{2}'.format(uniqueid, mediaitem.season, mediaitem.episode) elif mediaitem.mediatype == mediatypes.MOVIESET: if not mediaitem.uniqueids.get('tmdb'): uniqueid = processed.get_data(mediaitem.dbid, mediaitem.mediatype, mediaitem.label) if search and not uniqueid and not mediatypes.only_filesystem(mediaitem.mediatype): searchresults = search.search(mediaitem.label, mediaitem.mediatype) if searchresults: for result in searchresults: if result['label'] == mediaitem.label: uniqueid = result['uniqueids']['tmdb'] break uniqueid = searchresults[0]['uniqueids']['tmdb'] if uniqueid: processed.set_data(mediaitem.dbid, mediatypes.MOVIESET, mediaitem.label, uniqueid) else: processed.set_data(mediaitem.dbid, mediatypes.MOVIESET, mediaitem.label, None) mediaitem.error = L(CANT_FIND_MOVIESET) log("Could not find set '{0}' on TheMovieDB".format(mediaitem.label), xbmc.LOGNOTICE) mediaitem.uniqueids['tmdb'] = uniqueid if not processed.exists(mediaitem.dbid, mediaitem.mediatype, mediaitem.label): _remove_set_movieposters(mediaitem) if settings.setartwork_fromparent and not mediaitem.file: _identify_parent_movieset(mediaitem) elif mediaitem.mediatype == mediatypes.MUSICVIDEO: if not mediaitem.uniqueids.get('mbtrack') or not mediaitem.uniqueids.get('mbgroup') \ or not mediaitem.uniqueids.get('mbartist'): newdata = processed.get_data(mediaitem.dbid, mediaitem.mediatype, mediaitem.label) if newdata: mb_t, mb_al, mb_ar = newdata.split('/') mediaitem.uniqueids = {'mbtrack': mb_t, 'mbgroup': mb_al, 'mbartist': mb_ar} elif search and not mediatypes.only_filesystem(mediaitem.mediatype): results = search.search(mediaitem.label, mediatypes.MUSICVIDEO) uq = results and results[0].get('uniqueids') if uq and uq.get('mbtrack') and uq.get('mbgroup') and uq.get('mbartist'): mediaitem.uniqueids = uq processed.set_data(mediaitem.dbid, mediatypes.MUSICVIDEO, mediaitem.label, uq['mbtrack'] + '/' + uq['mbgroup'] + '/' + uq['mbartist']) else: processed.set_data(mediaitem.dbid, mediatypes.MUSICVIDEO, mediaitem.label, None) mediaitem.error = L(CANT_FIND_MUSICVIDEO) log("Could not find music video '{0}' on TheAudioDB".format(mediaitem.label), xbmc.LOGNOTICE) elif mediaitem.mediatype == mediatypes.ALBUM: folders = _identify_album_folders(mediaitem) if folders: mediaitem.file, mediaitem.discfolders = folders
def finalmessages(count): return (L(ARTWORK_UPDATED_MESSAGE).format(count), L(FINAL_MESSAGE)) if count else \ (L(NO_ARTWORK_UPDATED_MESSAGE), L(SOMETHING_MISSING) + ' ' + L(FINAL_MESSAGE))
def create_progress(self): if not self.visible and settings.progressdisplay == PROGRESS_DISPLAY_FULLPROGRESS: self.progress.create("Artwork Beef: " + L(ADDING_ARTWORK_MESSAGE), "") self.visible = True
def downloadfor(self, mediaitem, allartwork=True): if self.fileerror_count >= FILEERROR_LIMIT: return False, '' if not info.can_saveartwork(mediaitem): return False, '' to_download = get_downloadable_art(mediaitem, allartwork) if not to_download: return False, '' services_hit = False error = '' localfiles = get_local_art(mediaitem, allartwork) for arttype, url in to_download.items(): hostname = urlparse.urlparse(url).netloc if self.provider_errors.get(hostname, 0) >= PROVIDERERROR_LIMIT: continue full_basefilepath = info.build_artwork_basepath(mediaitem, arttype) if not full_basefilepath: continue if self.debug: mediaitem.downloadedart[arttype] = full_basefilepath + '.ext' continue result, err = self.doget(url) if err: error = err self.provider_errors[hostname] = self.provider_errors.get( hostname, 0) + 1 continue if not result: # 404 URL dead, wipe it so we can add another one later mediaitem.downloadedart[arttype] = None continue self.size += int(result.headers.get('content-length', 0)) services_hit = True ext = get_file_extension(result.headers.get('content-type'), url) if not ext: log("Can't determine extension for '{0}'\nfor image type '{1}'" .format(url, arttype)) continue full_basefilepath += '.' + ext if xbmcvfs.exists(full_basefilepath): if extrafanart_name_used(full_basefilepath, localfiles): # REVIEW: can this happen in any other circumstance? full_basefilepath = get_next_filename( full_basefilepath, localfiles) localfiles.append(full_basefilepath) if xbmcvfs.exists( full_basefilepath) and settings.recycle_removed: recyclefile(full_basefilepath) else: folder = os.path.dirname(full_basefilepath) if not xbmcvfs.exists(folder): xbmcvfs.mkdirs(folder) # For now this just downloads the whole thing in memory, then saves it to file. # Maybe chunking it will be better when GIFs are handled file_ = xbmcvfs.File(full_basefilepath, 'wb') with closing(file_): if not file_.write(result.content): self.fileerror_count += 1 raise FileError( L(CANT_WRITE_TO_FILE).format(full_basefilepath)) self.fileerror_count = 0 mediaitem.downloadedart[arttype] = full_basefilepath log("downloaded '{0}'\nto image file '{1}'".format( url, full_basefilepath)) return services_hit, error
def build_video_thumbnail(self, path): url = build_video_thumbnail_path(path) return {'url': url, 'rating': SortedDisplay(0, ''), 'language': 'xx', 'title': L(VIDEO_FILE_THUMB), 'provider': self.name, 'size': SortedDisplay(0, ''), 'preview': url}