def tvshows(tvshowtitle, imdb, tvdb, season, watched): control.busy() try: import sys,xbmc if not trakt.getTraktIndicatorsInfo() == False: raise Exception() from metahandler import metahandlers from resources.lib.indexers import episodes metaget = metahandlers.MetaData(preparezip=False) name = control.addonInfo('name') dialog = control.progressDialogBG dialog.create(str(name), str(tvshowtitle)) dialog.update(0, str(name), str(tvshowtitle)) metaget.get_meta('tvshow', name='', imdb_id=imdb) items = episodes.episodes().get(tvshowtitle, '0', imdb, tvdb, '0', idx=False) try: items = [i for i in items if int('%01d' % int(season)) == int('%01d' % int(i['season']))] except: pass items = [{'label': '%s S%02dE%02d' % (tvshowtitle, int(i['season']), int(i['episode'])), 'season': int('%01d' % int(i['season'])), 'episode': int('%01d' % int(i['episode']))} for i in items] for i in range(len(items)): if xbmc.abortRequested == True: return sys.exit() dialog.update(int((100 / float(len(items))) * i), str(name), str(items[i]['label'])) season, episode = items[i]['season'], items[i]['episode'] metaget.get_episode_meta('', imdb_id=imdb, season=season, episode=episode) metaget.change_watched('episode', '', imdb_id=imdb, season=season, episode=episode, watched=int(watched)) try: dialog.close() except: pass except: try: dialog.close() except: pass try: if trakt.getTraktIndicatorsInfo() == False: raise Exception() if season: from resources.lib.indexers import episodes items = episodes.episodes().get(tvshowtitle, '0', imdb, tvdb, season, idx=False) items = [(int(i['season']), int(i['episode'])) for i in items] items = [i[1] for i in items if int('%01d' % int(season)) == int('%01d' % i[0])] for i in items: if int(watched) == 7: trakt.markEpisodeAsWatched(tvdb, season, i) else: trakt.markEpisodeAsNotWatched(tvdb, season, i) else: if int(watched) == 7: trakt.markTVShowAsWatched(tvdb) else: trakt.markTVShowAsNotWatched(tvdb) trakt.cachesyncTVShows() except: pass control.refresh()
def add(self, tvshowtitle, year, imdb, tmdb, tvdb, tvrage, range=False): if not control.condVisibility('Window.IsVisible(infodialog)') and not control.condVisibility('Player.HasVideo'): control.infoDialog(control.lang(30421).encode('utf-8'), time=10000000) self.infoDialog = True from resources.lib.indexers import episodes items = episodes.episodes().get(tvshowtitle, year, imdb, tmdb, tvdb, tvrage, idx=False) try: items = [{'name': i['name'], 'title': i['title'], 'year': i['year'], 'imdb': i['imdb'], 'tmdb': i['tmdb'], 'tvdb': i['tvdb'], 'tvrage': i['tvrage'], 'season': i['season'], 'episode': i['episode'], 'tvshowtitle': i['tvshowtitle'], 'alter': i['alter'], 'date': i['premiered']} for i in items] except: items = [] try: if not self.dupe_setting == 'true': raise Exception() if items == []: raise Exception() id = [items[0]['imdb'], items[0]['tvdb']] if not items[0]['tmdb'] == '0': id += [items[0]['tmdb']] lib = control.jsonrpc('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": {"properties" : ["imdbnumber", "title", "year"]}, "id": 1}') lib = unicode(lib, 'utf-8', errors='ignore') lib = json.loads(lib)['result']['tvshows'] lib = [i['title'].encode('utf-8') for i in lib if str(i['imdbnumber']) in id or (i['title'].encode('utf-8') == items[0]['tvshowtitle'] and str(i['year']) == items[0]['year'])][0] lib = control.jsonrpc('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": {"filter":{"and": [{"field": "tvshow", "operator": "is", "value": "%s"}]}, "properties": ["season", "episode"]}, "id": 1}' % lib) lib = unicode(lib, 'utf-8', errors='ignore') lib = json.loads(lib)['result']['episodes'] lib = ['S%02dE%02d' % (int(i['season']), int(i['episode'])) for i in lib] items = [i for i in items if not 'S%02dE%02d' % (int(i['season']), int(i['episode'])) in lib] except: pass for i in items: try: if xbmc.abortRequested == True: return sys.exit() if self.check_setting == 'true': if i['episode'] == '1': self.block = True from resources.lib.sources import sources src = sources().checkSources(i['name'], i['title'], i['year'], i['imdb'], i['tmdb'], i['tvdb'], i['tvrage'], i['season'], i['episode'], i['tvshowtitle'], i['alter'], i['date']) if src == True: self.block = False if self.block == True: raise Exception() if int(self.date) <= int(re.sub('[^0-9]', '', str(i['date']))): from resources.lib.sources import sources src = sources().checkSources(i['name'], i['title'], i['year'], i['imdb'], i['tmdb'], i['tvdb'], i['tvrage'], i['season'], i['episode'], i['tvshowtitle'], i['alter'], i['date']) if src == False: raise Exception() self.strmFile(i) except: pass if range == True: return if self.infoDialog == True: control.infoDialog(control.lang(30423).encode('utf-8'), time=1) if self.library_setting == 'true' and not control.condVisibility('Library.IsScanningVideo'): control.execute('UpdateLibrary(video)')
def add(self, tvshowtitle, year, imdb, tmdb, tvdb, tvrage, range=False): if not control.condVisibility('Window.IsVisible(infodialog)') and not control.condVisibility('Player.HasVideo'): control.infoDialog(control.lang(30421).encode('utf-8'), time=10000000) self.infoDialog = True from resources.lib.indexers import episodes items = episodes.episodes().get(tvshowtitle, year, imdb, tmdb, tvdb, tvrage, idx=False) try: items = [{'name': i['name'], 'title': i['title'], 'year': i['year'], 'imdb': i['imdb'], 'tmdb': i['tmdb'], 'tvdb': i['tvdb'], 'tvrage': i['tvrage'], 'season': i['season'], 'episode': i['episode'], 'tvshowtitle': i['tvshowtitle'], 'alter': i['alter'], 'date': i['premiered']} for i in items] except: items = [] try: if not self.dupe_setting == 'true': raise Exception() if items == []: raise Exception() id = [items[0]['imdb'], items[0]['tvdb']] if not items[0]['tmdb'] == '0': id += [items[0]['tmdb']] lib = control.jsonrpc('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": {"properties" : ["imdbnumber", "title", "year"]}, "id": 1}') lib = unicode(lib, 'utf-8', errors='ignore') lib = json.loads(lib)['result']['tvshows'] lib = [i['title'].encode('utf-8') for i in lib if str(i['imdbnumber']) in id or (i['title'].encode('utf-8') == items[0]['tvshowtitle'] and str(i['year']) == items[0]['year'])][0] lib = control.jsonrpc('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": {"filter":{"and": [{"field": "tvshow", "operator": "is", "value": "%s"}]}, "properties": ["season", "episode"]}, "id": 1}' % lib) lib = unicode(lib, 'utf-8', errors='ignore') lib = json.loads(lib)['result']['episodes'] lib = ['S%02dE%02d' % (int(i['season']), int(i['episode'])) for i in lib] items = [i for i in items if not 'S%02dE%02d' % (int(i['season']), int(i['episode'])) in lib] except: pass for i in items: try: if xbmc.abortRequested == True: return sys.exit() if self.check_setting == 'true': if i['episode'] == '1': self.block = True from resources.lib.sources import sources src = sources().getSources(i['name'], i['title'], i['year'], i['imdb'], i['tmdb'], i['tvdb'], i['tvrage'], i['season'], i['episode'], i['tvshowtitle'], i['alter'], i['date']) if len(src) > 0: self.block = False if self.block == True: raise Exception() if int(self.date) <= int(re.sub('[^0-9]', '', str(i['date']))): from resources.lib.sources import sources src = sources().getSources(i['name'], i['title'], i['year'], i['imdb'], i['tmdb'], i['tvdb'], i['tvrage'], i['season'], i['episode'], i['tvshowtitle'], i['alter'], i['date']) if not len(src) > 0: raise Exception() self.strmFile(i) except: pass if range == True: return if self.infoDialog == True: control.infoDialog(control.lang(30423).encode('utf-8'), time=1) if self.library_setting == 'true' and not control.condVisibility('Library.IsScanningVideo'): control.execute('UpdateLibrary(video)')
def seasonList(self, url): # Dirty implementation, but avoids rewritting everything from episodes.py. episodes = episodesx.episodes(type = self.type, kids = self.kids) self.list = cache.get(episodes.trakt_list, 0, url, self.trakt_user) self.list = self.list[::-1] tvshows = tvshowsx.tvshows(type = self.type, kids = self.kids) tvshows.list = self.list tvshows.worker() self.list = tvshows.list # Remove duplicate season entries. try: result = [] for i in self.list: found = False for j in result: if i['imdb'] == j['imdb'] and i['season'] == j['season']: found = True break if not found: result.append(i) self.list = result except: pass self.seasonDirectory(self.list)
def tvshows(tvshowtitle, year, imdb, tvdb, season, watched): traktMode = False if trakt.getTraktCredentials() == False else True watched = int(watched) try: if traktMode == True: raise Exception() from metahandler import metahandlers from resources.lib.indexers import episodes metaget = metahandlers.MetaData(preparezip=False) dialog = control.progressDialog dialog.create(control.addonInfo('name'), str(tvshowtitle)) dialog.update(0, str(tvshowtitle), control.lang(30451).encode('utf-8') + '...') metaget.get_meta('tvshow', '', imdb_id=imdb) items = episodes.episodes().get(tvshowtitle, year, imdb, '0', tvdb, '0', idx=False) try: items = [i for i in items if int('%01d' % int(season)) == int('%01d' % int(i['season']))] except: pass items = [ {'name': i['name'], 'season': int('%01d' % int(i['season'])), 'episode': int('%01d' % int(i['episode']))} for i in items] for i in range(len(items)): if xbmc.abortRequested == True: return sys.exit() if dialog.iscanceled(): return dialog.close() dialog.update(int((100 / float(len(items))) * i), str(tvshowtitle), str(items[i]['name'])) season, episode = items[i]['season'], items[i]['episode'] metaget.get_episode_meta('', imdb, season, episode) metaget.change_watched('episode', '', imdb, season=season, episode=episode, year='', watched=watched) try: dialog.close() except: pass except: try: dialog.close() except: pass try: if traktMode == False: raise Exception() if watched == 7: trakt.markTVShowAsWatched(tvdb) else: trakt.markTVShowAsNotWatched(tvdb) trakt.syncTVShows() except: pass control.refresh()
def resolveSeason(title, year, imdb, tvdb): result = episodes.episodes(type=self.mType, kids=self.mKids, notifications=False).get( title, year, imdb, tvdb) lock.acquire() itemsEpisodes.extend(result) lock.release()
def seasonList(self, url): # Dirty implementation, but avoids rewritting everything from episodes.py. episodes = episodesx.episodes(type=self.type, kids=self.kids) self.list = cache.get(episodes.trakt_list, 0, url, self.trakt_user) self.list = self.list[::-1] episodes.list = self.list episodes.worker() self.list = episodes.list self.seasonDirectory(self.list)
def seasonList(self, url): # Dirty implementation, but avoids rewritting everything from episodes.py. episodes = episodesx.episodes(type = self.type, kids = self.kids) self.list = cache.get(episodes.trakt_list, 0, url, self.trakt_user) self.list = self.list[::-1] episodes.list = self.list episodes.worker() self.list = episodes.list self.seasonDirectory(self.list)
def userlists(self): episodes = episodesx.episodes(type = self.type, kids = self.kids) userlists = [] try: if trakt.getTraktCredentialsInfo() == False: raise Exception() activity = trakt.getActivity() except: pass try: if trakt.getTraktCredentialsInfo() == False: raise Exception() self.list = [] try: if activity > cache.timeout(episodes.trakt_user_list, self.traktlists_link, self.trakt_user): raise Exception() userlists += cache.get(episodes.trakt_user_list, 3, self.traktlists_link, self.trakt_user) except: userlists += cache.get(episodes.trakt_user_list, 0, self.traktlists_link, self.trakt_user) except: pass try: if trakt.getTraktCredentialsInfo() == False: raise Exception() self.list = [] try: if activity > cache.timeout(episodes.trakt_user_list, self.traktlikedlists_link, self.trakt_user): raise Exception() userlists += cache.get(episodes.trakt_user_list, 3, self.traktlikedlists_link, self.trakt_user) except: userlists += cache.get(episodes.trakt_user_list, 0, self.traktlikedlists_link, self.trakt_user) except: pass self.list = [] # Filter the user's own lists that were for i in range(len(userlists)): contains = False adapted = userlists[i]['url'].replace('/me/', '/%s/' % self.trakt_user) for j in range(len(self.list)): if adapted == self.list[j]['url'].replace('/me/', '/%s/' % self.trakt_user): contains = True break if not contains: self.list.append(userlists[i]) for i in range(0, len(self.list)): self.list[i].update({'image': 'traktlists.png', 'action': self.parameterize('seasonsList')}) # Watchlist if trakt.getTraktCredentialsInfo(): self.list.insert(0, {'name' : interface.Translation.string(32033), 'url' : self.traktwatchlist_link, 'image': 'traktwatch.png', 'action': self.parameterize('seasons')}) episodes.addDirectory(self.list, queue = True) return self.list
def userlists(self): episodes = episodesx.episodes(type = self.type, kids = self.kids) userlists = [] try: if trakt.getTraktCredentialsInfo() == False: raise Exception() activity = trakt.getActivity() except: pass try: if trakt.getTraktCredentialsInfo() == False: raise Exception() self.list = [] try: if activity > cache.timeout(episodes.trakt_user_list, self.traktlists_link, self.trakt_user): raise Exception() userlists += cache.get(episodes.trakt_user_list, 3, self.traktlists_link, self.trakt_user) except: userlists += cache.get(episodes.trakt_user_list, 0, self.traktlists_link, self.trakt_user) except: pass try: if trakt.getTraktCredentialsInfo() == False: raise Exception() self.list = [] try: if activity > cache.timeout(episodes.trakt_user_list, self.traktlikedlists_link, self.trakt_user): raise Exception() userlists += cache.get(episodes.trakt_user_list, 3, self.traktlikedlists_link, self.trakt_user) except: userlists += cache.get(episodes.trakt_user_list, 0, self.traktlikedlists_link, self.trakt_user) except: pass self.list = [] # Filter the user's own lists that were for i in range(len(userlists)): contains = False adapted = userlists[i]['url'].replace('/me/', '/%s/' % self.trakt_user) for j in range(len(self.list)): if adapted == self.list[j]['url'].replace('/me/', '/%s/' % self.trakt_user): contains = True break if not contains: self.list.append(userlists[i]) for i in range(0, len(self.list)): self.list[i].update({'image': 'traktlists.png', 'action': self.parameterize('seasonList')}) # Watchlist if trakt.getTraktCredentialsInfo(): self.list.insert(0, {'name' : interface.Translation.string(32033), 'url' : self.traktwatchlist_link, 'context' : self.traktwatchlist_link, 'image': 'traktwatch.png', 'action': self.parameterize('seasons')}) episodes.addDirectory(self.list, queue = True) return self.list
def tvshows(tvshowtitle, year, imdb, tvdb, season, watched): traktMode = False if trakt.getTraktCredentials() == False else True watched = int(watched) try: if traktMode == True: raise Exception() from metahandler import metahandlers from resources.lib.indexers import episodes metaget = metahandlers.MetaData(preparezip=False) dialog = control.progressDialog dialog.create(control.addonInfo('name'), str(tvshowtitle)) dialog.update(0, str(tvshowtitle), control.lang(30451).encode('utf-8') + '...') metaget.get_meta('tvshow', '', imdb_id=imdb) items = episodes.episodes().get(tvshowtitle, year, imdb, '0', tvdb, '0', idx=False) try: items = [i for i in items if int('%01d' % int(season)) == int('%01d' % int(i['season']))] except: pass items = [{'name': i['name'], 'season': int('%01d' % int(i['season'])), 'episode': int('%01d' % int(i['episode']))} for i in items] for i in range(len(items)): if xbmc.abortRequested == True: return sys.exit() if dialog.iscanceled(): return dialog.close() dialog.update(int((100 / float(len(items))) * i), str(tvshowtitle), str(items[i]['name'])) season, episode = items[i]['season'], items[i]['episode'] metaget.get_episode_meta('', imdb, season, episode) metaget.change_watched('episode', '', imdb, season=season, episode=episode, year='', watched=watched) try: dialog.close() except: pass except: try: dialog.close() except: pass try: if traktMode == False: raise Exception() if watched == 7: trakt.markTVShowAsWatched(tvdb) else: trakt.markTVShowAsNotWatched(tvdb) trakt.syncTVShows() except: pass control.refresh()
def tvshowsUpdate(imdb, tvdb): try: from metahandler import metahandlers from resources.lib.indexers import episodes if not trakt.getTraktIndicatorsInfo() == False: raise Exception() name = control.addonInfo('name') metaget = metahandlers.MetaData(preparezip=False) metaget.get_meta('tvshow', name='', imdb_id=imdb) items = episodes.episodes().get('', '0', imdb, tvdb, idx=False) for i in range(len(items)): items[i]['season'] = int(items[i]['season']) items[i]['episode'] = int(items[i]['episode']) seasons = {} for i in items: if not i['season'] 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 seasons.iteritems(): countEpisode = 0 for i in value: countEpisode += int( metaget._get_watched_episode({ 'imdb_id': i['imdb'], 'season': i['season'], 'episode': i['episode'], 'premiered': '' }) == 7) countSeason += int(countEpisode == len(value)) metaget.change_watched( 'season', '', imdb_id=imdb, season=key, watched=7 if countEpisode == len(value) else 6) metaget.change_watched( 'tvshow', '', imdb_id=imdb, watched=7 if countSeason == len(seasons.keys()) else 6) except: tools.Logger.error() control.refresh()
def _televisionAddMultiple(self, link): interface.Loader.hide() count = -1 if interface.Dialog.option(title=33244, message=35179): count = 0 if self._ready(): interface.Dialog.notification( title=33244, message=35177, icon=interface.Dialog.IconInformation, time=100000000) self.mDialog = True items = None try: from resources.lib.indexers import tvshows items = tvshows.tvshows().get(link, idx=False, notifications=False) except: pass if not items or len(items) == 0: from resources.lib.indexers import episodes items = episodes.episodes().calendar(link) if items == None: items = [] for i in items: try: if tools.System.aborted(): return sys.exit() count += self._televisionAddSingle( i['tvshowtitle'] if 'tvshowtitle' in i else i['title'], i['year'], i['imdb'], i['tvdb'], i, multiple=True) except: pass return count
def tvshows(tvshowtitle, imdb, tvdb, season, watched): try: import sys,xbmc if not trakt.getTraktIndicatorsInfo() == False: raise Exception() watched=int(watched) from metahandler import metahandlers from resources.lib.indexers import episodes imdb = imdb.encode('utf-8') metaget = metahandlers.MetaData(preparezip=False) name = control.addonInfo('name') dialog = control.progressDialogBG dialog.create(str(name), str(tvshowtitle)) dialog.update(0, str(name), str(tvshowtitle)) items = episodes.episodes().get(tvshowtitle, '0', imdb, tvdb, '0', idx=False) try: items = [i for i in items if int('%01d' % int(season)) == int('%01d' % int(i['season']))] except: pass items = [{'label': '%s S%02dE%02d' % (tvshowtitle, int(i['season']), int(i['episode'])), 'season': int('%01d' % int(i['season'])), 'episode': int('%01d' % int(i['episode']))} for i in items] for i in range(len(items)): if xbmc.abortRequested == True: return sys.exit() dialog.update(int((100 / float(len(items))) * i), str(name), str(items[i]['label'])) season, episode = items[i]['season'], items[i]['episode'] metaget.get_episode_meta('', imdb, season, episode) metaget.change_watched('episode', '', imdb, season=season, episode=episode, year='', watched=watched) try: dialog.close() except: pass except: try: dialog.close() except: pass control.refresh()
def tvshows(tvshowtitle, imdb, tmdb, season, watched): control.busy() try: import sys, xbmc if not trakt.getTraktIndicatorsInfo() == False: raise Exception() from resources.lib.indexers import episodes name = control.addonInfo('name') dialog = control.progressDialogBG dialog.create(str(name), str(tvshowtitle)) dialog.update(0, str(name), str(tvshowtitle)) #log_utils.log('playcount_season: ' + str(season)) items = [] if season: items = episodes.episodes().get(tvshowtitle, '0', imdb, tmdb, meta=None, season=season, idx=False) items = [ i for i in items if int('%01d' % int(season)) == int('%01d' % int(i['season'])) ] items = [{ 'label': '%s S%02dE%02d' % (tvshowtitle, int(i['season']), int(i['episode'])), 'season': int('%01d' % int(i['season'])), 'episode': int('%01d' % int(i['episode'])), 'unaired': i['unaired'] } for i in items] for i in range(len(items)): if control.monitor.abortRequested(): return sys.exit() dialog.update(int((100 / float(len(items))) * i), str(name), str(items[i]['label'])) _season, _episode, unaired = items[i]['season'], items[i][ 'episode'], items[i]['unaired'] if int(watched) == 7: if not unaired == 'true': bookmarks.reset(1, 1, 'episode', imdb, _season, _episode) else: pass else: bookmarks._delete_record('episode', imdb, _season, _episode) else: seasons = episodes.seasons().get(tvshowtitle, '0', imdb, tmdb, meta=None, idx=False) seasons = [i['season'] for i in seasons] #log_utils.log('playcount_seasons: ' + str(seasons)) for s in seasons: items = episodes.episodes().get(tvshowtitle, '0', imdb, tmdb, meta=None, season=s, idx=False) items = [{ 'label': '%s S%02dE%02d' % (tvshowtitle, int(i['season']), int(i['episode'])), 'season': int('%01d' % int(i['season'])), 'episode': int('%01d' % int(i['episode'])), 'unaired': i['unaired'] } for i in items] #log_utils.log('playcount_items2: ' + str(items)) for i in range(len(items)): if control.monitor.abortRequested(): return sys.exit() dialog.update(int((100 / float(len(items))) * i), str(name), str(items[i]['label'])) _season, _episode, unaired = items[i]['season'], items[i][ 'episode'], items[i]['unaired'] if int(watched) == 7: if not unaired == 'true': bookmarks.reset(1, 1, 'episode', imdb, _season, _episode) else: pass else: bookmarks._delete_record('episode', imdb, _season, _episode) try: dialog.close() except: pass except: log_utils.log('playcount_local_shows', 1) try: dialog.close() except: pass try: if trakt.getTraktIndicatorsInfo() == False: raise Exception() #log_utils.log('playcount_season: ' + str(season)) if season: from resources.lib.indexers import episodes items = episodes.episodes().get(tvshowtitle, '0', imdb, tmdb, meta=None, season=season, idx=False) items = [(int(i['season']), int(i['episode'])) for i in items] items = [ i[1] for i in items if int('%01d' % int(season)) == int('%01d' % i[0]) ] for i in items: if int(watched) == 7: trakt.markEpisodeAsWatched(imdb, season, i) else: trakt.markEpisodeAsNotWatched(imdb, season, i) else: if int(watched) == 7: trakt.markTVShowAsWatched(imdb) else: trakt.markTVShowAsNotWatched(imdb) trakt.cachesyncTVShows() except: log_utils.log('playcount_trakt_shows', 1) pass control.refresh() control.idle()
elif action == 'tvYears': from resources.lib.indexers import tvshows tvshows.tvshows().years() elif action == 'tvUserlists': from resources.lib.indexers import tvshows tvshows.tvshows().userlists() elif action == 'seasons': from resources.lib.indexers import episodes episodes.seasons().get(tvshowtitle, year, imdb, tmdb, tvdb, tvrage) elif action == 'episodes': from resources.lib.indexers import episodes episodes.episodes().get(tvshowtitle, year, imdb, tmdb, tvdb, tvrage, season, episode) elif action == 'calendar': from resources.lib.indexers import episodes episodes.episodes().calendar(url) elif action == 'tvWidget': from resources.lib.indexers import episodes episodes.episodes().widget() elif action == 'episodeFavourites': from resources.lib.indexers import episodes episodes.episodes().favourites() elif action == 'calendars': from resources.lib.indexers import episodes
elif action == 'authTrakt' : trakt.authTrakt() elif action == 'backupwatchlist' : fn = os.path.join(datapath, 'favourites.db') if os.path.exists(fn): backupdir = control.setting('remote_path') if not backupdir == '': to_backup = xbmc.translatePath(os.path.join('special://', 'profile/addon_data/')) rootlen = len(datapath) backup_ui_zip = xbmc.translatePath(os.path.join(backupdir, 'uranus_watchlist.zip')) zipobj = zipfile.ZipFile(backup_ui_zip , 'w', zipfile.ZIP_DEFLATED) zipobj.write(fn, fn[rootlen:]) dialog.ok('Backup Watchlist', 'Backup complete', '', '') else: dialog.ok('Backup Watchlist', 'No backup location found: Please setup your Backup location in the addon settings', '', '') xbmc.executebuiltin('RunPlugin(%s?action=openSettings&query=7.0)' % sys.argv[0]) elif action == 'calendar' : episodes.episodes().calendar(url) elif action == 'calendars' : episodes.episodes().calendars() elif action == 'channels' : channels.channels().get() elif action == 'clearCache' : navigator.navigator().clearCache() elif action == 'clearProgress': progressFile = os.path.join(datapath, 'progress.db') if os.path.exists(progressFile): if control.yesnoDialog(control.lang(32056).encode('utf-8'), '', ''): try: os.remove(progressFile) dialog.ok('Clear Progress', 'Clear Progress Complete', '', '') except: dialog.ok('Clear Progress', 'There was an error Deleting the Database', '', '') else: control.infoDialog(control.lang2(161).encode('utf-8'), heading='"Progress Database"', sound=False, icon=thumbnail) elif action == 'clearSources' :
def add(self, tvshowtitle, year, imdb, tvdb, range=False): if not control.condVisibility( "Window.IsVisible(infodialog)" ) and not control.condVisibility("Player.HasVideo"): control.infoDialog(control.lang(32552).encode("utf-8"), time=10000000) self.infoDialog = True from resources.lib.indexers import episodes items = episodes.episodes().get(tvshowtitle, year, imdb, tvdb, idx=False) try: items = [ { "title": i["title"], "year": i["year"], "imdb": i["imdb"], "tvdb": i["tvdb"], "season": i["season"], "episode": i["episode"], "tvshowtitle": i["tvshowtitle"], "premiered": i["premiered"], } for i in items ] except: items = [] try: if not self.dupe_setting == "true": raise Exception() if items == []: raise Exception() id = [items[0]["imdb"], items[0]["tvdb"]] lib = control.jsonrpc( '{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": {"properties" : ["imdbnumber", "title", "year"]}, "id": 1}' ) lib = unicode(lib, "utf-8", errors="ignore") lib = json.loads(lib)["result"]["tvshows"] lib = [ i["title"].encode("utf-8") for i in lib if str(i["imdbnumber"]) in id or ( i["title"].encode("utf-8") == items[0]["tvshowtitle"] and str(i["year"]) == items[0]["year"] ) ][0] lib = control.jsonrpc( '{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": {"filter":{"and": [{"field": "tvshow", "operator": "is", "value": "%s"}]}, "properties": ["season", "episode"]}, "id": 1}' % lib ) lib = unicode(lib, "utf-8", errors="ignore") lib = json.loads(lib)["result"]["episodes"] lib = ["S%02dE%02d" % (int(i["season"]), int(i["episode"])) for i in lib] items = [ i for i in items if not "S%02dE%02d" % (int(i["season"]), int(i["episode"])) in lib ] except: pass files_added = 0 for i in items: try: if xbmc.abortRequested == True: return sys.exit() if self.check_setting == "true": if i["episode"] == "1": self.block = True src = lib_tools.check_sources( i["title"], i["year"], i["imdb"], i["tvdb"], i["season"], i["episode"], i["tvshowtitle"], i["premiered"], ) if src: self.block = False if self.block == True: raise Exception() premiered = i.get("premiered", "0") if ( premiered != "0" and int(re.sub("[^0-9]", "", str(premiered))) > int(self.date) ) or (premiered == "0" and not self.include_unknown): continue self.strmFile(i) files_added += 1 except: pass if range == True: return if self.infoDialog == True: control.infoDialog(control.lang(32554).encode("utf-8"), time=1) if ( self.library_setting == "true" and not control.condVisibility("Library.IsScanningVideo") and files_added > 0 ): control.execute("UpdateLibrary(video)")
elif action == 'tvNetworks': from resources.lib.indexers import tvshows tvshows.tvshows().networks() elif action == 'tvYears': from resources.lib.indexers import tvshows tvshows.tvshows().years() elif action == 'tvUserlists': from resources.lib.indexers import tvshows tvshows.tvshows().userlists() elif action == 'tvWidget': from resources.lib.indexers import episodes episodes.episodes().widget() elif action == 'openSettings': from resources.lib.lib import control control.openSettings(query) elif action == 'moviePlaycount': from resources.lib.libraries import playcount playcount.movies(title, year, imdb, query) elif action == 'episodePlaycount': from resources.lib.libraries import playcount playcount.episodes(imdb, tvdb, season, episode, query) elif action == 'tvPlaycount':
def add(self, tvshowtitle, year, imdb, tvdb, range=False): if not control.condVisibility('Window.IsVisible(infodialog)') and not control.condVisibility('Player.HasVideo')\ and self.silentDialog is False: control.infoDialog("Hinzufügen zur Bibliothek...", time=10000000) self.infoDialog = True from resources.lib.indexers import episodes items = episodes.episodes().get(tvshowtitle, year, imdb, tvdb, idx=False) try: items = [{ 'title': i['title'], 'year': i['year'], 'imdb': i['imdb'], 'tvdb': i['tvdb'], 'season': i['season'], 'episode': i['episode'], 'tvshowtitle': i['tvshowtitle'], 'premiered': i['premiered'] } for i in items] except: items = [] try: if not self.dupe_setting == 'true': raise Exception() if items == []: raise Exception() id = [items[0]['imdb'], items[0]['tvdb']] lib = control.jsonrpc( '{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": {"properties" : ["imdbnumber", "title", "year"]}, "id": 1}' ) lib = unicode(lib, 'utf-8', errors='ignore') lib = json.loads(lib)['result']['tvshows'] lib = [ i['title'].encode('utf-8') for i in lib if str(i['imdbnumber']) in id or ( i['title'].encode('utf-8') == items[0]['tvshowtitle'] and str(i['year']) == items[0]['year']) ][0] lib = control.jsonrpc( '{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": {"filter":{"and": [{"field": "tvshow", "operator": "is", "value": "%s"}]}, "properties": ["season", "episode"]}, "id": 1}' % lib) lib = unicode(lib, 'utf-8', errors='ignore') lib = json.loads(lib)['result']['episodes'] lib = [ 'S%02dE%02d' % (int(i['season']), int(i['episode'])) for i in lib ] items = [ i for i in items if not 'S%02dE%02d' % (int(i['season']), int(i['episode'])) in lib ] except: pass files_added = 0 for i in items: try: if xbmc.abortRequested == True: return sys.exit() if self.check_setting == 'true': if i['episode'] == '1': self.block = True src = lib_tools.check_sources(i['title'], i['year'], i['imdb'], i['tvdb'], i['season'], i['episode'], i['tvshowtitle'], i['premiered']) if src: self.block = False if self.block == True: raise Exception() premiered = i.get('premiered', '0') if self.include_unknown == 'false': if (premiered != '0' and int(re.sub('[^0-9]', '', str(premiered))) > int(self.date)) or premiered == '0': continue self.strmFile(i) files_added += 1 except: pass if range == True: return if self.infoDialog is True: control.infoDialog("Vorgang abgeschlossen", time=1) if self.library_setting == 'true' and not control.condVisibility( 'Library.IsScanningVideo') and files_added > 0: control.execute('UpdateLibrary(video)')
elif action == 'tvshows': from resources.lib.indexers import tvshows tvshows.tvshows().get(url, provider=provider, network=name) elif action == 'seasons': from resources.lib.indexers import episodes episodes.seasons().get(tvshowtitle, year, imdb, tmdb, tvdb, tvrage) elif action == 'episodes': from resources.lib.indexers import episodes episodes.episodes().get(tvshowtitle, year, imdb, tmdb, tvdb, tvrage, season, episode, provider=provider, url=url) elif action == 'sources': from resources.lib.sources import sources sources().addItem(name, title, year, imdb, tmdb, tvdb, tvrage, season, episode, tvshowtitle, alter, date, meta) elif action == 'download': import json from resources.lib.sources import sources from resources.lib.libraries import downloader try:
elif action == 'tvPersons': from resources.lib.indexers import tvshows tvshows.tvshows().persons(url) elif action == 'tvUserlists': from resources.lib.indexers import tvshows tvshows.tvshows().userlists() elif action == 'seasons': from resources.lib.indexers import episodes episodes.seasons().get(tvshowtitle, year, imdb, tvdb) elif action == 'episodes': from resources.lib.indexers import episodes episodes.episodes().get(tvshowtitle, year, imdb, tvdb, season, episode) elif action == 'calendar': from resources.lib.indexers import episodes episodes.episodes().calendar(url) elif action == 'tvWidget': from resources.lib.indexers import episodes episodes.episodes().widget() elif action == 'calendars': from resources.lib.indexers import episodes episodes.episodes().calendars() elif action == 'episodeUserlists': from resources.lib.indexers import episodes
elif action == 'movieSearch': from resources.lib.indexers import movies movies.movies().search(query, lang) elif action == 'tvshows': from resources.lib.indexers import tvshows tvshows.tvshows().get(url, provider=provider, network=name) elif action == 'seasons': from resources.lib.indexers import episodes episodes.seasons().get(tvshowtitle, year, imdb, tmdb, tvdb, tvrage) elif action == 'episodes': from resources.lib.indexers import episodes episodes.episodes().get(tvshowtitle, year, imdb, tmdb, tvdb, tvrage, season, episode, provider=provider, url=url) elif action == 'sources': from resources.lib.sources import sources sources().addItem(name, title, year, imdb, tmdb, tvdb, tvrage, season, episode, tvshowtitle, alter, date, meta) elif action == 'download': import json from resources.lib.sources import sources from resources.lib.libraries import downloader try: downloader.download(name, image, sources().sourcesResolve(json.loads(source)[0])) except: pass elif action == 'play': from resources.lib.sources import sources sources().play(name, title, year, imdb, tmdb, tvdb, tvrage, season, episode, tvshowtitle, alter, date, meta, url)
def update(self, query=None, info="true"): if not query == None: control.idle() try: items = [] season, episode = [], [] show = [os.path.join(self.library_folder, i) for i in control.listDir(self.library_folder)[0]] for s in show: try: season += [os.path.join(s, i) for i in control.listDir(s)[0]] except: pass for s in season: try: episode.append([os.path.join(s, i) for i in control.listDir(s)[1] if i.endswith(".strm")][-1]) except: pass for file in episode: try: file = control.openFile(file) read = file.read() read = read.encode("utf-8") file.close() if not read.startswith(sys.argv[0]): raise Exception() params = dict(urlparse.parse_qsl(read.replace("?", ""))) try: tvshowtitle = params["tvshowtitle"] except: tvshowtitle = None try: tvshowtitle = params["show"] except: pass if tvshowtitle == None or tvshowtitle == "": raise Exception() year, imdb, tvdb = params["year"], params["imdb"], params["tvdb"] imdb = "tt" + re.sub("[^0-9]", "", str(imdb)) try: tmdb = params["tmdb"] except: tmdb = "0" try: tvrage = params["tvrage"] except: tvrage = "0" items.append( { "tvshowtitle": tvshowtitle, "year": year, "imdb": imdb, "tmdb": tmdb, "tvdb": tvdb, "tvrage": tvrage, } ) except: pass items = [i for x, i in enumerate(items) if i not in items[x + 1 :]] if len(items) == 0: raise Exception() except: return try: lib = control.jsonrpc( '{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": {"properties" : ["imdbnumber", "title", "year"]}, "id": 1}' ) lib = unicode(lib, "utf-8", errors="ignore") lib = json.loads(lib)["result"]["tvshows"] except: return if ( info == "true" and not control.condVisibility("Window.IsVisible(infodialog)") and not control.condVisibility("Player.HasVideo") ): control.infoDialog(control.lang(30422).encode("utf-8"), time=10000000) self.infoDialog = True try: control.makeFile(control.dataPath) dbcon = database.connect(control.libcacheFile) dbcur = dbcon.cursor() dbcur.execute("CREATE TABLE IF NOT EXISTS tvshows (" "id TEXT, " "items TEXT, " "UNIQUE(id)" ");") except: return try: from resources.lib.indexers import episodes except: return for item in items: it = None if xbmc.abortRequested == True: return sys.exit() try: dbcur.execute("SELECT * FROM tvshows WHERE id = '%s'" % item["tvdb"]) fetch = dbcur.fetchone() it = eval(fetch[1].encode("utf-8")) except: pass try: if not it == None: raise Exception() it = episodes.episodes().get( item["tvshowtitle"], item["year"], item["imdb"], item["tmdb"], item["tvdb"], item["tvrage"], idx=False, ) status = it[0]["status"].lower() it = [ { "name": i["name"], "title": i["title"], "year": i["year"], "imdb": i["imdb"], "tmdb": i["tmdb"], "tvdb": i["tvdb"], "tvrage": i["tvrage"], "season": i["season"], "episode": i["episode"], "tvshowtitle": i["tvshowtitle"], "alter": i["alter"], "date": i["premiered"], } for i in it ] if status == "continuing": raise Exception() dbcur.execute("INSERT INTO tvshows Values (?, ?)", (item["tvdb"], repr(it))) dbcon.commit() except: pass try: id = [item["imdb"], item["tvdb"]] if not item["tmdb"] == "0": id += [item["tmdb"]] ep = [ x["title"].encode("utf-8") for x in lib if str(x["imdbnumber"]) in id or (x["title"].encode("utf-8") == item["tvshowtitle"] and str(x["year"]) == item["year"]) ][0] ep = control.jsonrpc( '{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": {"filter":{"and": [{"field": "tvshow", "operator": "is", "value": "%s"}]}, "properties": ["season", "episode"]}, "id": 1}' % ep ) ep = unicode(ep, "utf-8", errors="ignore") ep = json.loads(ep)["result"]["episodes"][-1] num = [ x for x, y in enumerate(it) if str(y["season"]) == str(ep["season"]) and str(y["episode"]) == str(ep["episode"]) ][-1] it = [y for x, y in enumerate(it) if x > num] if len(it) == 0: continue except: continue for i in it: try: if xbmc.abortRequested == True: return sys.exit() if int(self.date) <= int(re.sub("[^0-9]", "", str(i["date"]))): from resources.lib.sources import sources src = sources().checkSources( i["name"], i["title"], i["year"], i["imdb"], i["tmdb"], i["tvdb"], i["tvrage"], i["season"], i["episode"], i["tvshowtitle"], i["alter"], i["date"], ) control.log("### SOURCES SRC 10 %s | %s" % (src, i["name"])) if src == False: raise Exception() libtvshows().strmFile(i) except: pass if self.infoDialog == True: control.infoDialog(control.lang(30423).encode("utf-8"), time=1) if self.library_setting == "true" and not control.condVisibility("Library.IsScanningVideo"): control.execute("UpdateLibrary(video)")
def add(self, tvshowtitle, year, imdb, tmdb, tvdb, tvrage, range=False): if not control.condVisibility("Window.IsVisible(infodialog)") and not control.condVisibility("Player.HasVideo"): control.infoDialog(control.lang(30421).encode("utf-8"), time=10000000) self.infoDialog = True from resources.lib.indexers import episodes items = episodes.episodes().get(tvshowtitle, year, imdb, tmdb, tvdb, tvrage, idx=False) try: items = [ { "name": i["name"], "title": i["title"], "year": i["year"], "imdb": i["imdb"], "tmdb": i["tmdb"], "tvdb": i["tvdb"], "tvrage": i["tvrage"], "season": i["season"], "episode": i["episode"], "tvshowtitle": i["tvshowtitle"], "alter": i["alter"], "date": i["premiered"], } for i in items ] except: items = [] try: if not self.dupe_setting == "true": raise Exception() if items == []: raise Exception() id = [items[0]["imdb"], items[0]["tvdb"]] if not items[0]["tmdb"] == "0": id += [items[0]["tmdb"]] lib = control.jsonrpc( '{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": {"properties" : ["imdbnumber", "title", "year"]}, "id": 1}' ) lib = unicode(lib, "utf-8", errors="ignore") lib = json.loads(lib)["result"]["tvshows"] lib = [ i["title"].encode("utf-8") for i in lib if str(i["imdbnumber"]) in id or (i["title"].encode("utf-8") == items[0]["tvshowtitle"] and str(i["year"]) == items[0]["year"]) ][0] lib = control.jsonrpc( '{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": {"filter":{"and": [{"field": "tvshow", "operator": "is", "value": "%s"}]}, "properties": ["season", "episode"]}, "id": 1}' % lib ) lib = unicode(lib, "utf-8", errors="ignore") lib = json.loads(lib)["result"]["episodes"] lib = ["S%02dE%02d" % (int(i["season"]), int(i["episode"])) for i in lib] items = [i for i in items if not "S%02dE%02d" % (int(i["season"]), int(i["episode"])) in lib] except: pass for i in items: try: if xbmc.abortRequested == True: return sys.exit() if self.check_setting == "true": if i["episode"] == "1": self.block = True from resources.lib.sources import sources src = sources().checkSources( i["name"], i["title"], i["year"], i["imdb"], i["tmdb"], i["tvdb"], i["tvrage"], i["season"], i["episode"], i["tvshowtitle"], i["alter"], i["date"], ) if src == True: self.block = False if self.block == True: raise Exception() if int(self.date) <= int(re.sub("[^0-9]", "", str(i["date"]))): from resources.lib.sources import sources src = sources().checkSources( i["name"], i["title"], i["year"], i["imdb"], i["tmdb"], i["tvdb"], i["tvrage"], i["season"], i["episode"], i["tvshowtitle"], i["alter"], i["date"], ) if src == False: raise Exception() self.strmFile(i) except: pass if range == True: return if self.infoDialog == True: control.infoDialog(control.lang(30423).encode("utf-8"), time=1) if self.library_setting == "true" and not control.condVisibility("Library.IsScanningVideo"): control.execute("UpdateLibrary(video)")
def _update(self, notifications=None): try: self._createDirectory(self._location(tools.Media.TypeMovie)) self._createDirectory(self._location(tools.Media.TypeShow)) self._createDirectory(self._location(tools.Media.TypeDocumentary)) self._createDirectory(self._location(tools.Media.TypeShort)) except: pass if notifications == None: notifications = tools.Settings.getInteger( 'library.updates.shows.notifications') notificationDuration = 10000000000 if notifications == 2 else 3000 notifications = notifications > 0 interface.Loader.hide() try: items = [] season, episode = [], [] show = [ tools.File.joinPath(self.mLocation, i) for i in tools.File.listDirectory(self.mLocation)[0] ] for s in show: try: season += [ tools.File.joinPath(s, i) for i in tools.File.listDirectory(s)[0] ] except: pass for s in season: try: episode.append([ tools.File.joinPath(s, i) for i in tools.File.listDirectory(s)[1] if i.endswith('.strm') ][-1]) except: pass for file in episode: try: data = tools.File.readNow(file).encode('utf-8') if not data.startswith(sys.argv[0]): raise Exception() params = dict(urlparse.parse_qsl(data.replace('?', ''))) try: tvshowtitle = params['tvshowtitle'] except: tvshowtitle = None try: tvshowtitle = params['show'] except: pass if tvshowtitle == None or tvshowtitle == '': raise Exception() year, imdb, tvdb = params['year'], params['imdb'], params[ 'tvdb'] imdb = 'tt' + re.sub('[^0-9]', '', str(imdb)) try: tmdb = params['tmdb'] except: tmdb = '0' items.append({ 'tvshowtitle': tvshowtitle, 'year': year, 'imdb': imdb, 'tmdb': tmdb, 'tvdb': tvdb }) except: pass items = [i for x, i in enumerate(items) if i not in items[x + 1:]] if len(items) == 0: raise Exception() except: return try: library = tools.System.executeJson( '{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": {"properties" : ["imdbnumber", "title", "year"]}, "id": 1}' ) library = unicode(library, 'utf-8', errors='ignore') library = tools.Converter.jsonFrom(library)['result']['tvshows'] except: return if notifications and self._ready(): interface.Dialog.notification( title=33244, message=35181, icon=interface.Dialog.IconInformation, time=notificationDuration) self.mDialog = True try: base = database.Database(name=self.DatabaseName) base._create( 'CREATE TABLE IF NOT EXISTS shows (id TEXT, items TEXT, UNIQUE(id));' ) except: return try: from resources.lib.indexers import episodes except: return count = 0 for item in items: if tools.System.aborted(): return sys.exit() it = None try: fetch = base._selectSingle( 'SELECT * FROM shows WHERE id = "%s";' % item['tvdb']) it = tools.Converter.jsonFrom( tools.Converter.base64From(fetch[1].encode('utf-8'))) except: pass try: if not it == None: raise Exception() it = episodes.episodes().get(item['tvshowtitle'], item['year'], item['imdb'], item['tvdb'], idx=False) status = it[0]['status'].lower() it = [{ 'title': i['title'], 'year': i['year'], 'imdb': i['imdb'], 'tvdb': i['tvdb'], 'season': i['season'], 'episode': i['episode'], 'tvshowtitle': i['tvshowtitle'], 'premiered': i['premiered'], 'seasoncount': i['seasoncount'] if 'seasoncount' in i else None } for i in it] if status == 'continuing': raise Exception() json = tools.Converter.base64To(tools.Converter.jsonTo(it)) base._insert('INSERT INTO shows VALUES ("%s", "%s");' % (item['tvdb'], json)) except: pass try: id = [item['imdb'], item['tvdb']] if not item['tmdb'] == '0': id += [item['tmdb']] episode = [ x['title'].encode('utf-8') for x in library if str(x['imdbnumber']) in id or ( x['title'].encode('utf-8') == item['tvshowtitle'] and str(x['year']) == item['year']) ][0] episode = tools.System.executeJson( '{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": {"filter":{"and": [{"field": "tvshow", "operator": "is", "value": "%s"}]}, "properties": ["season", "episode"]}, "id": 1}' % episode) episode = unicode(episode, 'utf-8', errors='ignore') episode = tools.Converter.jsonFrom(episode).get( 'result', {}).get('episodes', {}) episode = [{ 'season': int(i['season']), 'episode': int(i['episode']) } for i in episode] episode = sorted(episode, key=lambda x: (x['season'], x['episode']))[-1] num = [ x for x, y in enumerate(it) if str(y['season']) == str(episode['season']) and str(y['episode']) == str(episode['episode']) ][-1] it = [y for x, y in enumerate(it) if x > num] if len(it) == 0: continue except: continue dateCurrent = int((datetime.datetime.utcnow() - datetime.timedelta(hours=6)).strftime('%Y%m%d')) for i in it: try: if tools.System.aborted(): return sys.exit() try: premiered = i['premiered'] except: premiered = None if not premiered or premiered == '' or premiered == '0': premiered = None #if (premiered and int(re.sub('[^0-9]', '', str(premiered))) > dateCurrent) or (not premiered and not self.mUnaired): # continue self._televisionFiles(i) count += 1 except: tools.Logger.error() if notifications and self.mDialog: interface.Dialog.notification(title=33244, message=35182, icon=interface.Dialog.IconSuccess) if self.mUpdate and not self._libraryBusy() and count > 0: self._libraryUpdate()
def add(self, tvshowtitle, year, imdb, tmdb, range=False): try: if not control.condVisibility('Window.IsVisible(infodialog)') and not control.condVisibility('Player.HasVideo')\ and self.silentDialog is False: control.infoDialog(control.lang(32552), time=10000000) self.infoDialog = True from resources.lib.indexers import episodes seasons = episodes.seasons().get(tvshowtitle, year, imdb, tmdb, meta=None, idx=False) seasons = [i['season'] for i in seasons] for s in seasons: items = episodes.episodes().get(tvshowtitle, year, imdb, tmdb, meta=None, season=s, idx=False) try: items = [{ 'title': i['title'], 'year': i['year'], 'imdb': i['imdb'], 'tvdb': i['tvdb'], 'tmdb': i['tmdb'], 'season': i['season'], 'episode': i['episode'], 'tvshowtitle': i['tvshowtitle'], 'premiered': i['premiered'] } for i in items] except: items = [] try: if not self.dupe_setting == 'true': raise Exception() if items == []: raise Exception() id = [items[0]['imdb'], items[0]['tmdb']] lib = control.jsonrpc( '{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": {"properties" : ["imdbnumber", "title", "year"]}, "id": 1}' ) lib = six.ensure_text(lib, errors='ignore') lib = json.loads(lib)['result']['tvshows'] lib = [ six.ensure_str(i['title']) for i in lib if str(i['imdbnumber']) in id or (six.ensure_str(i['title']) == items[0]['tvshowtitle'] and str(i['year']) == items[0]['year']) ][0] lib = control.jsonrpc( '{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": {"filter":{"and": [{"field": "tvshow", "operator": "is", "value": "%s"}]}, "properties": ["season", "episode"]}, "id": 1}' % lib) lib = six.ensure_text(lib, errors='ignore') lib = json.loads(lib)['result']['episodes'] lib = [ 'S%02dE%02d' % (int(i['season']), int(i['episode'])) for i in lib ] items = [ i for i in items if not 'S%02dE%02d' % (int(i['season']), int(i['episode'])) in lib ] if self.include_special == 'false': items = [ i for i in items if not str(i['season']) == '0' ] except: pass files_added = 0 for i in items: try: if control.monitor.abortRequested(): return sys.exit() # if self.check_setting == 'true': # if i['episode'] == '1': # self.block = True # src = lib_tools.check_sources(i['title'], i['year'], i['imdb'], i['tvdb'], i['season'], i['episode'], i['tvshowtitle'], i['premiered']) # if src: self.block = False # if self.block == True: raise Exception() premiered = i.get('premiered', '0') if (premiered != '0' and int(re.sub('[^0-9]', '', str(premiered))) > int(self.date)) or (premiered == '0' and not self.include_unknown): continue self.strmFile(i) files_added += 1 except: pass if range == True: return if self.infoDialog is True: control.infoDialog(control.lang(32554), time=1) if self.library_setting == 'true' and not control.condVisibility( 'Library.IsScanningVideo') and files_added > 0: control.execute('UpdateLibrary(video)') except: log_utils.log('lib_tv_add', 1)
def _televisionAddSingle(self, title, year, imdb, tvdb, metadata, multiple=False): count = 0 if self._ready() and not multiple: interface.Dialog.notification( title=33244, message=35177, icon=interface.Dialog.IconInformation, time=100000000) self.mDialog = True from resources.lib.indexers import episodes items = episodes.episodes().get(title, year, imdb, tvdb, idx=False) try: items = [{ 'title': i['title'], 'year': i['year'], 'imdb': i['imdb'], 'tvdb': i['tvdb'], 'season': i['season'], 'episode': i['episode'], 'tvshowtitle': i['tvshowtitle'], 'premiered': i['premiered'], 'seasoncount': i['seasoncount'] if 'seasoncount' in i else None } for i in items] except: items = [] try: if self.mDuplicates and len(items) > 0: id = [items[0]['imdb'], items[0]['tvdb']] library = tools.System.executeJson( '{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": {"properties" : ["imdbnumber", "title", "year"]}, "id": 1}' ) library = unicode(library, 'utf-8', errors='ignore') library = tools.Converter.jsonFrom( library)['result']['tvshows'] library = [ i['title'].encode('utf-8') for i in library if str(i['imdbnumber']) in id or ( i['title'].encode('utf-8') == items[0]['tvshowtitle'] and str(i['year']) == items[0]['year']) ][0] library = tools.System.executeJson( '{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": {"filter":{"and": [{"field": "tvshow", "operator": "is", "value": "%s"}]}, "properties": ["season", "episode"]}, "id": 1}' % library) library = unicode(library, 'utf-8', errors='ignore') library = tools.Converter.jsonFrom( library)['result']['episodes'] library = [ 'S%02dE%02d' % (int(i['season']), int(i['episode'])) for i in library ] items = [ i for i in items if not 'S%02dE%02d' % (int(i['season']), int(i['episode'])) in library ] except: pass dateCurrent = int((datetime.datetime.utcnow() - datetime.timedelta(hours=6)).strftime('%Y%m%d')) for i in items: try: if tools.System.aborted(): return sys.exit() if self.mPrecheck: if i['episode'] == '1': self.mBlock = True streams = self._checkSources(i['title'], i['year'], i['imdb'], i['tvdb'], i['season'], i['episode'], i['tvshowtitle'], i['premiered']) if streams: self.mBlock = False if self.mBlock: raise Exception() try: premiered = i['premiered'] except: premiered = None if not premiered or premiered == '' or premiered == '0': premiered = None if (premiered and int(re.sub('[^0-9]', '', str(premiered))) > dateCurrent) or (not premiered and not self.mUnaired): continue self._televisionFiles(item=i, metadata=metadata) count += 1 except: tools.Logger.error() return count
def getSeasonIndicators2(tvshowtitle, imdb, tvdb, season): try: import sys, xbmc from resources.lib.modules import control if not trakt.getTraktIndicatorsInfo() == False: raise Exception() total = '6' from metahandler import metahandlers from resources.lib.indexers import episodes if not int('%01d' % int(season)) > 0: raise Exception() metaget = metahandlers.MetaData(preparezip=False) name = control.addonInfo('name') imdb = imdb.encode('utf-8') tvdb = tvdb.encode('utf-8') season = season.encode('utf-8') # metaget.get_meta('tvshow', '', imdb_id=imdb) items = episodes.episodes().get(tvshowtitle, '0', imdb, tvdb, '0', idx=False) try: items = [ i for i in items if int('%01d' % int(season)) == int('%01d' % int(i['season'])) ] except: pass season_playcount = [] for i in range(len(items)): season, episode = items[i]['season'], items[i]['episode'] playcount = metaget._get_watched_episode({ 'imdb_id': imdb, 'season': season, 'episode': episode, 'premiered': '' }) playcount = str(playcount) if playcount == '7': play = '1' else: play = '0' season_playcount.append(playcount) season_file = control.seasons_meta try: from sqlite3 import dbapi2 as database except: from pysqlite2 import dbapi2 as database try: control.makeFile(control.dataPath) dbcon = database.connect(season_file) dbcur = dbcon.cursor() dbcur.execute("CREATE TABLE IF NOT EXISTS season_meta (" "imdb TEXT, " "tvdb TEXT, " "season TEXT, " "playcount TEXT, " "UNIQUE(imdb, tvdb, season, playcount)" ");") dbcon.commit() except: pass if "6" in season_playcount: total = '6' dbcon = database.connect(season_file) dbcur = dbcon.cursor() dbcur.execute( "DELETE FROM season_meta WHERE imdb = '%s' AND season = '%s'" % (imdb, season)) dbcur.execute("INSERT INTO season_meta Values (?, ?, ?, ?)", (imdb, tvdb, season, total)) dbcon.commit() elif int(len(season_playcount)) > 0: if not "6" in season_playcount: total = '7' dbcon = database.connect(season_file) dbcur = dbcon.cursor() dbcur.execute( "DELETE FROM season_meta WHERE imdb = '%s' AND season = '%s'" % (imdb, season)) dbcur.execute("INSERT INTO season_meta Values (?, ?, ?, ?)", (imdb, tvdb, season, total)) dbcon.commit() # metaget.change_watched('season', name='', imdb_id=imdb, season=season, watched=int(total)) return total except: return total
def marktvshows(tvshowtitle, imdb, tvdb, watched): try: import sys, xbmc if not trakt.getTraktIndicatorsInfo() == False: raise Exception() watched = int(watched) from metahandler import metahandlers from resources.lib.indexers import episodes imdb = imdb.encode('utf-8') metaget = metahandlers.MetaData(preparezip=False) name = control.addonInfo('name') dialog = control.progressDialogBG dialog.create(str(name), str(tvshowtitle)) dialog.update(0, str(name), str(tvshowtitle)) items = episodes.episodes().get(tvshowtitle, '0', imdb, tvdb, '0', idx=False) try: items = [i for i in items] except: pass items = [{ 'label': '%s S%02dE%02d' % (tvshowtitle, int(i['season']), int(i['episode'])), 'season': int('%01d' % int(i['season'])), 'episode': int('%01d' % int(i['episode'])) } for i in items] season_file = control.seasons_meta try: from sqlite3 import dbapi2 as database except: from pysqlite2 import dbapi2 as database try: if watched == 6: total = '6' dbcon = database.connect(season_file) dbcur = dbcon.cursor() dbcur.execute("DELETE FROM season_meta WHERE imdb = '%s'" % (imdb)) dbcon.commit() except: pass for i in range(len(items)): if xbmc.abortRequested == True: return sys.exit() dialog.update(int((100 / float(len(items))) * i), str(name), str(items[i]['label'])) season, episode = items[i]['season'], items[i]['episode'] metaget.get_episode_meta('', imdb, season, episode) metaget.change_watched('episode', '', imdb, season=season, episode=episode, year='', watched=watched) try: if watched == 7: total = '7' dbcon = database.connect(season_file) dbcur = dbcon.cursor() dbcur.execute( "DELETE FROM season_meta WHERE imdb = '%s' AND season = '%s'" % (imdb, season)) dbcur.execute( "INSERT INTO season_meta Values (?, ?, ?, ?)", (imdb, tvdb, season, total)) dbcon.commit() except: pass try: dialog.close() except: pass except: try: dialog.close() except: pass try: import sys, xbmc watched = int(watched) imdb = imdb.encode('utf-8') from metahandler import metahandlers from resources.lib.indexers import episodes metaget = metahandlers.MetaData(preparezip=False) metaget.get_meta('tvshow', name='', imdb_id=imdb) metaget._update_watched(imdb, 'tvshow', watched) metaget.change_watched('tvshow', '', imdb, watched=watched) except: pass control.refresh()
def getSeasonIndicators2(tvshowtitle, imdb, tvdb, season): try: import sys,xbmc from resources.lib.modules import control if not trakt.getTraktIndicatorsInfo() == False: raise Exception() total = '6' from metahandler import metahandlers from resources.lib.indexers import episodes if not int('%01d' % int(season)) > 0: raise Exception() metaget = metahandlers.MetaData(preparezip=False) name = control.addonInfo('name') imdb = imdb.encode('utf-8') tvdb = tvdb.encode('utf-8') season = season.encode('utf-8') # metaget.get_meta('tvshow', '', imdb_id=imdb) items = episodes.episodes().get(tvshowtitle, '0', imdb, tvdb, '0', idx=False) try: items = [i for i in items if int('%01d' % int(season)) == int('%01d' % int(i['season']))] except: pass season_playcount = [] for i in range(len(items)): season, episode = items[i]['season'], items[i]['episode'] playcount = metaget._get_watched_episode({'imdb_id' : imdb, 'season' : season, 'episode': episode, 'premiered' : ''}) playcount = str(playcount) if playcount == '7': play = '1' else: play = '0' season_playcount.append(playcount) season_file = control.seasons_meta try: from sqlite3 import dbapi2 as database except: from pysqlite2 import dbapi2 as database try: control.makeFile(control.dataPath) dbcon = database.connect(season_file) dbcur = dbcon.cursor() dbcur.execute("CREATE TABLE IF NOT EXISTS season_meta (""imdb TEXT, ""tvdb TEXT, ""season TEXT, ""playcount TEXT, ""UNIQUE(imdb, tvdb, season, playcount)"");") dbcon.commit() except: pass if "6" in season_playcount: total = '6' dbcon = database.connect(season_file) dbcur = dbcon.cursor() dbcur.execute("DELETE FROM season_meta WHERE imdb = '%s' AND season = '%s'" % (imdb, season)) dbcur.execute("INSERT INTO season_meta Values (?, ?, ?, ?)", (imdb, tvdb, season, total)) dbcon.commit() elif int(len(season_playcount)) > 0: if not "6" in season_playcount: total = '7' dbcon = database.connect(season_file) dbcur = dbcon.cursor() dbcur.execute("DELETE FROM season_meta WHERE imdb = '%s' AND season = '%s'" % (imdb, season)) dbcur.execute("INSERT INTO season_meta Values (?, ?, ?, ?)", (imdb, tvdb, season, total)) dbcon.commit() # metaget.change_watched('season', name='', imdb_id=imdb, season=season, watched=int(total)) return total except: return total
elif action == 'tvPersons': from resources.lib.indexers import tvshows tvshows.tvshows(type = type, kids = kids).persons(url) elif action == 'tvUserlists': from resources.lib.indexers import tvshows tvshows.tvshows(type = type, kids = kids).userlists(mode = params.get('mode')) elif action == 'seasons': from resources.lib.indexers import seasons seasons.seasons(type = type, kids = kids).get(tvshowtitle, year, imdb, tvdb) elif action == 'episodes': from resources.lib.indexers import episodes episodes.episodes(type = type, kids = kids).get(tvshowtitle, year, imdb, tvdb, season, episode) elif action == 'calendar': from resources.lib.indexers import episodes episodes.episodes(type = type, kids = kids).calendar(url) elif action == 'tvHome': from resources.lib.indexers import episodes episodes.episodes(type = type, kids = kids).home() elif action == 'tvArrivals': from resources.lib.indexers import episodes episodes.episodes(type = type, kids = kids).arrivals() elif action == 'tvCalendars': from resources.lib.indexers import episodes
def tvshows(tvshowtitle, imdb, tvdb, season, watched): try: import sys, xbmc if not trakt.getTraktIndicatorsInfo() == False: raise Exception() from metahandler import metahandlers from resources.lib.indexers import episodes metaget = metahandlers.MetaData(preparezip=False) name = control.addonInfo("name") dialog = control.progressDialogBG dialog.create(str(name), str(tvshowtitle)) dialog.update(0, str(name), str(tvshowtitle)) metaget.get_meta("tvshow", name="", imdb_id=imdb) items = episodes.episodes().get(tvshowtitle, "0", imdb, tvdb, "0", idx=False) try: items = [i for i in items if int("%01d" % int(season)) == int("%01d" % int(i["season"]))] except: pass items = [ { "label": "%s S%02dE%02d" % (tvshowtitle, int(i["season"]), int(i["episode"])), "season": int("%01d" % int(i["season"])), "episode": int("%01d" % int(i["episode"])), } for i in items ] for i in range(len(items)): if xbmc.abortRequested == True: return sys.exit() dialog.update(int((100 / float(len(items))) * i), str(name), str(items[i]["label"])) season, episode = items[i]["season"], items[i]["episode"] metaget.get_episode_meta("", imdb_id=imdb, season=season, episode=episode) metaget.change_watched("episode", "", imdb_id=imdb, season=season, episode=episode, watched=int(watched)) try: dialog.close() except: pass except: try: dialog.close() except: pass try: if trakt.getTraktIndicatorsInfo() == False: raise Exception() if int(watched) == 7: trakt.markTVShowAsWatched(tvdb) else: trakt.markTVShowAsNotWatched(tvdb) trakt.cachesyncTVShows() except: pass control.refresh()
def tvshows(tvshowtitle, imdb, tvdb, season, watched): watched = int(watched) try: from metahandler import metahandlers from resources.lib.indexers import episodes if not trakt.getTraktIndicatorsInfo() == False: raise Exception() name = control.addonInfo('name') dialog = control.progressDialogBG() dialog.create(str(name), str(tvshowtitle)) dialog.update(0, str(name), str(tvshowtitle)) metaget = metahandlers.MetaData(preparezip=False) metaget.get_meta('tvshow', name='', imdb_id=imdb) items = episodes.episodes().get(tvshowtitle, '0', imdb, tvdb, idx=False) for i in range(len(items)): items[i]['season'] = int(items[i]['season']) items[i]['episode'] = int(items[i]['episode']) try: items = [ i for i in items if int('%01d' % int(season)) == int('%01d' % i['season']) ] except: pass items = [{ 'label': '%s S%02dE%02d' % (tvshowtitle, i['season'], i['episode']), 'season': int('%01d' % i['season']), 'episode': int('%01d' % i['episode']) } for i in items] count = len(items) for i in range(count): if xbmc.abortRequested == True: return sys.exit() dialog.update(int(100.0 / count * i), str(name), str(items[i]['label'])) season, episode = items[i]['season'], items[i]['episode'] metaget.get_episode_meta('', imdb_id=imdb, season=season, episode=episode) metaget.change_watched('episode', '', imdb_id=imdb, season=season, episode=episode, watched=watched) tvshowsUpdate(imdb=imdb, tvdb=tvdb) try: dialog.close() except: pass except: try: dialog.close() except: pass try: if trakt.getTraktIndicatorsInfo() == False: raise Exception() if watched == 7: trakt.watch(imdb=imdb, tvdb=tvdb, season=season, refresh=True, notification=False) else: trakt.unwatch(imdb=imdb, tvdb=tvdb, season=season, refresh=True, notification=False) except: tools.Logger.error() pass
def marktvshows(tvshowtitle, imdb, tvdb, watched): try: import sys,xbmc if not trakt.getTraktIndicatorsInfo() == False: raise Exception() watched=int(watched) from metahandler import metahandlers from resources.lib.indexers import episodes imdb = imdb.encode('utf-8') metaget = metahandlers.MetaData(preparezip=False) name = control.addonInfo('name') dialog = control.progressDialogBG dialog.create(str(name), str(tvshowtitle)) dialog.update(0, str(name), str(tvshowtitle)) items = episodes.episodes().get(tvshowtitle, '0', imdb, tvdb, '0', idx=False) try: items = [i for i in items] except: pass items = [{'label': '%s S%02dE%02d' % (tvshowtitle, int(i['season']), int(i['episode'])), 'season': int('%01d' % int(i['season'])), 'episode': int('%01d' % int(i['episode']))} for i in items] season_file = control.seasons_meta try: from sqlite3 import dbapi2 as database except: from pysqlite2 import dbapi2 as database try: if watched == 6: total = '6' dbcon = database.connect(season_file) dbcur = dbcon.cursor() dbcur.execute("DELETE FROM season_meta WHERE imdb = '%s'" % (imdb)) dbcon.commit() except: pass for i in range(len(items)): if xbmc.abortRequested == True: return sys.exit() dialog.update(int((100 / float(len(items))) * i), str(name), str(items[i]['label'])) season, episode = items[i]['season'], items[i]['episode'] metaget.get_episode_meta('', imdb, season, episode) metaget.change_watched('episode', '', imdb, season=season, episode=episode, year='', watched=watched) try: if watched == 7: total = '7' dbcon = database.connect(season_file) dbcur = dbcon.cursor() dbcur.execute("DELETE FROM season_meta WHERE imdb = '%s' AND season = '%s'" % (imdb, season)) dbcur.execute("INSERT INTO season_meta Values (?, ?, ?, ?)", (imdb, tvdb, season, total)) dbcon.commit() except: pass try: dialog.close() except: pass except: try: dialog.close() except: pass try: import sys,xbmc watched=int(watched) imdb = imdb.encode('utf-8') from metahandler import metahandlers from resources.lib.indexers import episodes metaget = metahandlers.MetaData(preparezip=False) metaget.get_meta('tvshow', name='', imdb_id=imdb) metaget._update_watched(imdb, 'tvshow', watched) metaget.change_watched('tvshow', '', imdb, watched=watched) except: pass control.refresh()
def update(self, query, info='true'): if query == 'tool': return xbmc.executebuiltin('RunPlugin(%s?action=updateLibrary)' % sys.argv[0]) try: items = [] season, episode = [], [] show = [os.path.join(self.library_folder, i) for i in control.listDir(self.library_folder)[0]] for s in show: try: season += [os.path.join(s, i) for i in control.listDir(s)[0]] except: pass for s in season: try: episode.append([os.path.join(s, i) for i in control.listDir(s)[1] if i.endswith('.strm')][-1]) except: pass for file in episode: try: file = control.openFile(file) read = file.read() read = read.encode('utf-8') file.close() if not read.startswith(sys.argv[0]): raise Exception() params = dict(urlparse.parse_qsl(read.replace('?',''))) try: tvshowtitle = params['tvshowtitle'] except: tvshowtitle = None try: tvshowtitle = params['show'] except: pass if tvshowtitle == None or tvshowtitle == '': raise Exception() year, imdb, tvdb = params['year'], params['imdb'], params['tvdb'] imdb = 'tt' + re.sub('[^0-9]', '', str(imdb)) try: tmdb = params['tmdb'] except: tmdb = '0' try: tvrage = params['tvrage'] except: tvrage = '0' items.append({'tvshowtitle': tvshowtitle, 'year': year, 'imdb': imdb, 'tmdb': tmdb, 'tvdb': tvdb, 'tvrage': tvrage}) except: pass items = [i for x, i in enumerate(items) if i not in items[x + 1:]] if len(items) == 0: raise Exception() except: return try: lib = control.jsonrpc('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": {"properties" : ["imdbnumber", "title", "year"]}, "id": 1}') lib = unicode(lib, 'utf-8', errors='ignore') lib = json.loads(lib)['result']['tvshows'] except: return if info == 'true' and not control.condVisibility('Window.IsVisible(infodialog)') and not control.condVisibility('Player.HasVideo'): control.infoDialog(control.lang(30422).encode('utf-8'), time=10000000) self.infoDialog = True try: control.makeFile(control.dataPath) dbcon = database.connect(control.libcacheFile) dbcur = dbcon.cursor() dbcur.execute("CREATE TABLE IF NOT EXISTS tvshows (""id TEXT, ""items TEXT, ""UNIQUE(id)"");") except: return try: from resources.lib.indexers import episodes except: return for item in items: it = None if xbmc.abortRequested == True: return sys.exit() try: dbcur.execute("SELECT * FROM tvshows WHERE id = '%s'" % item['tvdb']) fetch = dbcur.fetchone() it = eval(fetch[1].encode('utf-8')) except: pass try: if not it == None: raise Exception() it = episodes.episodes().get(item['tvshowtitle'], item['year'], item['imdb'], item['tmdb'], item['tvdb'], item['tvrage'], idx=False) status = it[0]['status'].lower() it = [{'name': i['name'], 'title': i['title'], 'year': i['year'], 'imdb': i['imdb'], 'tmdb': i['tmdb'], 'tvdb': i['tvdb'], 'tvrage': i['tvrage'], 'season': i['season'], 'episode': i['episode'], 'tvshowtitle': i['tvshowtitle'], 'alter': i['alter'], 'date': i['premiered']} for i in it] if status == 'continuing': raise Exception() dbcur.execute("INSERT INTO tvshows Values (?, ?)", (item['tvdb'], repr(it))) dbcon.commit() except: pass try: id = [item['imdb'], item['tvdb']] if not item['tmdb'] == '0': id += [item['tmdb']] ep = [x['title'].encode('utf-8') for x in lib if str(x['imdbnumber']) in id or (x['title'].encode('utf-8') == item['tvshowtitle'] and str(x['year']) == item['year'])][0] ep = control.jsonrpc('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": {"filter":{"and": [{"field": "tvshow", "operator": "is", "value": "%s"}]}, "properties": ["season", "episode"]}, "id": 1}' % ep) ep = unicode(ep, 'utf-8', errors='ignore') ep = json.loads(ep)['result']['episodes'][-1] num = [x for x,y in enumerate(it) if str(y['season']) == str(ep['season']) and str(y['episode']) == str(ep['episode'])][-1] it = [y for x,y in enumerate(it) if x > num] if len(it) == 0: continue except: continue for i in it: try: if xbmc.abortRequested == True: return sys.exit() if int(self.date) <= int(re.sub('[^0-9]', '', str(i['date']))): from resources.lib.sources import sources src = sources().getSources(i['name'], i['title'], i['year'], i['imdb'], i['tmdb'], i['tvdb'], i['tvrage'], i['season'], i['episode'], i['tvshowtitle'], i['alter'], i['date']) if not len(src) > 2: raise Exception() libtvshows().strmFile(i) except: pass if self.infoDialog == True: control.infoDialog(control.lang(30423).encode('utf-8'), time=1) if self.library_setting == 'true' and not control.condVisibility('Library.IsScanningVideo'): control.execute('UpdateLibrary(video)')
def update(self, query=None, info='true'): if not query == None: control.idle() try: items = [] season, episode = [], [] show = [os.path.join(self.library_folder, i) for i in control.listDir(self.library_folder)[0]] for s in show: try: season += [os.path.join(s, i) for i in control.listDir(s)[0]] except: pass for s in season: try: episode.append([os.path.join(s, i) for i in control.listDir(s)[1] if i.endswith('.strm')][-1]) except: pass for file in episode: try: file = control.openFile(file) read = file.read() read = read.encode('utf-8') file.close() if not read.startswith(sys.argv[0]): raise Exception() params = dict(urlparse.parse_qsl(read.replace('?',''))) try: tvshowtitle = params['tvshowtitle'] except: tvshowtitle = None try: tvshowtitle = params['show'] except: pass if tvshowtitle == None or tvshowtitle == '': raise Exception() year, imdb, tvdb = params['year'], params['imdb'], params['tvdb'] imdb = 'tt' + re.sub('[^0-9]', '', str(imdb)) try: tmdb = params['tmdb'] except: tmdb = '0' items.append({'tvshowtitle': tvshowtitle, 'year': year, 'imdb': imdb, 'tmdb': tmdb, 'tvdb': tvdb}) except: pass items = [i for x, i in enumerate(items) if i not in items[x + 1:]] if len(items) == 0: raise Exception() except: return try: lib = control.jsonrpc('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": {"properties" : ["imdbnumber", "title", "year"]}, "id": 1}') lib = unicode(lib, 'utf-8', errors='ignore') lib = json.loads(lib)['result']['tvshows'] except: return if info == 'true' and not control.condVisibility('Window.IsVisible(infodialog)') and not control.condVisibility('Player.HasVideo'): control.infoDialog(control.lang(32553).encode('utf-8'), time=10000000) self.infoDialog = True try: control.makeFile(control.dataPath) dbcon = database.connect(control.libcacheFile) dbcur = dbcon.cursor() dbcur.execute("CREATE TABLE IF NOT EXISTS tvshows (""id TEXT, ""items TEXT, ""UNIQUE(id)"");") except: return try: from resources.lib.indexers import episodes except: return files_added = 0 # __init__ doesn't get called from services so self.date never gets updated and new episodes are not added to the library self.datetime = (datetime.datetime.utcnow() - datetime.timedelta(hours = 5)) self.date = (self.datetime - datetime.timedelta(hours = 24)).strftime('%Y%m%d') for item in items: it = None if xbmc.abortRequested == True: return sys.exit() try: dbcur.execute("SELECT * FROM tvshows WHERE id = '%s'" % item['tvdb']) fetch = dbcur.fetchone() it = eval(fetch[1].encode('utf-8')) except: pass try: if not it == None: raise Exception() it = episodes.episodes().get(item['tvshowtitle'], item['year'], item['imdb'], item['tvdb'], idx=False) status = it[0]['status'].lower() it = [{'title': i['title'], 'year': i['year'], 'imdb': i['imdb'], 'tvdb': i['tvdb'], 'season': i['season'], 'episode': i['episode'], 'tvshowtitle': i['tvshowtitle'], 'premiered': i['premiered']} for i in it] if status == 'continuing': raise Exception() dbcur.execute("INSERT INTO tvshows Values (?, ?)", (item['tvdb'], repr(it))) dbcon.commit() except: pass try: id = [item['imdb'], item['tvdb']] if not item['tmdb'] == '0': id += [item['tmdb']] ep = [x['title'].encode('utf-8') for x in lib if str(x['imdbnumber']) in id or (x['title'].encode('utf-8') == item['tvshowtitle'] and str(x['year']) == item['year'])][0] ep = control.jsonrpc('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": {"filter":{"and": [{"field": "tvshow", "operator": "is", "value": "%s"}]}, "properties": ["season", "episode"]}, "id": 1}' % ep) ep = unicode(ep, 'utf-8', errors='ignore') ep = json.loads(ep).get('result', {}).get('episodes', {}) ep = [{'season': int(i['season']), 'episode': int(i['episode'])} for i in ep] ep = sorted(ep, key=lambda x: (x['season'], x['episode']))[-1] num = [x for x,y in enumerate(it) if str(y['season']) == str(ep['season']) and str(y['episode']) == str(ep['episode'])][-1] it = [y for x,y in enumerate(it) if x > num] if len(it) == 0: continue except: continue for i in it: try: if xbmc.abortRequested == True: return sys.exit() premiered = i.get('premiered', '0') if (premiered != '0' and int(re.sub('[^0-9]', '', str(premiered))) > int(self.date)) or (premiered == '0' and not self.include_unknown): continue libtvshows().strmFile(i) files_added += 1 except: pass if self.infoDialog == True: control.infoDialog(control.lang(32554).encode('utf-8'), time=1) if self.library_setting == 'true' and not control.condVisibility('Library.IsScanningVideo') and files_added > 0: control.execute('UpdateLibrary(video)')
elif action == 'tvCertificates': from resources.lib.indexers import tvshows tvshows.tvshows().certifications() elif action == 'tvUserlists': from resources.lib.indexers import tvshows tvshows.tvshows().userlists() elif action == 'seasons': from resources.lib.indexers import episodes episodes.seasons().get(tvshowtitle, year, imdb, tvdb) elif action == 'episodes': from resources.lib.indexers import episodes episodes.episodes().get(tvshowtitle, year, imdb, tvdb, season, episode) elif action == 'calendar': from resources.lib.indexers import episodes episodes.episodes().calendar(url) elif action == 'tvWidget': from resources.lib.indexers import episodes episodes.episodes().widget() elif action == 'calendars': from resources.lib.indexers import episodes episodes.episodes().calendars() elif action == 'episodeUserlists': from resources.lib.indexers import episodes
def update(self, query=None, info='true'): if not query == None: control.idle() try: items = [] season, episode = [], [] show = [ os.path.join(self.library_folder, i) for i in control.listDir(self.library_folder)[0] ] for s in show: try: season += [ os.path.join(s, i) for i in control.listDir(s)[0] ] except: pass for s in season: try: episode.append([ os.path.join(s, i) for i in control.listDir(s)[1] if i.endswith('.strm') ][-1]) except: pass for file in episode: try: file = control.openFile(file) read = file.read() read = read.encode('utf-8') file.close() if not read.startswith(sys.argv[0]): raise Exception() params = dict(urlparse.parse_qsl(read.replace('?', ''))) try: tvshowtitle = params['tvshowtitle'] except: tvshowtitle = None try: tvshowtitle = params['show'] except: pass if tvshowtitle == None or tvshowtitle == '': raise Exception() year, imdb, tvdb = params['year'], params['imdb'], params[ 'tvdb'] imdb = 'tt' + re.sub('[^0-9]', '', str(imdb)) try: tmdb = params['tmdb'] except: tmdb = '0' items.append({ 'tvshowtitle': tvshowtitle, 'year': year, 'imdb': imdb, 'tmdb': tmdb, 'tvdb': tvdb }) except: pass items = [i for x, i in enumerate(items) if i not in items[x + 1:]] if len(items) == 0: raise Exception() except: return try: lib = control.jsonrpc( '{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": {"properties" : ["imdbnumber", "title", "year"]}, "id": 1}' ) lib = unicode(lib, 'utf-8', errors='ignore') lib = json.loads(lib)['result']['tvshows'] except: return if info == 'true' and not control.condVisibility( 'Window.IsVisible(infodialog)') and not control.condVisibility( 'Player.HasVideo'): control.infoDialog(control.lang(32553).encode('utf-8'), time=10000000) self.infoDialog = True try: control.makeFile(control.dataPath) dbcon = database.connect(control.libcacheFile) dbcur = dbcon.cursor() dbcur.execute("CREATE TABLE IF NOT EXISTS tvshows (" "id TEXT, " "items TEXT, " "UNIQUE(id)" ");") except: return try: from resources.lib.indexers import episodes except: return files_added = 0 # __init__ doesn't get called from services so self.date never gets updated and new episodes are not added to the library self.datetime = (datetime.datetime.utcnow() - datetime.timedelta(hours=5)) self.date = (self.datetime - datetime.timedelta(hours=24)).strftime('%Y%m%d') for item in items: it = None if xbmc.abortRequested == True: return sys.exit() try: dbcur.execute("SELECT * FROM tvshows WHERE id = '%s'" % item['tvdb']) fetch = dbcur.fetchone() it = eval(fetch[1].encode('utf-8')) except: pass try: if not it == None: raise Exception() it = episodes.episodes().get(item['tvshowtitle'], item['year'], item['imdb'], item['tvdb'], idx=False) status = it[0]['status'].lower() it = [{ 'title': i['title'], 'year': i['year'], 'imdb': i['imdb'], 'tvdb': i['tvdb'], 'season': i['season'], 'episode': i['episode'], 'tvshowtitle': i['tvshowtitle'], 'premiered': i['premiered'] } for i in it] if status == 'continuing': raise Exception() dbcur.execute("INSERT INTO tvshows Values (?, ?)", (item['tvdb'], repr(it))) dbcon.commit() except: pass try: id = [item['imdb'], item['tvdb']] if not item['tmdb'] == '0': id += [item['tmdb']] ep = [ x['title'].encode('utf-8') for x in lib if str(x['imdbnumber']) in id or ( x['title'].encode('utf-8') == item['tvshowtitle'] and str(x['year']) == item['year']) ][0] ep = control.jsonrpc( '{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": {"filter":{"and": [{"field": "tvshow", "operator": "is", "value": "%s"}]}, "properties": ["season", "episode"]}, "id": 1}' % ep) ep = unicode(ep, 'utf-8', errors='ignore') ep = json.loads(ep).get('result', {}).get('episodes', {}) ep = [{ 'season': int(i['season']), 'episode': int(i['episode']) } for i in ep] ep = sorted(ep, key=lambda x: (x['season'], x['episode']))[-1] num = [ x for x, y in enumerate(it) if str(y['season']) == str(ep['season']) and str(y['episode']) == str(ep['episode']) ][-1] it = [y for x, y in enumerate(it) if x > num] if len(it) == 0: continue except: continue for i in it: try: if xbmc.abortRequested == True: return sys.exit() premiered = i.get('premiered', '0') if (premiered != '0' and int(re.sub('[^0-9]', '', str(premiered))) > int(self.date)) or (premiered == '0' and not self.include_unknown): continue libtvshows().strmFile(i) files_added += 1 except: pass if self.infoDialog == True: control.infoDialog(control.lang(32554).encode('utf-8'), time=1) if self.library_setting == 'true' and not control.condVisibility( 'Library.IsScanningVideo') and files_added > 0: control.execute('UpdateLibrary(video)')
def routing(_argv): params = dict(urllib_parse.parse_qsl(_argv.replace('?', ''))) action = params.get('action') name = params.get('name') title = params.get('title') year = params.get('year') imdb = params.get('imdb') tvdb = params.get('tvdb') tmdb = params.get('tmdb') season = params.get('season') episode = params.get('episode') tvshowtitle = params.get('tvshowtitle') premiered = params.get('premiered') url = params.get('url') image = params.get('image') meta = params.get('meta') select = params.get('select') query = params.get('query') source = params.get('source') content = params.get('content') status = params.get('status') rtype = params.get('rtype') windowedtrailer = params.get('windowedtrailer') windowedtrailer = int(windowedtrailer) if windowedtrailer in ('0', '1') else 0 if action == None: from resources.lib.indexers import navigator from resources.lib.modules import cache cache.cache_version_check() navigator.navigator().root() elif action == 'furkNavigator': from resources.lib.indexers import navigator navigator.navigator().furk() elif action == 'furkMetaSearch': from resources.lib.indexers import furk furk.furk().furk_meta_search(url) elif action == 'furkSearch': from resources.lib.indexers import furk furk.furk().search() elif action == 'furkUserFiles': from resources.lib.indexers import furk furk.furk().user_files() elif action == 'furkSearchNew': from resources.lib.indexers import furk furk.furk().search_new() elif action == 'movieNavigator': from resources.lib.indexers import navigator navigator.navigator().movies() elif action == 'movieliteNavigator': from resources.lib.indexers import navigator navigator.navigator().movies(lite=True) elif action == 'mymovieNavigator': from resources.lib.indexers import navigator navigator.navigator().mymovies() elif action == 'mymovieliteNavigator': from resources.lib.indexers import navigator navigator.navigator().mymovies(lite=True) elif action == 'tvNavigator': from resources.lib.indexers import navigator navigator.navigator().tvshows() elif action == 'tvliteNavigator': from resources.lib.indexers import navigator navigator.navigator().tvshows(lite=True) elif action == 'mytvNavigator': from resources.lib.indexers import navigator navigator.navigator().mytvshows() elif action == 'mytvliteNavigator': from resources.lib.indexers import navigator navigator.navigator().mytvshows(lite=True) elif action == 'downloadNavigator': from resources.lib.indexers import navigator navigator.navigator().downloads() elif action == 'libraryNavigator': from resources.lib.indexers import navigator navigator.navigator().library() elif action == 'toolNavigator': from resources.lib.indexers import navigator navigator.navigator().tools() elif action == 'searchNavigator': from resources.lib.indexers import navigator navigator.navigator().search() elif action == 'viewsNavigator': from resources.lib.indexers import navigator navigator.navigator().views() elif action == 'cacheNavigator': from resources.lib.indexers import navigator navigator.navigator().cache_functions() elif action == 'logNavigator': from resources.lib.indexers import navigator navigator.navigator().log_functions() elif action == 'clearCache': from resources.lib.indexers import navigator navigator.navigator().clearCache() elif action == 'clearCacheProviders': from resources.lib.indexers import navigator navigator.navigator().clearCacheProviders() elif action == 'clearDebridCheck': from resources.lib.indexers import navigator navigator.navigator().clearDebridCheck() elif action == 'clearCacheSearch': from resources.lib.indexers import navigator navigator.navigator().clearCacheSearch(select) elif action == 'clearAllCache': from resources.lib.indexers import navigator navigator.navigator().clearCacheAll() elif action == 'infoCheck': from resources.lib.indexers import navigator navigator.navigator().infoCheck('') elif action == 'uploadLog': from resources.lib.indexers import navigator navigator.navigator().uploadLog() elif action == 'emptyLog': from resources.lib.indexers import navigator navigator.navigator().emptyLog() elif action == 'viewLog': from resources.lib.modules import log_utils log_utils.view_log() elif action == 'movies': from resources.lib.indexers import movies movies.movies().get(url) elif action == 'moviePage': from resources.lib.indexers import movies movies.movies().get(url) elif action == 'movieWidget': from resources.lib.indexers import movies movies.movies().widget() elif action == 'movieSearch': from resources.lib.indexers import movies movies.movies().search() elif action == 'movieSearchnew': from resources.lib.indexers import movies movies.movies().search_new() elif action == 'movieSearchterm': from resources.lib.indexers import movies movies.movies().search_term(name) elif action == 'movieMosts': from resources.lib.indexers import movies movies.movies().mosts() elif action == 'movieGenres': from resources.lib.indexers import movies movies.movies().genres() elif action == 'movieLanguages': from resources.lib.indexers import movies movies.movies().languages() elif action == 'movieCertificates': from resources.lib.indexers import movies movies.movies().certifications() elif action == 'movieYears': from resources.lib.indexers import movies movies.movies().years() elif action == 'movieDecades': from resources.lib.indexers import movies movies.movies().decades() elif action == 'movieKeywords': from resources.lib.indexers import movies movies.movies().keywords() elif action == 'movieKeywords2': from resources.lib.indexers import movies movies.movies().keywords2() elif action == 'movieCustomLists': from resources.lib.indexers import movies movies.movies().custom_lists() elif action == 'movieUserlists': from resources.lib.indexers import movies movies.movies().userlists() elif action == 'channels': from resources.lib.indexers import channels channels.channels().get() elif action == 'tvshows': from resources.lib.indexers import tvshows tvshows.tvshows().get(url) elif action == 'tvshowPage': from resources.lib.indexers import tvshows tvshows.tvshows().get(url) elif action == 'tvSearch': from resources.lib.indexers import tvshows tvshows.tvshows().search() elif action == 'tvSearchnew': from resources.lib.indexers import tvshows tvshows.tvshows().search_new() elif action == 'tvSearchterm': from resources.lib.indexers import tvshows tvshows.tvshows().search_term(name) elif action == 'tvMosts': from resources.lib.indexers import tvshows tvshows.tvshows().mosts() elif action == 'tvGenres': from resources.lib.indexers import tvshows tvshows.tvshows().genres() elif action == 'tvNetworks': from resources.lib.indexers import tvshows tvshows.tvshows().networks() elif action == 'tvLanguages': from resources.lib.indexers import tvshows tvshows.tvshows().languages() elif action == 'tvCertificates': from resources.lib.indexers import tvshows tvshows.tvshows().certifications() elif action == 'tvUserlists': from resources.lib.indexers import tvshows tvshows.tvshows().userlists() elif action == 'peopleSearch': from resources.lib.indexers import people people.People().search(content) elif action == 'peopleSearchnew': from resources.lib.indexers import people people.People().search_new(content) elif action == 'peopleSearchterm': from resources.lib.indexers import people people.People().search_term(name, content) elif action == 'persons': from resources.lib.indexers import people people.People().persons(url, content) elif action == 'moviePerson': from resources.lib.indexers import people people.People().persons(url, content='movies') elif action == 'tvPerson': from resources.lib.indexers import people people.People().persons(url, content='tvshows') elif action == 'personsSelect': from resources.lib.indexers import people people.People().getPeople(name, url) elif action == 'seasons': from resources.lib.indexers import episodes episodes.seasons().get(tvshowtitle, year, imdb, tmdb, meta) elif action == 'episodes': from resources.lib.indexers import episodes episodes.episodes().get(tvshowtitle, year, imdb, tmdb, meta, season, episode) elif action == 'calendar': from resources.lib.indexers import episodes episodes.episodes().calendar(url) elif action == 'tvWidget': from resources.lib.indexers import episodes episodes.episodes().widget() elif action == 'calendars': from resources.lib.indexers import episodes episodes.episodes().calendars() elif action == 'episodeUserlists': from resources.lib.indexers import episodes episodes.episodes().userlists() elif action == 'refresh': from resources.lib.modules import control control.refresh() elif action == 'queueItem': from resources.lib.modules import control control.queueItem() elif action == 'openSettings': from resources.lib.modules import control control.openSettings(query) elif action == 'artwork': from resources.lib.modules import control control.artwork() elif action == 'addView': from resources.lib.modules import views views.addView(content) elif action == 'moviePlaycount': from resources.lib.modules import playcount playcount.movies(imdb, query) elif action == 'episodePlaycount': from resources.lib.modules import playcount playcount.episodes(imdb, tmdb, season, episode, query) elif action == 'tvPlaycount': from resources.lib.modules import playcount playcount.tvshows(name, imdb, tmdb, season, query) elif action == 'yt_trailer': from resources.lib.modules import control, trailer if not control.condVisibility('System.HasAddon(plugin.video.youtube)'): control.installAddon('plugin.video.youtube') trailer.YT_trailer().play(name, url, tmdb, imdb, season, episode, windowedtrailer) elif action == 'tmdb_trailer': from resources.lib.modules import control, trailer if not control.condVisibility('System.HasAddon(plugin.video.youtube)'): control.installAddon('plugin.video.youtube') trailer.TMDb_trailer().play(tmdb, imdb, season, episode, windowedtrailer) elif action == 'imdb_trailer': from resources.lib.modules import trailer trailer.IMDb_trailer().play(imdb, name, tmdb, season, episode, windowedtrailer) elif action == 'traktManager': from resources.lib.modules import trakt trakt.manager(name, imdb, tmdb, content) elif action == 'authTrakt': from resources.lib.modules import trakt trakt.authTrakt() elif action == 'smuSettings': try: import resolveurl resolveurl.display_settings() except: pass elif action == 'oathscrapersettings': from resources.lib.modules import control control.openSettings('0.0', 'script.module.oathscrapers') elif action == 'installOrion': from resources.lib.modules import control control.installAddon('script.module.orion') control.sleep(200) control.refresh() elif action == 'orionsettings': from resources.lib.modules import control control.openSettings('0.0', 'script.module.orion') elif action == 'download': import simplejson as json from resources.lib.modules import sources from resources.lib.modules import downloader try: downloader.download( name, image, sources.sources().sourcesResolve(json.loads(source)[0], True)) except: pass elif action == 'play': from resources.lib.modules import control control.busy() from resources.lib.modules import sources sources.sources().play(title, year, imdb, tmdb, season, episode, tvshowtitle, premiered, meta, select, unfiltered=False) elif action == 'playUnfiltered': from resources.lib.modules import control control.busy() from resources.lib.modules import sources sources.sources().play(title, year, imdb, tmdb, season, episode, tvshowtitle, premiered, meta, select, unfiltered=True) elif action == 'addItem': from resources.lib.modules import sources sources.sources().addItem(title) elif action == 'playItem': from resources.lib.modules import sources sources.sources().playItem(title, source) elif action == 'alterSources': from resources.lib.modules import sources sources.sources().alterSources(url, meta) elif action == 'clearSources': from resources.lib.modules import sources sources.sources().clearSources() elif action == 'random': from sys import argv if rtype == 'movie': from resources.lib.indexers import movies rlist = movies.movies().get(url, create_directory=False) r = argv[0] + '?action=play' elif rtype == 'episode': from resources.lib.indexers import episodes rlist = episodes.episodes().get(tvshowtitle, year, imdb, tmdb, meta, season, create_directory=False) r = argv[0] + '?action=play' elif rtype == 'season': from resources.lib.indexers import episodes rlist = episodes.seasons().get(tvshowtitle, year, imdb, tmdb, None, create_directory=False) r = argv[0] + '?action=random&rtype=episode' elif rtype == 'show': from resources.lib.indexers import tvshows rlist = tvshows.tvshows().get(url, create_directory=False) r = argv[0] + '?action=random&rtype=season' from random import randint import simplejson as json try: from resources.lib.modules import control rand = randint(1, len(rlist)) - 1 for p in [ 'title', 'year', 'imdb', 'tmdb', 'season', 'episode', 'tvshowtitle', 'premiered', 'select' ]: if rtype == 'show' and p == 'tvshowtitle': try: r += '&' + p + '=' + urllib_parse.quote_plus( rlist[rand]['title']) except: pass else: if rtype == 'movie': rlist[rand]['title'] = rlist[rand]['originaltitle'] elif rtype == 'episode': rlist[rand]['tvshowtitle'] = urllib_parse.unquote_plus( rlist[rand]['tvshowtitle']) try: r += '&' + p + '=' + urllib_parse.quote_plus( rlist[rand][p]) except: pass try: r += '&meta=' + urllib_parse.quote_plus(json.dumps( rlist[rand])) except: r += '&meta={}' if rtype == 'movie': try: control.infoDialog( '%s (%s)' % (rlist[rand]['title'], rlist[rand]['year']), control.lang(32536), time=20000) except: pass elif rtype == 'episode': try: control.infoDialog( '%s - %01dx%02d . %s' % (urllib_parse.unquote_plus(rlist[rand]['tvshowtitle']), int(rlist[rand]['season']), int( rlist[rand]['episode']), rlist[rand]['title']), control.lang(32536), time=20000) except: pass control.execute('RunPlugin(%s)' % r) except: from resources.lib.modules import control control.infoDialog(control.lang(32537), time=8000) elif action == 'movieToLibrary': from resources.lib.modules import libtools libtools.libmovies().add(name, title, year, imdb, tmdb) elif action == 'moviesToLibrary': from resources.lib.modules import libtools libtools.libmovies().range(url) elif action == 'moviesToLibrarySilent': from resources.lib.modules import libtools libtools.libmovies().silent(url) elif action == 'tvshowToLibrary': from resources.lib.modules import libtools libtools.libtvshows().add(tvshowtitle, year, imdb, tmdb) elif action == 'tvshowsToLibrary': from resources.lib.modules import libtools libtools.libtvshows().range(url) elif action == 'tvshowsToLibrarySilent': from resources.lib.modules import libtools libtools.libtvshows().silent(url) elif action == 'updateLibrary': from resources.lib.modules import libtools libtools.libepisodes().update(query) elif action == 'service': from resources.lib.modules import libtools libtools.libepisodes().service() elif action == 'syncTraktStatus': from resources.lib.modules import trakt trakt.syncTraktStatus() elif action == 'changelog': from resources.lib.modules import changelog changelog.get() elif action == 'cleanSettings': from resources.lib.modules import control control.clean_settings() elif action == 'tvcredits': from resources.lib.modules import credits credits.Credits().get_tv(tmdb, status) elif action == 'moviecredits': from resources.lib.modules import credits credits.Credits().get_movies(tmdb, status)
def tvshows(tvshowtitle, imdb, tvdb, season, watched): # #### seasonID 0 is Full Tv Show ##### SeasonID = str(season) try: import sys,xbmc name = control.addonInfo('name') dialog = control.progressDialogBG dialog.create(str(name), str(tvshowtitle)) dialog.update(0, str(name), str(tvshowtitle)) from resources.lib.indexers import episodes year = '' items = episodes.episodes().getLibrary(tvshowtitle, year, imdb, tvdb, idx=True) if SeasonID == '0': metaShow = {'imdb':imdb, 'tvdb':tvdb} playcountMeta('tv', metaShow, str(watched)) try: items = [i for i in items] except: pass items = [{'season': int('%01d' % int(i['season'])), 'episode': int('%01d' % int(i['episode']))} for i in items] for i in range(len(items)): if xbmc.abortRequested == True: return sys.exit() season, episode = items[i]['season'], items[i]['episode'] dialog.update(int((100 / float(len(items))) * i), 'Setting MetaData', 'Season: ' + str(season) + ' Episode: ' + str(episode)) meta = {'imdb':imdb, 'tvdb':tvdb, 'season':season, 'episode':episode} playcountMeta('episode', meta, str(watched)) else: try: items = [i for i in items if int('%01d' % int(season)) == int('%01d' % int(i['season']))] except: pass items = [{'season': int('%01d' % int(i['season'])), 'episode': int('%01d' % int(i['episode']))} for i in items] for i in range(len(items)): if xbmc.abortRequested == True: return sys.exit() season, episode = items[i]['season'], items[i]['episode'] dialog.update(int((100 / float(len(items))) * i), 'Setting MetaData', 'Season: ' + str(season) + ' Episode: ' + str(episode)) meta = {'imdb':imdb, 'tvdb':tvdb, 'season':season, 'episode':episode} playcountMeta('episode', meta, str(watched)) try: dialog.close() except: pass except: try: dialog.close() except: pass try: name = control.addonInfo('name') dialog = control.progressDialogBG dialog.create(str(name), str(tvshowtitle)) dialog.update(0, str(name), str(tvshowtitle)) if trakt.getTraktIndicatorsInfo() == False: raise Exception() if not control.setting('trakt.scrobbleTV') == 'true': raise Exception() if SeasonID == '0': year = '' items = episodes.episodes().getLibrary(tvshowtitle, year, imdb, tvdb, idx=True) for i in range(len(items)): season, episode = items[i]['season'], items[i]['episode'] dialog.update(int((100 / float(len(items))) * i), 'TRAKT Watchlist', 'Season: ' + str(season) + ' Episode: ' + str(episode)) if int(watched) == 7: trakt.markEpisodeAsWatched(tvdb, season, episode) else: trakt.markEpisodeAsNotWatched(tvdb, season, episode) else: year = '' items = episodes.episodes().getLibrary(tvshowtitle, year, imdb, tvdb, idx=True) items = [(int(i['season']), int(i['episode'])) for i in items] items = [i[1] for i in items if int('%01d' % int(season)) == int('%01d' % i[0])] for i in items: dialog.update(int((100 / float(len(items))) * i), 'TRAKT Watchlist', 'Season: ' + str(season) + ' Episode: ' + str(i)) if int(watched) == 7: trakt.markEpisodeAsWatched(tvdb, season, i) else: trakt.markEpisodeAsNotWatched(tvdb, season, i) try: dialog.close() except: pass trakt.cachesyncTVShows() except: pass