def get_nextcheckdelay(self, mediaitem): weeks = 4 if mediatypes.only_filesystem(mediaitem.mediatype) \ else 32 if mediaitem.missingid or not mediaitem.missingart \ or mediaitem.mediatype in (mediatypes.MOVIE, mediatypes.TVSHOW) \ and mediaitem.premiered < self.freshstart \ else 16 return plus_some(weeks * 7, weeks)
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 _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 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)