def list_update(self): contains = lib_tools().ckKodiSources() if not contains: return try: if not control.existsPath(control.dataPath): control.makeFile(control.dataPath) dbcon = database.connect(control.libcacheFile) dbcur = dbcon.cursor() dbcur.execute('''CREATE TABLE IF NOT EXISTS lists (type TEXT, list_name TEXT, url TEXT, UNIQUE(type, list_name, url));''') dbcur.connection.commit() except: log_utils.error() try: results = dbcur.execute('''SELECT * FROM lists WHERE type="tvshows";''').fetchall() if not results: control.notification(message=32124) return except: log_utils.error() finally: dbcur.close() ; dbcon.close() for list in results: type = list[0] list_name = list[1] url = list[2] # type, list_name, url = list[0], list[1], list[2] try: if 'trakt' in url: from resources.lib.menus import tvshows items = tvshows.TVshows().trakt_list(url, control.setting('trakt.user').strip()) if 'themoviedb' in url: from resources.lib.indexers import tmdb if '/list/' not in url: items = tmdb.TVshows().tmdb_list(url) else: items = tmdb.TVshows().tmdb_collections_list(url) except: log_utils.error() if not items: continue if service_notification and not control.condVisibility('Window.IsVisible(infodialog)') and not control.condVisibility('Player.HasVideo'): control.notification(title='list...' + list_name + ' - ' + type, message=32552) total_added = 0 for i in items: if control.monitor.abortRequested(): return sys.exit() try: files_added = self.add(i['title'], i['year'], i['imdb'], i['tmdb'], i['tvdb'], range=True) if general_notification and files_added > 0: control.notification(title=i['title'], message=32554) if files_added > 0: total_added += 1 except: log_utils.error() if self.library_update == 'true' and not control.condVisibility('Library.IsScanningVideo') and total_added > 0: if contains: control.sleep(10000) control.execute('UpdateLibrary(video)') elif service_notification: control.notification(message=32103)
def getTMDb(self, url, idx=True, cached=True): self.list = [] try: try: url = getattr(self, url + '_link') except: pass try: u = urlparse(url).netloc.lower() except: pass if u in self.tmdb_link and '/list/' in url: self.list = cache.get(tmdb_indexer.TVshows().tmdb_collections_list, 0, url) elif u in self.tmdb_link and not '/list/' in url: duration = 168 if cached else 0 self.list = cache.get(tmdb_indexer.TVshows().tmdb_list, duration, url) if self.list is None: self.list = [] if idx: self.tvshowDirectory(self.list) return self.list except: from resources.lib.modules import log_utils log_utils.error() if not self.list: control.hide() if self.notifications: control.notification(title=32002, message=33049)
def tvshowsUpdate(imdb, tvdb): try: if traktIndicators: return from metahandler import metahandlers from resources.lib.menus import seasons, episodes from resources.lib.indexers import tmdb as tmdb_indexer from resources.lib.database import cache from resources.lib.modules import log_utils # name = addonInfo('name') metaget = metahandlers.MetaData(tmdb_api_key, omdb_api_key, tvdb_api_key) show_meta = metaget.get_meta('tvshow', name='', imdb_id=imdb) log_utils.log('show_meta=%s' % show_meta) tvshowtitle = show_meta.get( 'title', '') # useless because it's in cleantitle format log_utils.log('tvshowtitle=%s' % tvshowtitle) # seasons_meta = seasons.Seasons().get('', '', imdb, '', tvdb, {}, create_directory=False) # items = seasons.Seasons().get('', '', imdb, '', tvdb, {}, create_directory=False) # def get(self, tvshowtitle, year, imdb, tmdb, tvdb, art, idx=True, create_directory=True): tmdb = '' if not tmdb and (imdb or tvdb): try: result = cache.get(tmdb_indexer.TVshows().IdLookup, 96, imdb, tvdb) tmdb = str(result.get('id')) if result else '' except: if control.setting('debug.level') != '1': return from resources.lib.modules import log_utils return log_utils.log( 'tvshowtitle: (%s) missing tmdb_id: ids={imdb: %s, tmdb: %s, tvdb: %s}' % (tvshowtitle, imdb, tmdb, tvdb), __name__, log_utils.LOGDEBUG) # log TMDb shows that they do not have items = cache.get(tmdb_indexer.TVshows().get_showSeasons_meta, 96, tmdb) log_utils.log('items=%s' % items) items = items.get('seasons', []) # for i in items: # items = episodes.Episodes().get('', '', imdb, '', tvdb, {}, create_directory=False) # def get(self, tvshowtitle, year, imdb, tmdb, tvdb, meta, season=None, episode=None, create_directory=True): # log_utils.log('items=%s' % items) for i in range(len(items)): log_utils.log('items[i]=%s' % items[i]) items[i]['season'] = int(items[i]['season']) items[i]['episode'] = int(items[i]['episode']) seasons = {} for i in items: if i['season'] not in seasons: seasons[i['season']] = [] seasons[i['season']].append(i) countSeason = 0 metaget.get_seasons( '', imdb, seasons.keys()) # Must be called to initialize the database. for key, value in iter(seasons.items()): countEpisode = 0 for i in value: countEpisode += int( metaget._get_watched_episode({ 'imdb_id': i['imdb'], 'season': i['season'], 'episode': i['episode'], 'premiered': '' }) == 5) countSeason += int(countEpisode == len(value)) metaget.change_watched( 'season', '', imdb_id=imdb, season=key, watched=5 if countEpisode == len(value) else 4) metaget.change_watched( 'tvshow', '', imdb_id=imdb, watched=5 if countSeason == len(seasons.keys()) else 4) except: from resources.lib.modules import log_utils log_utils.error() containerRefresh()
def super_info(self, i): try: if self.list[i]['metacache']: return imdb = self.list[i].get('imdb', '') ; tmdb = self.list[i].get('tmdb', '') ; tvdb = self.list[i].get('tvdb', '') #### -- Missing id's lookup -- #### trakt_ids = None if (not tmdb or not tvdb) and imdb: trakt_ids = trakt.IdLookup('imdb', imdb, 'show') if (not tmdb or not imdb) and tvdb: trakt_ids = trakt.IdLookup('tvdb', tvdb, 'show') if trakt_ids: if not imdb: imdb = str(trakt_ids.get('imdb', '')) if trakt_ids.get('imdb') else '' if not tmdb: tmdb = str(trakt_ids.get('tmdb', '')) if trakt_ids.get('tmdb') else '' if not tvdb: tvdb = str(trakt_ids.get('tvdb', '')) if trakt_ids.get('tvdb') else '' if not tmdb and (imdb or tvdb): try: result = cache.get(tmdb_indexer.TVshows().IdLookup, 96, imdb, tvdb) tmdb = str(result.get('id', '')) if result.get('id') else '' except: tmdb = '' if not imdb or not tmdb or not tvdb: try: results = trakt.SearchTVShow(quote_plus(self.list[i]['title']), self.list[i]['year'], full=False) if results[0]['show']['title'].lower() != self.list[i]['title'].lower() or int(results[0]['show']['year']) != int(self.list[i]['year']): return # Trakt has "THEM" and "Them" twice for same show, use .lower() ids = results[0].get('show', {}).get('ids', {}) if not imdb: imdb = str(ids.get('imdb', '')) if ids.get('imdb') else '' if not tmdb: tmdb = str(ids.get('tmdb', '')) if ids.get('tmdb') else '' if not tvdb: tvdb = str(ids.get('tvdb', '')) if ids.get('tvdb') else '' except: pass ################################# if not tmdb: if control.setting('debug.level') != '1': return from resources.lib.modules import log_utils log_utils.log('tvshowtitle: (%s) missing tmdb_id' % self.list[i]['title'], __name__, log_utils.LOGDEBUG) # log TMDb shows that they do not have showSeasons = cache.get(tmdb_indexer.TVshows().get_showSeasons_meta, 96, tmdb) if not showSeasons: return values = {} values.update(showSeasons) if not tvdb: tvdb = values.get('tvdb', '') if not values.get('imdb'): values['imdb'] = imdb if not values.get('tmdb'): values['tmdb'] = tmdb if not values.get('tvdb'): values['tvdb'] = tvdb if self.lang != 'en': try: # if self.lang == 'en' or self.lang not in values.get('available_translations', [self.lang]): raise Exception() trans_item = trakt.getTVShowTranslation(imdb, lang=self.lang, full=True) if trans_item: if trans_item.get('title'): values['tvshowtitle'] = trans_item.get('title') values['title'] = trans_item.get('title') if trans_item.get('overview'): values['plot'] =trans_item.get('overview') except: from resources.lib.modules import log_utils log_utils.error() if not self.disable_fanarttv: extended_art = cache.get(fanarttv.get_tvshow_art, 168, tvdb) if extended_art: values.update(extended_art) values = dict((k, v) for k, v in iter(values.items()) if v is not None and v != '') # remove empty keys so .update() doesn't over-write good meta with empty values. self.list[i].update(values) meta = {'imdb': imdb, 'tmdb': tmdb, 'tvdb': tvdb, 'lang': self.lang, 'user': self.user, 'item': values} self.meta.append(meta) except: from resources.lib.modules import log_utils log_utils.error()
def originals(self): originals = tmdb_indexer.TVshows().get_originals() for i in originals: self.list.append({'name': i[0], 'url': self.tmdb_networks_link % ('%s', i[1]), 'image': i[2], 'icon': 'DefaultNetwork.png', 'action': 'tmdbTvshows'}) self.addDirectory(self.list) return self.list
def tmdb_list(self, tvshowtitle, imdb, tmdb, tvdb, art): if not tmdb and (imdb or tvdb): try: result = cache.get(tmdb_indexer.TVshows().IdLookup, 96, imdb, tvdb) tmdb = str(result.get('id')) if result else '' except: log_utils.log( 'tvshowtitle: (%s) missing tmdb_id' % tvshowtitle, __name__, log_utils.LOGDEBUG) # log TMDb does not have show return showSeasons = cache.get(tmdb_indexer.TVshows().get_showSeasons_meta, 96, tmdb) if not showSeasons: return if art: art = jsloads( art ) # prob better off leaving this as it's own dict so seasonDirectory list builder can just pull that out and pass to .setArt() for item in showSeasons[ 'seasons']: # seasons not parsed in tmdb module so ['seasons'] here is direct json response try: if not self.showspecials and item['season_number'] == 0: continue values = {} values.update(showSeasons) values['mediatype'] = 'season' values['premiered'] = str(item.get( 'air_date', '')) if item.get('air_date') else '' values['year'] = showSeasons[ 'year'] # use show year not season year. In seasonDirecotry send InfoLabels year pulled from premiered only. values['unaired'] = '' try: if values['status'].lower() == 'ended': pass # season level unaired elif not values['premiered']: values['unaired'] = 'true' if not self.showunaired: continue pass elif int(re.sub(r'[^0-9]', '', str( values['premiered']))) > int( re.sub(r'[^0-9]', '', str(self.today_date))): values['unaired'] = 'true' if not self.showunaired: continue except: log_utils.error() values['total_episodes'] = item[ 'episode_count'] # will be total for the specific season only values['season_title'] = item['name'] values['plot'] = item['overview'] or showSeasons['plot'] try: values[ 'poster'] = self.tmdb_poster_path + item['poster_path'] except: values['poster'] = '' if not values['poster'] and art: values['poster'] = art['poster'] if 'poster' in art else '' values['season_poster'] = values['poster'] values['season'] = str(int(item['season_number'])) if art: values['fanart'] = art['fanart'] values['icon'] = art['icon'] values['thumb'] = art['thumb'] values['banner'] = art['banner'] values['clearlogo'] = art['clearlogo'] values['clearart'] = art['clearart'] values['landscape'] = art['landscape'] for k in ('seasons', ): values.pop( k, None ) # pop() keys from showSeasons that are not needed anymore self.list.append(values) except: log_utils.error() return self.list
def range(self, url, list_name): control.hide() if not control.yesnoDialog(control.lang(32555), '', ''): return try: if 'traktcollection' in url: message = 32661 elif 'traktwatchlist' in url: message = 32662 elif all(i in url for i in ['trakt', '/me/', '/lists/']): message = 32663 elif all(i in url for i in ['trakt', '/lists/']) and '/me/' not in url: message = 32664 elif 'tmdb_watchlist' in url: message = 32679 elif 'tmdb_favorites' in url: message = 32680 elif all(i in url for i in ['themoviedb', '/list/']): message = 32681 else: message = 'list import' except: log_utils.error() if general_notification: if not control.condVisibility('Window.IsVisible(infodialog)') and not control.condVisibility('Player.HasVideo'): control.notification(message=message) items = [] try: if 'trakt' in url: if 'traktcollection' in url: url = 'https://api.trakt.tv/users/me/collection/shows' if 'traktwatchlist' in url: url = 'https://api.trakt.tv/users/me/watchlist/shows' from resources.lib.menus import tvshows items = tvshows.TVshows().trakt_list(url, control.setting('trakt.user').strip()) if 'tmdb' in url: if 'tmdb_watchlist' in url: url = 'https://api.themoviedb.org/3/account/{account_id}/watchlist/tv?api_key=%s&session_id=%s' % ('%s', tmdb_session_id) if 'tmdb_favorites' in url: url = 'https://api.themoviedb.org/3/account/{account_id}/favorite/tv?api_key=%s&session_id=%s' % ('%s', tmdb_session_id) from resources.lib.indexers import tmdb items = tmdb.TVshows().tmdb_list(url) if (all(i in url for i in ['themoviedb', '/list/'])): url = url.split('&sort_by')[0] from resources.lib.indexers import tmdb items = tmdb.TVshows().tmdb_collections_list(url) except: log_utils.error() if items is None or items == []: if general_notification: control.notification(title=message, message=33049) return contains = lib_tools().ckKodiSources() total_added = 0 for i in items: if control.monitor.abortRequested(): return sys.exit() try: files_added = self.add(i['title'], i['year'], i['imdb'], i['tmdb'], i['tvdb'], range=True) if general_notification and files_added > 0: control.notification(title=i['title'], message=32554) if files_added > 0: total_added += 1 except: log_utils.error() try: type = 'tvshows' control.makeFile(control.dataPath) dbcon = database.connect(control.libcacheFile) dbcur = dbcon.cursor() dbcur.execute('''CREATE TABLE IF NOT EXISTS lists (type TEXT, list_name TEXT, url TEXT, UNIQUE(type, list_name, url));''') dbcur.execute('''INSERT OR REPLACE INTO lists Values (?, ?, ?)''', (type, list_name, url)) dbcur.connection.commit() except: log_utils.error() finally: dbcur.close() ; dbcon.close() if self.library_update == 'true' and not control.condVisibility('Library.IsScanningVideo') and total_added > 0: if contains: control.sleep(10000) control.execute('UpdateLibrary(video)') elif general_notification: control.notification(message=32103)
def items_list(tvmaze_id): # if i['metacache']: return # not possible with only a tvmaze_id try: values = {} values['next'] = next values['tvmaze'] = tvmaze_id url = self.tvmaze_info_link % tvmaze_id item = get_request(url) values['content'] = item.get('type', '').lower() values['mediatype'] = 'tvshow' values['title'] = item.get('name') values['originaltitle'] = values['title'] values['tvshowtitle'] = values['title'] values['premiered'] = str(item.get( 'premiered', '')) if item.get('premiered') else '' try: values['year'] = values['premiered'][:4] except: values['year'] = '' ids = item.get('externals') imdb = str(ids.get('imdb', '')) if ids.get('imdb') else '' tvdb = str(ids.get('thetvdb', '')) if ids.get('thetvdb') else '' tmdb = '' # TVMaze does not have tmdb_id in api studio = item.get('network', {}) or item.get('webChannel', {}) values['studio'] = studio.get('name', '') values['genre'] = [] for i in item['genres']: values['genre'].append(i.title()) if values['genre'] == []: values['genre'] = 'NA' values['duration'] = int(item.get( 'runtime', '')) * 60 if item.get('runtime') else '' values['rating'] = str(item.get('rating').get( 'average', '')) if item.get('rating').get('average') else '' values['plot'] = client.cleanHTML(item['summary']) values['status'] = item.get('status', '') values['castandart'] = [] for person in item['_embedded']['cast']: try: values['castandart'].append({ 'name': person['person']['name'], 'role': person['character']['name'], 'thumbnail': (person['person']['image']['medium'] if person['person']['image']['medium'] else '') }) except: pass if len(values['castandart']) == 150: break image = item.get('image', {}) or '' values['poster'] = image.get('original', '') if image else '' values['fanart'] = '' values['banner'] = '' values['mpaa'] = '' values['votes'] = '' try: values['airday'] = item['schedule']['days'][0] except: values['airday'] = '' values['airtime'] = item['schedule']['time'] or '' try: values['airzone'] = item['network']['country']['timezone'] except: values['airzone'] = '' values['metacache'] = False #### -- Missing id's lookup -- #### if not tmdb and (imdb or tvdb): try: result = cache.get(tmdb_indexer.TVshows().IdLookup, 96, imdb, tvdb) tmdb = str(result.get('id', '')) if result.get('id') else '' except: tmdb = '' if not imdb or not tmdb or not tvdb: try: trakt_ids = trakt.SearchTVShow(quote_plus( values['tvshowtitle']), values['year'], full=False) if not trakt_ids: raise Exception ids = trakt_ids[0].get('show', {}).get('ids', {}) if not imdb: imdb = str(ids.get('imdb', '')) if ids.get('imdb') else '' if not tmdb: tmdb = str(ids.get('tmdb', '')) if ids.get('tmdb') else '' if not tvdb: tvdb = str(ids.get('tvdb', '')) if ids.get('tvdb') else '' except: log_utils.error() ################################# if not tmdb: return log_utils.log( 'tvshowtitle: (%s) missing tmdb_id: ids={imdb: %s, tmdb: %s, tvdb: %s}' % (values['tvshowtitle'], imdb, tmdb, tvdb), __name__, log_utils.LOGDEBUG ) # log TMDb shows that they do not have # self.list = metacache.fetch(self.list, self.lang, self.user) # if self.list['metacache'] is True: raise Exception() showSeasons = cache.get( tmdb_indexer.TVshows().get_showSeasons_meta, 96, tmdb) if not showSeasons: return showSeasons = dict( (k, v) for k, v in iter(showSeasons.items()) if v is not None and v != '' ) # removes empty keys so .update() doesn't over-write good meta values.update(showSeasons) if not values.get('imdb'): values['imdb'] = imdb if not values.get('tmdb'): values['tmdb'] = tmdb if not values.get('tvdb'): values['tvdb'] = tvdb for k in ('seasons', ): values.pop( k, None ) # pop() keys from showSeasons that are not needed anymore if self.enable_fanarttv: extended_art = fanarttv_cache.get(fanarttv.get_tvshow_art, 168, tvdb) if extended_art: values.update(extended_art) meta = { 'imdb': imdb, 'tmdb': tmdb, 'tvdb': tvdb, 'lang': self.lang, 'user': self.user, 'item': values } # DO NOT move this after "values = dict()" below or it becomes the same object and "del meta['item']['next']" removes it from both values = dict((k, v) for k, v in iter(values.items()) if v is not None and v != '') self.list.append(values) if 'next' in meta.get('item'): del meta['item']['next'] # next can not exist in metacache self.meta.append(meta) self.meta = [ i for i in self.meta if i.get('tmdb') ] # without this ui removed missing tmdb but it still writes these cases to metacache? metacache.insert(self.meta) except: log_utils.error()
def tmdb_list(self, tvshowtitle, imdb, tmdb, tvdb, art): #### -- Missing id's lookup -- #### trakt_ids = None if (not tmdb or not tvdb) and imdb: trakt_ids = trakt.IdLookup('imdb', imdb, 'show') elif (not tmdb or not imdb) and tvdb: trakt_ids = trakt.IdLookup('tvdb', tvdb, 'show') if trakt_ids: if not imdb: imdb = str(trakt_ids.get('imdb', '')) if trakt_ids.get('imdb') else '' if not tmdb: tmdb = str(trakt_ids.get('tmdb', '')) if trakt_ids.get('tmdb') else '' if not tvdb: tvdb = str(trakt_ids.get('tvdb', '')) if trakt_ids.get('tvdb') else '' if not tmdb and (imdb or tvdb): try: result = cache.get(tmdb_indexer.TVshows().IdLookup, 96, imdb, tvdb) tmdb = str(result.get('id')) if result else '' except: if getSetting('debug.level') != '1': return from resources.lib.modules import log_utils return log_utils.log( 'tvshowtitle: (%s) missing tmdb_id: ids={imdb: %s, tmdb: %s, tvdb: %s}' % (tvshowtitle, imdb, tmdb, tvdb), __name__, log_utils.LOGDEBUG) # log TMDb shows that they do not have ################################# showSeasons = cache.get(tmdb_indexer.TVshows().get_showSeasons_meta, 96, tmdb) if not showSeasons: return if not showSeasons.get('imdb'): showSeasons[ 'imdb'] = imdb # use value passed from tvshows super_info() due to extensive ID lookups if not showSeasons.get('tvdb'): showSeasons['tvdb'] = tvdb if art: art = jsloads( art ) # prob better off leaving this as it's own dict so seasonDirectory list builder can just pull that out and pass to .setArt() for item in showSeasons[ 'seasons']: # seasons not parsed in tmdb module so ['seasons'] here is direct json response try: if not self.showspecials and item['season_number'] == 0: continue values = {} values.update(showSeasons) values['mediatype'] = 'season' values['premiered'] = str(item.get( 'air_date', '')) if item.get('air_date') else '' values['year'] = showSeasons[ 'year'] # use show year not season year. In seasonDirecotry send InfoLabels year pulled from premiered only. values['unaired'] = '' try: if values['status'].lower() == 'ended': pass # season level unaired elif not values['premiered']: values['unaired'] = 'true' if not self.showunaired: continue pass elif int(re.sub(r'[^0-9]', '', str( values['premiered']))) > int( re.sub(r'[^0-9]', '', str(self.today_date))): values['unaired'] = 'true' if not self.showunaired: continue except: from resources.lib.modules import log_utils log_utils.error() values['total_episodes'] = item[ 'episode_count'] # will be total for the specific season only values['season_title'] = item['name'] values['plot'] = item['overview'] or showSeasons['plot'] try: values[ 'poster'] = self.tmdb_poster_path + item['poster_path'] except: values['poster'] = '' if not values['poster'] and art: values['poster'] = art['poster'] if 'poster' in art else '' values['season_poster'] = values['poster'] values['season'] = str(int(item['season_number'])) if self.enable_fanarttv: values['season_poster2'] = fanarttv.get_season_poster( tvdb, values['season']) if art: values['fanart'] = art['fanart'] values['icon'] = art['icon'] values['thumb'] = art[ 'thumb'] # thumb here is show_poster from show level TMDb module values['banner'] = art['banner'] values['clearlogo'] = art['clearlogo'] values['clearart'] = art['clearart'] values['landscape'] = art['landscape'] values['tvshow.poster'] = art[ 'tvshow.poster'] # not used in seasonDirectory() atm for k in ('seasons', ): values.pop( k, None ) # pop() keys from showSeasons that are not needed anymore self.list.append(values) except: from resources.lib.modules import log_utils log_utils.error() return self.list