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)')
def libForPlayback(self): try: if self.DBID == None: raise Exception() if self.content == 'movie': rpc = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetMovieDetails", "params": {"movieid" : %s, "playcount" : 1 }, "id": 1 }' % str(self.DBID) elif self.content == 'episode': rpc = '{"jsonrpc": "2.0", "method": "VideoLibrary.SetEpisodeDetails", "params": {"episodeid" : %s, "playcount" : 1 }, "id": 1 }' % str(self.DBID) control.jsonrpc(rpc) ; control.refresh() except: pass
def favorites(): import json; from resources.lib.modules import control; try: favs = control.jsonrpc('{"jsonrpc": "2.0", "method": "Favourites.GetFavourites", "params": { "properties": ["path", "windowparameter"] }, "id": "1"}'); favs = json.loads(favs); favs = list(set([item for sublist in [[d.get('windowparameter', None), d.get('path', None)] for d in favs['result']['favourites']] for item in sublist if item is not None])); return favs; except Exception as inst: logger.error(inst); return [];
def add(self, name, title, year, imdb, tmdb, range=False): contains = lib_tools.ckKodiSources() if general_notification: if not control.condVisibility('Window.IsVisible(infodialog)') and not control.condVisibility('Player.HasVideo'): control.notification(title = name, message = 32552, icon = 'default', time = 1000, sound = notificationSound) try: if not self.dupe_chk == 'true': raise Exception() id = [imdb, tmdb] if tmdb != '0' else [imdb] lib = control.jsonrpc('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": {"filter":{"or": [{"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}]}, "properties" : ["imdbnumber", "title", "originaltitle", "year"]}, "id": 1}' % (year, str(int(year)+1), str(int(year)-1))) lib = unicode(lib, 'utf-8', errors = 'ignore') lib = json.loads(lib)['result']['movies'] lib = [i for i in lib if str(i['imdbnumber']) in id or (cleantitle.get(title) in [cleantitle.get(i['title'].encode('utf-8')), cleantitle.get(i['originaltitle'].encode('utf-8'))] and str(i['year']) == year)] except: lib = [] files_added = 0 try: if lib != []: raise Exception() if self.check_setting == 'true': src = lib_tools.check_sources(title, year, imdb, None, None, None, None, None) if not src: raise Exception() self.strmFile({'name': name, 'title': title, 'year': year, 'imdb': imdb, 'tmdb': tmdb}) files_added += 1 except: pass if files_added == 0 and general_notification: control.notification(title = name, message = 32652, icon = 'default', time = 1000, sound = notificationSound) if range is True: return files_added if self.library_update == 'true' and not control.condVisibility('Library.IsScanningVideo') and files_added > 0: if contains: if general_notification: control.notification(title = name, message = 32554, icon = 'default', time = 1000, sound = notificationSound) control.sleep(10000) control.execute('UpdateLibrary(video)') elif general_notification: control.notification(title = name, message = 'strm file written but library cannot be updated', icon = 'default', time = 2000, sound = notificationSound)
def playListItems(): rpc = '{"jsonrpc": "2.0", "method": "Playlist.GetItems", "params": {"playlistid" : %s}, "id": 1 }' % Id result = control.jsonrpc(rpc) limits = json.loads(result)['result']['limits'] total = limits['total'] if int(total) <= 0: return [] result = unicode(result, 'utf-8', errors='ignore') result = json.loads(result)['result']['items'] # label = cleantitle(i['label']) try: return [i['label'].encode('utf-8') for i in result] except: return []
def add(self, name, title, year, imdb, 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 try: if not self.dupe_setting == 'true': raise Exception() id = imdb lib = control.jsonrpc( '{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": {"filter":{"or": [{"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}]}, "properties" : ["imdbnumber", "originaltitle", "year"]}, "id": 1}' % (year, str(int(year) + 1), str(int(year) - 1))) lib = unicode(lib, 'utf-8', errors='ignore') lib = json.loads(lib)['result']['movies'] lib = [ i for i in lib if str(i['imdbnumber']) in id or (i['originaltitle'].encode( 'utf-8') == title and str(i['year']) == year) ][0] except: lib = [] try: if not lib == []: raise Exception() self.strmFile({ 'name': name, 'title': title, 'year': year, 'imdb': imdb }) except: pass if range == True: return 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, name, title, year, imdb, 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 try: if not self.dupe_setting == "true": raise Exception() id = imdb lib = control.jsonrpc( '{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": {"filter":{"or": [{"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}]}, "properties" : ["imdbnumber", "originaltitle", "year"]}, "id": 1}' % (year, str(int(year) + 1), str(int(year) - 1)) ) lib = unicode(lib, "utf-8", errors="ignore") lib = json.loads(lib)["result"]["movies"] lib = [ i for i in lib if str(i["imdbnumber"]) in id or (i["originaltitle"].encode("utf-8") == title and str(i["year"]) == year) ][0] except: lib = [] try: if not lib == []: raise Exception() self.strmFile({"name": name, "title": title, "year": year, "imdb": imdb}) except: pass if range == True: return 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, name, title, year, imdb, range=False): 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 try: if not self.dupe_setting == 'true': raise Exception() id = imdb lib = control.jsonrpc('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": {"filter":{"or": [{"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}]}, "properties" : ["imdbnumber", "title", "year"]}, "id": 1}' % (year, str(int(year)+1), str(int(year)-1))) lib = six.ensure_text(lib, errors='ignore') lib = json.loads(lib)['result']['movies'] lib = [i for i in lib if str(i['imdbnumber']) in id or (six.ensure_str(i['title']) == title and str(i['year']) == year)][0] except: lib = [] files_added = 0 #name = cleantitle.normalize(name) #title = cleantitle.normalize(title) try: if not lib == []: raise Exception() # if self.check_setting == 'true': # src = lib_tools.check_sources(title, year, imdb, None, None, None, None, None) # if not src: raise Exception() self.strmFile({'name': name, 'title': title, 'year': year, 'imdb': imdb}) files_added += 1 except: pass if range == True: return if self.infoDialog == 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)')
def add(self, name, title, year, imdb, tmdb, range=False): if not control.condVisibility('Window.IsVisible(infodialog)') and not control.condVisibility('Player.HasVideo')\ and self.silentDialog is False: control.infoDialog(control.lang(32552).encode('utf-8'), time=10000000) self.infoDialog = True try: if not self.dupe_setting == 'true': raise Exception() id = [imdb, tmdb] if not tmdb == '0' else [imdb] lib = control.jsonrpc('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": {"filter":{"or": [{"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}]}, "properties" : ["imdbnumber", "originaltitle", "year"]}, "id": 1}' % (year, str(int(year)+1), str(int(year)-1))) lib = unicode(lib, 'utf-8', errors='ignore') lib = json.loads(lib)['result']['movies'] lib = [i for i in lib if str(i['imdbnumber']) in id or (i['originaltitle'].encode('utf-8') == title and str(i['year']) == year)][0] except: lib = [] files_added = 0 try: if not lib == []: raise Exception() if self.check_setting == 'true': src = lib_tools.check_sources(title, year, imdb, None, None, None, None, None) if not src: raise Exception() self.strmFile({'name': name, 'title': title, 'year': year, 'imdb': imdb, 'tmdb': tmdb}) 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)')
def add(self, tvshowtitle, year, imdb, tmdb, tvdb, range=False): try: contains = lib_tools().ckKodiSources() if general_notification: if not control.condVisibility('Window.IsVisible(infodialog)') and not control.condVisibility('Player.HasVideo'): control.notification(title=tvshowtitle, message=32552) try: # from resources.lib.menus import episodes # items = episodes.Episodes().get(tvshowtitle, year, imdb, tmdb, tvdb, idx=False) from resources.lib.menus import seasons items = seasons.Seasons().tvdb_list(tvshowtitle, year, imdb, tmdb, tvdb, control.apiLanguage()['tvdb'], '-1') # fetch fresh meta (uncached) except: log_utils.error() return status = items[0]['status'].lower() try: items = [{'title': i['title'], 'year': i['year'], 'imdb': i['imdb'], 'tmdb': i['tmdb'], 'tvdb': i['tvdb'], 'season': i['season'], 'episode': i['episode'], 'tvshowtitle': i['tvshowtitle'], 'premiered': i['premiered']} for i in items] except: items = [] if items == []: return try: if self.dupe_chk != 'true': 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 = control.jsonrpc('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": {"filter":{"or": [{"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}]}, "properties": ["imdbnumber", "title", "year"]}, "id": 1}' % (year, str(int(year)+1), str(int(year)-1))) lib = unicode(lib, 'utf-8', errors='ignore') lib = 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 = 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: lib = [] files_added = 0 for i in items: if lib != []: continue if control.monitor.abortRequested(): return sys.exit() try: 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: continue # Show Season Special(Season0). if str(i.get('season')) == '0' and control.setting('tv.specials') == 'false': continue # Show Unaired or Unknown items. premiered = i.get('premiered', '0') if premiered == '0' and self.include_unknown == 'false': continue elif int(re.sub(r'[^0-9]', '', str(premiered))) > int(re.sub(r'[^0-9]', '', str(self.date))): if self.showunaired != 'true': continue self.strmFile(i) files_added += 1 except: log_utils.error() if files_added == 0 and general_notification: control.notification(title=tvshowtitle, message=32652) if range: return files_added if self.library_update == 'true' and not control.condVisibility('Library.IsScanningVideo') and files_added > 0: if contains: if general_notification: control.notification(title=tvshowtitle, message=32554) control.execute('UpdateLibrary(video)') elif general_notification: control.notification(title=tvshowtitle, message=32104) except: pass
def update(self): if control.setting('library.service.update') == 'false': control.notification(message=32106) contains = lib_tools().ckKodiSources() if not contains: control.notification(message=32107) return try: items, season, episode = [], [], [] show = [control.joinPath(self.library_folder, i) for i in control.listDir(self.library_folder)[0]] if show == []: control.notification(message=32108) return for s in show: try: season += [control.joinPath(s, i) for i in control.listDir(s)[0]] except: pass for s in season: try: episode.append([control.joinPath(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]): continue params = dict(parse_qsl(read.replace('?',''))) try: tvshowtitle = params['tvshowtitle'] except: tvshowtitle = None try: tvshowtitle = params['show'] except: pass if tvshowtitle is None or tvshowtitle == '': continue year, imdb, tvdb = params['year'], params['imdb'], params['tvdb'] imdb = 'tt' + re.sub(r'[^0-9]', '', str(imdb)) tmdb = params.get('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: return except: log_utils.error() return try: lib = control.jsonrpc('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": {"properties": ["imdbnumber", "title", "year"]}, "id": 1 }') # lib = control.jsonrpc('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": {"filter":{"or": [{"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}]}, "properties": ["imdbnumber", "title", "year"]}, "id": 1}' % (year, str(int(year)+1), str(int(year)-1))) lib = unicode(lib, 'utf-8', errors='ignore') lib = loads(lib)['result']['tvshows'] except: log_utils.error() return if service_notification and not control.condVisibility('Window.IsVisible(infodialog)') and not control.condVisibility('Player.HasVideo'): control.notification(message=32553) 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));''') dbcur.connection.commit() # from resources.lib.menus import episodes from resources.lib.menus import seasons except: log_utils.error() try: dbcur.close() ; dbcon.close() except: pass 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.date_time = (datetime.utcnow() - timedelta(hours=5)) self.date_time = datetime.utcnow() if control.setting('library.importdelay') != 'true': self.date = self.date_time.strftime('%Y%m%d') else: self.date = (self.date_time - timedelta(hours=24)).strftime('%Y%m%d') for item in items: it = None if control.monitor.abortRequested(): try: dbcur.close() ; dbcon.close() except: pass return sys.exit() try: fetch = dbcur.execute("SELECT * FROM tvshows WHERE id = '%s'" % item['tvdb']).fetchone() if fetch: it = eval(fetch[1].encode('utf-8')) except: log_utils.error() try: if it: raise Exception() # it = episodes.Episodes().get(item['tvshowtitle'], item['year'], item['imdb'], item['tmdb'], item['tvdb'], idx=False) it = seasons.Seasons().tvdb_list(item['tvshowtitle'], item['year'], item['imdb'], item['tmdb'], item['tvdb'], control.apiLanguage()['tvdb'], '-1') # fetch fresh meta (uncached) if not it: continue status = it[0]['status'].lower() it = [{'title': i['title'], 'year': i['year'], 'imdb': i['imdb'], 'tmdb': i['tmdb'], '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))) dbcur.connection.commit() except: log_utils.error() try: id = [item['imdb'], item['tvdb']] if 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 = 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: # log_utils.error() continue for i in it: if control.monitor.abortRequested(): return sys.exit() try: # Show Season Special(Season0). if str(i.get('season')) == '0' and control.setting('tv.specials') == 'false': continue # Show Unaired items. premiered = i.get('premiered', '0') if premiered == '0' and self.include_unknown == 'false': continue elif int(re.sub(r'[^0-9]', '', str(premiered))) > int(re.sub(r'[^0-9]', '', str(self.date))): if self.showunaired != 'true': continue libtvshows().strmFile(i) files_added += 1 if service_notification : control.notification(title=item['tvshowtitle'], message=32678) except: log_utils.error() try: dbcur.close() ; dbcon.close() except: pass if files_added == 0 and service_notification : control.notification(message=32109) if self.library_update == 'true' and not control.condVisibility('Library.IsScanningVideo') and files_added > 0: if contains: if service_notification: control.notification(message=32554) control.sleep(10000) control.execute('UpdateLibrary(video)') elif service_notification: control.notification(message=32103)
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)")
def getMeta(self, meta): try: poster = '0' if 'poster3' in meta: poster = meta.get('poster3') elif 'poster2' in meta: poster = meta.get('poster2') elif 'poster' in meta: poster = meta.get('poster') thumb = '0' if 'thumb3' in meta: thumb = meta.get('thumb3') elif 'thumb2' in meta: thumb = meta.get('thumb2') elif 'thumb' in meta: thumb = meta.get('thumb') fanart = '0' if 'fanart3' in meta: fanart = meta.get('fanart3') elif 'fanart2' in meta: fanart = meta.get('fanart2') elif 'fanart' in meta: fanart = meta.get('fanart') # banner == '0': # if 'banner' in meta: banner = meta.get('banner') # if banner == '0': banner = poster clearart = '0' if 'clearart' in meta: clearart = meta.get('clearart') clearlogo = '0' if 'clearlogo' in meta: clearlogo = meta.get('clearlogo') discart = '0' if 'discart' in meta: discart = meta.get('discart') if poster == '0': poster = control.addonPoster() if thumb == '0': thumb = control.addonThumb() if fanart == '0': fanart = control.addonFanart() if not 'mediatype' in meta: meta.update({ 'mediatype': 'episode' if 'episode' in meta and meta['episode'] else 'movie' }) return (poster, thumb, fanart, clearart, clearlogo, discart, meta) except: import traceback traceback.print_exc() pass try: if not self.media_type == 'movie': raise Exception() meta = control.jsonrpc( '{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": {"filter":{"or": [{"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}]}, "properties" : ["title", "originaltitle", "year", "genre", "studio", "country", "runtime", "rating", "votes", "mpaa", "director", "writer", "plot", "plotoutline", "tagline", "thumbnail", "file"]}, "id": 1}' % (self.year, str(int(self.year) + 1), str(int(self.year) - 1))) meta = unicode(meta, 'utf-8', errors='ignore') meta = json.loads(meta)['result']['movies'] t = cleantitle.get(self.title) meta = [ i for i in meta if self.year == str(i['year']) and (t == cleantitle.get( i['title']) or t == cleantitle.get(i['originaltitle'])) ][0] if not 'mediatype' in meta: meta.update({'mediatype': 'movie'}) for k, v in meta.iteritems(): if type(v) == list: try: meta[k] = str(' / '.join( [i.encode('utf-8') for i in v])) except: meta[k] = '' else: try: meta[k] = str(v.encode('utf-8')) except: meta[k] = str(v) if 'plugin' not in control.infoLabel('Container.PluginName'): self.DBID = meta.get('movieid') poster = thumb = meta.get('thumbnail') # return (poster, thumb, meta) return (poster, thumb, '', '', '', '', meta) except: import traceback traceback.print_exc() pass try: if not self.media_type == 'episode': raise Exception() meta = control.jsonrpc( '{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": {"filter":{"or": [{"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}]}, "properties" : ["title", "year", "thumbnail", "file"]}, "id": 1}' % (self.year, str(int(self.year) + 1), str(int(self.year) - 1))) meta = unicode(meta, 'utf-8', errors='ignore') meta = json.loads(meta)['result']['tvshows'] t = cleantitle.get(self.title) meta = [ i for i in meta if self.year == str(i['year']) and t == cleantitle.get(i['title']) ][0] tvshowid = meta.get('tvshowid') poster = meta.get('thumbnail') meta = control.jsonrpc( '{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params":{ "tvshowid": %d, "filter":{"and": [{"field": "season", "operator": "is", "value": "%s"}, {"field": "episode", "operator": "is", "value": "%s"}]}, "properties": ["title", "season", "episode", "showtitle", "firstaired", "runtime", "rating", "director", "writer", "plot", "thumbnail", "file"]}, "id": 1}' % (tvshowid, self.season, self.episode)) meta = unicode(meta, 'utf-8', errors='ignore') meta = json.loads(meta)['result']['episodes'][0] if not 'mediatype' in meta: meta.update({'mediatype': 'episode'}) for k, v in meta.iteritems(): if type(v) == list: try: meta[k] = str(' / '.join( [i.encode('utf-8') for i in v])) except: meta[k] = '' else: try: meta[k] = str(v.encode('utf-8')) except: meta[k] = str(v) if 'plugin' not in control.infoLabel('Container.PluginName'): self.DBID = meta.get('episodeid') thumb = meta.get('thumbnail') return (poster, thumb, '', '', '', '', meta) # return (poster, thumb, meta) except: import traceback traceback.print_exc() poster, thumb, fanart, clearart, clearlogo, discart, meta = '', '', '', '', '', '', { 'title': self.name } return (poster, thumb, fanart, clearart, clearlogo, discart, meta)
def getMeta(self, meta): try: poster = meta['poster'] if 'poster' in meta else '0' thumb = meta['thumb'] if 'thumb' in meta else poster if poster == '0': poster = control.addonPoster() return (poster, thumb, meta) except Exception: pass try: if not self.content == 'movie': raise Exception() meta = control.jsonrpc( '{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": {"filter":{"or": [{"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}]}, "properties" : ["title", "originaltitle", "year", "genre", "studio", "country", "runtime", "rating", "votes", "mpaa", "director", "writer", "plot", "plotoutline", "tagline", "thumbnail", "file"]}, "id": 1}' % (self.year, str(int(self.year) + 1), str(int(self.year) - 1))) meta = unicode(meta, 'utf-8', errors='ignore') meta = json.loads(meta)['result']['movies'] t = cleantitle.get(self.title) meta = [ i for i in meta if self.year == str(i['year']) and (t == cleantitle.get( i['title']) or t == cleantitle.get(i['originaltitle'])) ][0] for k, v in meta.iteritems(): if type(v) == list: try: meta[k] = str(' / '.join( [i.encode('utf-8') for i in v])) except Exception: meta[k] = '' else: try: meta[k] = str(v.encode('utf-8')) except Exception: meta[k] = str(v) if 'plugin' not in control.infoLabel('Container.PluginName'): self.DBID = meta['movieid'] poster = thumb = meta['thumbnail'] return (poster, thumb, meta) except Exception: pass try: if not self.content == 'episode': raise Exception() meta = control.jsonrpc( '{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": {"filter":{"or": [{"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}]}, "properties" : ["title", "year", "thumbnail", "file"]}, "id": 1}' % (self.year, str(int(self.year) + 1), str(int(self.year) - 1))) meta = unicode(meta, 'utf-8', errors='ignore') meta = json.loads(meta)['result']['tvshows'] t = cleantitle.get(self.title) meta = [ i for i in meta if self.year == str(i['year']) and t == cleantitle.get(i['title']) ][0] tvshowid = meta['tvshowid'] poster = meta['thumbnail'] meta = control.jsonrpc( '{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params":{ "tvshowid": %d, "filter":{"and": [{"field": "season", "operator": "is", "value": "%s"}, {"field": "episode", "operator": "is", "value": "%s"}]}, "properties": ["title", "season", "episode", "showtitle", "firstaired", "runtime", "rating", "director", "writer", "plot", "thumbnail", "file"]}, "id": 1}' % (tvshowid, self.season, self.episode)) meta = unicode(meta, 'utf-8', errors='ignore') meta = json.loads(meta)['result']['episodes'][0] for k, v in meta.iteritems(): if type(v) == list: try: meta[k] = str(' / '.join( [i.encode('utf-8') for i in v])) except Exception: meta[k] = '' else: try: meta[k] = str(v.encode('utf-8')) except Exception: meta[k] = str(v) if 'plugin' not in control.infoLabel('Container.PluginName'): self.DBID = meta['episodeid'] thumb = meta['thumbnail'] return (poster, thumb, meta) except Exception: pass poster, thumb, meta = '', '', {'title': self.name} return (poster, thumb, meta)
def sources(self, url, hostDict, hostprDict): sources = [] try: if url is None: return sources data = urlparse.parse_qs(url) data = dict([(i, data[i][0]) if data[i] else (i, '') for i in data]) content_type = 'episode' if 'tvshowtitle' in data else 'movie' years = (data['year'], str(int(data['year'])+1), str(int(data['year'])-1)) if content_type == 'movie': title = cleantitle.get(data['title']) localtitle = cleantitle.get(data['localtitle']) ids = [data['imdb']] r = control.jsonrpc('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": {"filter":{"or": [{"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}]}, "properties": ["imdbnumber", "title", "originaltitle", "file"]}, "id": 1}' % years) r = unicode(r, 'utf-8', errors='ignore') r = json.loads(r)['result']['movies'] r = [i for i in r if str(i['imdbnumber']) in ids or title in [cleantitle.get(i['title'].encode('utf-8')), cleantitle.get(i['originaltitle'].encode('utf-8'))]] r = [i for i in r if not i['file'].encode('utf-8').endswith('.strm')][0] r = control.jsonrpc('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovieDetails", "params": {"properties": ["streamdetails", "file"], "movieid": %s }, "id": 1}' % str(r['movieid'])) r = unicode(r, 'utf-8', errors='ignore') r = json.loads(r)['result']['moviedetails'] elif content_type == 'episode': title = cleantitle.get(data['tvshowtitle']) localtitle = cleantitle.get(data['localtvshowtitle']) season, episode = data['season'], data['episode'] ids = [data['imdb'], data['tvdb']] r = control.jsonrpc('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": {"filter":{"or": [{"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}]}, "properties": ["imdbnumber", "title"]}, "id": 1}' % years) r = unicode(r, 'utf-8', errors='ignore') r = json.loads(r)['result']['tvshows'] r = [i for i in r if str(i['imdbnumber']) in ids or title in [cleantitle.get(i['title'].encode('utf-8')), cleantitle.get(i['originaltitle'].encode('utf-8'))]][0] r = control.jsonrpc('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": {"filter":{"and": [{"field": "season", "operator": "is", "value": "%s"}, {"field": "episode", "operator": "is", "value": "%s"}]}, "properties": ["file"], "tvshowid": %s }, "id": 1}' % (str(season), str(episode), str(r['tvshowid']))) r = unicode(r, 'utf-8', errors='ignore') r = json.loads(r)['result']['episodes'] r = [i for i in r if not i['file'].encode('utf-8').endswith('.strm')][0] r = control.jsonrpc('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodeDetails", "params": {"properties": ["streamdetails", "file"], "episodeid": %s }, "id": 1}' % str(r['episodeid'])) r = unicode(r, 'utf-8', errors='ignore') r = json.loads(r)['result']['episodedetails'] url = r['file'].encode('utf-8') try: quality = int(r['streamdetails']['video'][0]['width']) except: quality = -1 if quality >= 2160: quality = '4K' if quality >= 1440: quality = '1440p' if quality >= 1080: quality = '1080p' if 720 <= quality < 1080: quality = 'HD' if quality < 720: quality = 'SD' info = [] try: f = control.openFile(url) ; s = f.size() ; f.close() s = '%.2f GB' % (float(s)/1024/1024/1024) info.append(s) except: pass try: e = urlparse.urlparse(url).path.split('.')[-1].upper() info.append(e) except: pass info = ' | '.join(info) info = info.encode('utf-8') sources.append({'source': '0', 'quality': quality, 'language': 'en', 'url': url, 'info': info, 'local': True, 'direct': True, 'debridonly': False}) return sources except: return sources
def getMeta(self): try: if self.content != 'movie': raise Exception() lib = control.jsonrpc('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": {"properties" : ["imdbnumber" , "fanart", "title", "originaltitle", "rating", "genre", "year", "director", "plot", "thumbnail"]}, "id": 1}') meta = unicode(lib, 'utf-8', errors='ignore') meta = json.loads(meta)['result']['movies'] meta = [i for i in meta if str(i['movieid']) == str(self.DBID)][0] #print ("PREMIUMIZE PLAYER META", meta) self.imdb = meta['imdbnumber'] poster = thumb = fanart = meta['thumbnail'] # PASS POSTER AND FANART FOR INPROGRESS DATABASES" if "fanart" in meta: fanart = meta['fanart'] meta['poster'] = poster for k, v in meta.iteritems(): if type(v) == list: try: meta[k] = str(' / '.join([i.encode('utf-8') for i in v])) except: meta[k] = '' else: try: meta[k] = str(v.encode('utf-8')) except: meta[k] = str(v) return (poster, thumb, fanart, meta) except: pass try: if self.content != 'episode': raise Exception() #print ("PREMIUMIZE PLAYER META EPISODES") lib = control.jsonrpc('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": {"properties" : ["tvshowid", "title", "originaltitle", "season", "episode", "plot", "thumbnail", "art", "file"]}, "id": 1}') meta = unicode(lib, 'utf-8', errors='ignore') meta = json.loads(meta)['result']['episodes'] #print ("PREMIUMIZE PLAYER META", meta) meta = [i for i in meta if str(i['episodeid']) == str(self.DBID)][0] tvshowid = meta['tvshowid'] poster = thumb = fanart = meta['thumbnail'] if "fanart" in meta: fanart = meta['fanart'] meta['poster'] = poster for k, v in meta.iteritems(): if type(v) == list: try: meta[k] = str(' / '.join([i.encode('utf-8') for i in v])) except: meta[k] = '' else: try: meta[k] = str(v.encode('utf-8')) except: meta[k] = str(v) try: rpc_file = {"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": {"properties": ["title", "imdbnumber"]}, "id": "1"} rpc_file = json.dumps(rpc_file) result_file = xbmc.executeJSONRPC(rpc_file) result_file = json.loads(result_file) result_file = result_file['result']['tvshows'] result_meta = [i for i in result_file if str(i['tvshowid']) == str(tvshowid)][0] self.imdb = result_meta['imdbnumber'] meta['tvshowtitle'] = result_meta['title'] except:pass return (poster, thumb, fanart, meta) except: pass # self.Nextup = {'tvshowid', tvshowid, 'episodeid': self.DBID } poster, thumb, fanart, meta = '', '', '', {'title': self.title} return (poster, thumb, fanart, meta)
def getMeta(self, meta): try: poster = meta['poster'] if 'poster' in meta else '0' thumb = meta['thumb'] if 'thumb' in meta else poster if poster == '0': poster = control.addonPoster() return (poster, thumb, meta) except: pass try: if not self.content == 'movie': raise Exception() meta = control.jsonrpc('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": {"filter":{"or": [{"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}]}, "properties" : ["title", "originaltitle", "year", "genre", "studio", "country", "runtime", "rating", "votes", "mpaa", "director", "writer", "plot", "plotoutline", "tagline", "thumbnail", "file"]}, "id": 1}' % (self.year, str(int(self.year)+1), str(int(self.year)-1))) meta = unicode(meta, 'utf-8', errors='ignore') meta = json.loads(meta)['result']['movies'] t = cleantitle.get(self.title) meta = [i for i in meta if self.year == str(i['year']) and (t == cleantitle.get(i['title']) or t == cleantitle.get(i['originaltitle']))][0] for k, v in meta.iteritems(): if type(v) == list: try: meta[k] = str(' / '.join([i.encode('utf-8') for i in v])) except: meta[k] = '' else: try: meta[k] = str(v.encode('utf-8')) except: meta[k] = str(v) if not 'plugin' in control.infoLabel('Container.PluginName'): self.DBID = meta['movieid'] poster = thumb = meta['thumbnail'] return (poster, thumb, meta) except: pass try: if not self.content == 'episode': raise Exception() meta = control.jsonrpc('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": {"filter":{"or": [{"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}]}, "properties" : ["title", "year", "thumbnail", "file"]}, "id": 1}' % (self.year, str(int(self.year)+1), str(int(self.year)-1))) meta = unicode(meta, 'utf-8', errors='ignore') meta = json.loads(meta)['result']['tvshows'] t = cleantitle.get(self.title) meta = [i for i in meta if self.year == str(i['year']) and t == cleantitle.get(i['title'])][0] tvshowid = meta['tvshowid'] ; poster = meta['thumbnail'] meta = control.jsonrpc('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params":{ "tvshowid": %d, "filter":{"and": [{"field": "season", "operator": "is", "value": "%s"}, {"field": "episode", "operator": "is", "value": "%s"}]}, "properties": ["title", "season", "episode", "showtitle", "firstaired", "runtime", "rating", "director", "writer", "plot", "thumbnail", "file"]}, "id": 1}' % (tvshowid, self.season, self.episode)) meta = unicode(meta, 'utf-8', errors='ignore') meta = json.loads(meta)['result']['episodes'][0] for k, v in meta.iteritems(): if type(v) == list: try: meta[k] = str(' / '.join([i.encode('utf-8') for i in v])) except: meta[k] = '' else: try: meta[k] = str(v.encode('utf-8')) except: meta[k] = str(v) if not 'plugin' in control.infoLabel('Container.PluginName'): self.DBID = meta['episodeid'] thumb = meta['thumbnail'] return (poster, thumb, meta) except: pass poster, thumb, meta = '', '', {'title': self.name} return (poster, thumb, meta)
def getMeta(self, meta): try: if not meta or ('videodb' in control.infoLabel('ListItem.FolderPath')): raise Exception() poster = meta.get('poster3') or meta.get('poster2') or meta.get( 'poster') #poster2 and poster3 may not be passed anymore thumb = meta.get('thumb') thumb = thumb or poster or control.addonThumb() season_poster = meta.get('season_poster') or poster fanart = meta.get('fanart') banner = meta.get('banner') clearart = meta.get('clearart') clearlogo = meta.get('clearlogo') discart = meta.get('discart') if 'mediatype' not in meta: meta.update( {'mediatype': 'episode' if self.episode else 'movie'}) if self.episode: meta.update({ 'tvshowtitle': self.title, 'season': self.season, 'episode': self.episode }) return (poster, thumb, season_poster, fanart, banner, clearart, clearlogo, discart, meta) except: log_utils.error() try: def cleanLibArt(art): from urllib.parse import unquote if not art: return '' art = unquote(art.replace('image://', '')) if art.endswith('/'): art = art[:-1] return art def sourcesDirMeta( metadata): # pass player minimal meta needed from lib pull if not metadata: return metadata allowed = [ 'mediatype', 'imdb', 'tmdb', 'tvdb', 'poster', 'season_poster', 'fanart', 'banner', 'clearart', 'clearlogo', 'discart', 'thumb', 'title', 'tvshowtitle', 'year', 'premiered', 'rating', 'plot', 'duration', 'mpaa', 'season', 'episode', 'castandrole' ] return { k: v for k, v in iter(metadata.items()) if k in allowed } poster, thumb, season_poster, fanart, banner, clearart, clearlogo, discart, meta = '', '', '', '', '', '', '', '', { 'title': self.name } if self.media_type != 'movie': raise Exception() # do not add IMDBNUMBER as tmdb scraper puts their id in the key value meta = control.jsonrpc( '{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": {"filter":{"or": [{"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}]}, "properties" : ["title", "originaltitle", "uniqueid", "year", "premiered", "genre", "studio", "country", "runtime", "rating", "votes", "mpaa", "director", "writer", "cast", "plot", "plotoutline", "tagline", "thumbnail", "art", "file"]}, "id": 1}' % (self.year, str(int(self.year) + 1), str(int(self.year) - 1))) meta = jsloads(meta)['result']['movies'] meta = [ i for i in meta if i.get('uniqueid', []).get('imdb', '') == self.imdb ] if meta: meta = meta[0] else: raise Exception() if 'mediatype' not in meta: meta.update({'mediatype': 'movie'}) if 'duration' not in meta: meta.update({ 'duration': meta.get('runtime') }) # Trakt scrobble resume needs this for lib playback if 'castandrole' not in meta: meta.update({ 'castandrole': [(i['name'], i['role']) for i in meta.get('cast')] }) thumb = cleanLibArt(meta.get('art').get('thumb', '')) poster = cleanLibArt(meta.get('art').get('poster', '')) or self.poster fanart = cleanLibArt(meta.get('art').get('fanart', '')) or self.fanart banner = cleanLibArt(meta.get('art').get( 'banner', '')) # not sure this is even used by player clearart = cleanLibArt(meta.get('art').get('clearart', '')) clearlogo = cleanLibArt(meta.get('art').get('clearlogo', '')) discart = cleanLibArt(meta.get('art').get('discart')) if 'plugin' not in control.infoLabel('Container.PluginName'): self.DBID = meta.get('movieid') meta = sourcesDirMeta(meta) return (poster, thumb, '', fanart, banner, clearart, clearlogo, discart, meta) except: log_utils.error() try: if self.media_type != 'episode': raise Exception() # do not add IMDBNUMBER as tmdb scraper puts their id in the key value show_meta = control.jsonrpc( '{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": {"filter":{"or": [{"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}]}, "properties" : ["title", "originaltitle", "uniqueid", "mpaa", "year", "genre", "runtime", "thumbnail", "file"]}, "id": 1}' % (self.year, str(int(self.year) + 1), str(int(self.year) - 1))) show_meta = jsloads(show_meta)['result']['tvshows'] show_meta = [ i for i in show_meta if i['uniqueid']['imdb'] == self.imdb ] show_meta = [ i for i in show_meta if i.get('uniqueid', []).get('imdb', '') == self.imdb ] if show_meta: show_meta = show_meta[0] else: raise Exception() tvshowid = show_meta['tvshowid'] meta = control.jsonrpc( '{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params":{"tvshowid": %d, "filter":{"and": [{"field": "season", "operator": "is", "value": "%s"}, {"field": "episode", "operator": "is", "value": "%s"}]}, "properties": ["showtitle", "title", "season", "episode", "firstaired", "runtime", "rating", "director", "writer", "cast", "plot", "thumbnail", "art", "file"]}, "id": 1}' % (tvshowid, self.season, self.episode)) meta = jsloads(meta)['result']['episodes'] if meta: meta = meta[0] else: raise Exception() if 'mediatype' not in meta: meta.update({'mediatype': 'episode'}) if 'tvshowtitle' not in meta: meta.update({'tvshowtitle': meta.get('showtitle')}) if 'castandrole' not in meta: meta.update({ 'castandrole': [(i['name'], i['role']) for i in meta.get('cast')] }) if 'genre' not in meta: meta.update({'genre': show_meta.get('genre')}) if 'duration' not in meta: meta.update( {'duration': meta.get('runtime')} ) # Trakt scrobble resume needs this for lib playback but Kodi lib returns "0" for shows or episodes if 'mpaa' not in meta: meta.update({'mpaa': show_meta.get('mpaa')}) if 'premiered' not in meta: meta.update({'premiered': meta.get('firstaired')}) if 'year' not in meta: meta.update({'year': show_meta.get('year') }) # shows year not year episode aired thumb = cleanLibArt(meta.get('art').get('thumb', '')) season_poster = poster = cleanLibArt( meta.get('art').get('season.poster', '')) or self.poster fanart = cleanLibArt(meta.get('art').get('tvshow.fanart', '')) or self.poster banner = cleanLibArt(meta.get('art').get( 'tvshow.banner', '')) # not sure this is even used by player clearart = cleanLibArt(meta.get('art').get('tvshow.clearart', '')) clearlogo = cleanLibArt( meta.get('art').get('tvshow.clearlogo', '')) discart = cleanLibArt(meta.get('art').get('discart')) if 'plugin' not in control.infoLabel('Container.PluginName'): self.DBID = meta.get('episodeid') meta = sourcesDirMeta(meta) return (poster, thumb, season_poster, fanart, banner, clearart, clearlogo, discart, meta) except: log_utils.error() return (poster, thumb, season_poster, fanart, banner, clearart, clearlogo, discart, meta)
def sources(self, url, hostDict, hostprDict): try: sources = [] if url == None: return sources data = urlparse.parse_qs(url) data = dict([(i, data[i][0]) if data[i] else (i, '') for i in data]) type = 'episode' if 'tvshowtitle' in data else 'movie' years = (data['year'], str(int(data['year'])+1), str(int(data['year'])-1)) def add(result, title): link = result['file'].encode('utf-8') name = os.path.basename(link) try: videoQuality = int(result['streamdetails']['video'][0]['width']) except: videoQuality = -1 threshold = 20 # Some videos are a bit smaller. if videoQuality >= 8192 - threshold: videoQuality = 'HD8K' elif videoQuality >= 6144 - threshold: videoQuality = 'HD6K' elif videoQuality >= 3840 - threshold: videoQuality = 'HD4K' elif videoQuality >= 2048 - threshold: videoQuality = 'HD2K' elif videoQuality >= 1920 - threshold: videoQuality = 'HD1080' elif videoQuality >= 1280 - threshold: videoQuality = 'HD720' else: videoQuality = 'SD' try: videoCodec = result['streamdetails']['video'][0]['codec'] except: videoCodec = None try: video3D = len(result['streamdetails']['video'][0]['stereomode']) > 0 except: video3D = None try: audioChannels = result['streamdetails']['audio'][0]['channels'] except: audioChannels = None try: audioCodec = result['streamdetails']['audio'][0]['codec'] except: audioCodec = None try: subtitle = len(result['streamdetails']['subtitle']) > 0 except: subtitle = None try: file = control.openFile(link) size = file.size() file.close() except: size = None try: meta = metadata.Metadata(name = name, title = title, link = link, size = size) meta.setVideoQuality(videoQuality) meta.setVideoCodec(videoCodec) meta.setVideo3D(video3D) meta.setAudioChannels(audioChannels) meta.setAudioCodec(audioCodec) meta.setSubtitlesSoft(subtitle) except: pass sources.append({'source': '0', 'quality': meta.videoQuality(), 'language' : self.language[0], 'url': link, 'file' : name, 'local': True, 'direct': True, 'debridonly': False, 'info' : meta.information()}) if type == 'movie': title = cleantitle.get(data['title']) ids = [data['imdb']] results = control.jsonrpc('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": {"filter":{"or": [{"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}]}, "properties": ["imdbnumber", "title", "originaltitle", "file"]}, "id": 1}' % years) results = unicode(results, 'utf-8', errors='ignore') results = json.loads(results)['result']['movies'] results = [i for i in results if str(i['imdbnumber']) in ids or title in [cleantitle.get(i['title'].encode('utf-8')), cleantitle.get(i['originaltitle'].encode('utf-8'))]] results = [i for i in results if not i['file'].encode('utf-8').endswith('.strm')] for result in results: result = control.jsonrpc('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovieDetails", "params": {"properties": ["streamdetails", "file"], "movieid": %s }, "id": 1}' % str(result['movieid'])) result = unicode(result, 'utf-8', errors='ignore') result = json.loads(result)['result']['moviedetails'] add(result, title) elif type == 'episode': title = cleantitle.get(data['tvshowtitle']) season, episode = data['season'], data['episode'] ids = [data['imdb'], data['tvdb']] results = control.jsonrpc('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": {"filter":{"or": [{"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}]}, "properties": ["imdbnumber", "title"]}, "id": 1}' % years) results = unicode(results, 'utf-8', errors='ignore') results = json.loads(results)['result']['tvshows'] results = [i for i in results if str(i['imdbnumber']) in ids or title == cleantitle.get(i['title'].encode('utf-8'))][0] results = control.jsonrpc('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": {"filter":{"and": [{"field": "season", "operator": "is", "value": "%s"}, {"field": "episode", "operator": "is", "value": "%s"}]}, "properties": ["file"], "tvshowid": %s }, "id": 1}' % (str(season), str(episode), str(results['tvshowid']))) results = unicode(results, 'utf-8', errors='ignore') results = json.loads(results)['result']['episodes'] results = [i for i in results if not i['file'].encode('utf-8').endswith('.strm')] for result in results: result = control.jsonrpc('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodeDetails", "params": {"properties": ["streamdetails", "file"], "episodeid": %s }, "id": 1}' % str(result['episodeid'])) result = unicode(result, 'utf-8', errors='ignore') result = json.loads(result)['result']['episodedetails'] add(result, title) return sources except: return sources
def updatefavorites(params): import json; from resources.lib.modules import control; url = None; title = None; thumbnail = None; isFolder = None; try: if 'action' in params: params.pop('action'); if 'url' in params: url = re.sub('/action', '/?action', params['url']); params.pop('url'); if 'name' in params: title = params['name']; params.pop('name'); if 'posterart' in params: thumbnail = params['posterart']; params.pop('posterart'); if 'isFolder' in params: isFolder = params['isFolder']; params.pop('isFolder'); if url: import json; import xbmcgui; from resources.lib.modules import control; params = urllib.urlencode(params); url += ('&' + params); if isFolder == 'True': wid = xbmcgui.getCurrentWindowId(); favs = control.jsonrpc('{"jsonrpc": "2.0", "method": "Favourites.AddFavourite", "params": {"title": "%s", "type": "window", "windowparameter": "%s", "thumbnail": "%s", "window": "%s"}, "id": 1}' % (title, url, thumbnail, 10025)); else: favs = control.jsonrpc('{"jsonrpc": "2.0", "method": "Favourites.AddFavourite", "params": {"title": "%s", "type": "media", "path": "%s", "thumbnail": "%s"}, "id": 1}' % (title, url, thumbnail)); favs = json.loads(favs); if 'result' in favs and favs['result'] != 'OK': sendNotification(32506, 5000); else: control.refresh(); except Exception as inst: logger.error(inst); sendNotification(32506, 5000); pass;
def add(self, name, title, year, imdb, tmdb, 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 try: if not self.dupe_setting == "true": raise Exception() id = [imdb, tmdb] if not tmdb == "0" else [imdb] lib = control.jsonrpc( '{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": {"filter":{"or": [{"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}]}, "properties" : ["imdbnumber", "originaltitle", "year"]}, "id": 1}' % (year, str(int(year) + 1), str(int(year) - 1)) ) lib = unicode(lib, "utf-8", errors="ignore") lib = json.loads(lib)["result"]["movies"] lib = [ i for i in lib if str(i["imdbnumber"]) in id or ( i["originaltitle"].encode("utf-8") == title and str(i["year"]) == year ) ][0] except: lib = [] files_added = 0 try: if not lib == []: raise Exception() if self.check_setting == "true": src = lib_tools.check_sources( title, year, imdb, None, None, None, None, None ) if not src: raise Exception() self.strmFile( {"name": name, "title": title, "year": year, "imdb": imdb, "tmdb": tmdb} ) 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)")
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 sources(self, url, hostDict, hostprDict): sources = [] try: if url is None: return sources data = urlparse.parse_qs(url) data = dict([(i, data[i][0]) if data[i] else (i, '') for i in data]) content_type = 'episode' if 'tvshowtitle' in data else 'movie' years = (data['year'], str(int(data['year']) + 1), str(int(data['year']) - 1)) if content_type == 'movie': title = cleantitle.get(data['title']) localtitle = cleantitle.get(data['localtitle']) ids = [data['imdb']] r = control.jsonrpc( '{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": {"filter":{"or": [{"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}]}, "properties": ["imdbnumber", "title", "originaltitle", "file"]}, "id": 1}' % years) r = unicode(r, 'utf-8', errors='ignore') r = json.loads(r)['result']['movies'] r = [ i for i in r if str(i['imdbnumber']) in ids or title in [ cleantitle.get(i['title'].encode('utf-8')), cleantitle.get(i['originaltitle'].encode('utf-8')) ] ] r = [ i for i in r if not i['file'].encode('utf-8').endswith('.strm') ][0] r = control.jsonrpc( '{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovieDetails", "params": {"properties": ["streamdetails", "file"], "movieid": %s }, "id": 1}' % str(r['movieid'])) r = unicode(r, 'utf-8', errors='ignore') r = json.loads(r)['result']['moviedetails'] elif content_type == 'episode': title = data['tvshowtitle'] localtitle = data['localtvshowtitle'] season, episode = data['season'], data['episode'] r = control.jsonrpc( '{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": {"filter":{"or": [{"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}]}, "properties": ["imdbnumber", "title"]}, "id": 1}' % years) r = unicode(r, 'utf-8', errors='ignore') r = json.loads(r)['result']['tvshows'] r = [i for i in r if title in (i['title'].encode('utf-8'))][0] r = control.jsonrpc( '{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": {"filter":{"and": [{"field": "season", "operator": "is", "value": "%s"}, {"field": "episode", "operator": "is", "value": "%s"}]}, "properties": ["file"], "tvshowid": %s }, "id": 1}' % (str(season), str(episode), str(r['tvshowid']))) r = unicode(r, 'utf-8', errors='ignore') r = json.loads(r)['result']['episodes'] r = [ i for i in r if not i['file'].encode('utf-8').endswith('.strm') ][0] r = control.jsonrpc( '{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodeDetails", "params": {"properties": ["streamdetails", "file"], "episodeid": %s }, "id": 1}' % str(r['episodeid'])) r = unicode(r, 'utf-8', errors='ignore') r = json.loads(r)['result']['episodedetails'] url = r['file'].encode('utf-8') try: quality = int(r['streamdetails']['video'][0]['width']) except: quality = -1 if quality > 1920: quality = '2160p' if quality >= 1920: quality = '1080p' if 1280 <= quality < 1900: quality = 'HD' if quality < 1280: quality = 'HQ' info = [] try: f = control.openFile(url) s = f.size() f.close() s = '%.2f GB' % (float(s) / 1024 / 1024 / 1024) info.append(s) except: pass try: c = r['streamdetails']['video'][0]['codec'] if c == 'avc1': c = 'h264' info.append(c) except: pass try: ac = r['streamdetails']['audio'][0]['codec'] if ac == 'dca': ac = 'dts' if ac == 'dtshd_ma': ac = 'dts-hd ma' info.append(ac) except: pass try: ach = r['streamdetails']['audio'][0]['channels'] if ach == 1: ach = 'mono' if ach == 2: ach = '2.0' if ach == 6: ach = '5.1' if ach == 8: ach = '7.1' info.append(ach) except: pass info = ' | '.join(info) info = info.encode('utf-8') sources.append({ 'source': '0', 'quality': quality, 'language': 'en', 'url': url, 'info': info, 'local': True, 'direct': True, 'debridonly': False }) return sources except: return sources
def sources(self, url, hostDict, hostprDict): sources = [] try: if url is None: return sources data = urlparse.parse_qs(url) data = dict([(i, data[i][0]) if data[i] else (i, '') for i in data]) content_type = 'episode' if 'tvshowtitle' in data else 'movie' years = (data['year'], str(int(data['year']) + 1), str(int(data['year']) - 1)) if content_type == 'movie': title = cleantitle.get(data['title']) localtitle = cleantitle.get(data['localtitle']) ids = [data['imdb']] r = control.jsonrpc( '{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": {"filter":{"or": [{"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}]}, "properties": ["imdbnumber", "title", "originaltitle", "file"]}, "id": 1}' % years) r = unicode(r, 'utf-8', errors='ignore') r = json.loads(r)['result']['movies'] r = [ i for i in r if str(i['imdbnumber']) in ids or title in [ cleantitle.get(i['title'].encode('utf-8')), cleantitle.get(i['originaltitle'].encode('utf-8')) ] ] r = [ i for i in r if not i['file'].encode('utf-8').endswith('.strm') ][0] r = control.jsonrpc( '{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovieDetails", "params": {"properties": ["streamdetails", "file"], "movieid": %s }, "id": 1}' % str(r['movieid'])) r = unicode(r, 'utf-8', errors='ignore') r = json.loads(r)['result']['moviedetails'] elif content_type == 'episode': title = cleantitle.get(data['tvshowtitle']) localtitle = cleantitle.get(data['localtvshowtitle']) season, episode = data['season'], data['episode'] ids = [data['imdb'], data['tvdb']] r = control.jsonrpc( '{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": {"filter":{"or": [{"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}]}, "properties": ["imdbnumber", "title"]}, "id": 1}' % years) r = unicode(r, 'utf-8', errors='ignore') r = json.loads(r)['result']['tvshows'] r = [ i for i in r if str(i['imdbnumber']) in ids or title in [ cleantitle.get(i['title'].encode('utf-8')), cleantitle.get(i['originaltitle'].encode('utf-8')) ] ][0] r = control.jsonrpc( '{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": {"filter":{"and": [{"field": "season", "operator": "is", "value": "%s"}, {"field": "episode", "operator": "is", "value": "%s"}]}, "properties": ["file"], "tvshowid": %s }, "id": 1}' % (str(season), str(episode), str(r['tvshowid']))) r = unicode(r, 'utf-8', errors='ignore') r = json.loads(r)['result']['episodes'] r = [ i for i in r if not i['file'].encode('utf-8').endswith('.strm') ][0] r = control.jsonrpc( '{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodeDetails", "params": {"properties": ["streamdetails", "file"], "episodeid": %s }, "id": 1}' % str(r['episodeid'])) r = unicode(r, 'utf-8', errors='ignore') r = json.loads(r)['result']['episodedetails'] url = r['file'].encode('utf-8') try: quality = int(r['streamdetails']['video'][0]['width']) except: quality = -1 if quality >= 2160: quality = '4K' if quality >= 1440: quality = '1440p' if quality >= 1080: quality = '1080p' if 720 <= quality < 1080: quality = 'HD' if quality < 720: quality = 'SD' info = [] try: f = control.openFile(url) s = f.size() f.close() s = '%.2f GB' % (float(s) / 1024 / 1024 / 1024) info.append(s) except: pass try: e = urlparse.urlparse(url).path.split('.')[-1].upper() info.append(e) except: pass info = ' | '.join(info) info = info.encode('utf-8') sources.append({ 'source': '0', 'quality': quality, 'language': 'en', 'url': url, 'info': info, 'local': True, 'direct': True, 'debridonly': False }) return sources except: failure = traceback.format_exc() log_utils.log('Library - Exception: \n' + str(failure)) return sources
def getMeta(self, meta): try: if meta is None: raise Exception() poster1 = meta.get('poster') poster2 = meta.get('poster2') poster3 = meta.get('poster3') poster = poster3 or poster2 or poster1 or control.addonPoster() thumb = meta.get('thumb') thumb = thumb or poster or control.addonThumb() season_poster = meta.get('season_poster') or poster fanart1 = meta.get('fanart') fanart2 = meta.get('fanart2') fanart3 = meta.get('fanart3') fanart = fanart3 or fanart2 or fanart1 or control.addonFanart() banner = meta.get('banner') clearart = meta.get('clearart') clearlogo = meta.get('clearlogo') discart = meta.get('discart') if 'mediatype' not in meta: meta.update({ 'mediatype': 'episode' if 'episode' in meta and meta['episode'] else 'movie' }) return (poster, thumb, season_poster, fanart, banner, clearart, clearlogo, discart, meta) except: log_utils.error() pass try: raise Exception( ) #kodi seems to use scraped artwork so retrival from library not needed if self.media_type != 'movie': raise Exception() meta = control.jsonrpc( '{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": {"filter":{"or": [{"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}]}, "properties" : ["title", "originaltitle", "year", "genre", "studio", "country", "runtime", "rating", "votes", "mpaa", "director", "writer", "plot", "plotoutline", "tagline", "thumbnail", "file"]}, "id": 1}' % (self.year, str(int(self.year) + 1), str(int(self.year) - 1))) meta = unicode(meta, 'utf-8', errors='ignore') meta = json.loads(meta)['result']['movies'] t = cleantitle.get(self.title) meta = [ i for i in meta if self.year == str(i['year']) and (t == cleantitle.get( i['title']) or t == cleantitle.get(i['originaltitle'])) ][0] if 'mediatype' not in meta: meta.update({'mediatype': 'movie'}) for k, v in meta.iteritems(): if type(v) == list: try: meta[k] = str(' / '.join( [i.encode('utf-8') for i in v])) except: meta[k] = '' else: try: meta[k] = str(v.encode('utf-8')) except: meta[k] = str(v) if 'plugin' not in control.infoLabel('Container.PluginName'): self.DBID = meta.get('movieid') poster = thumb = meta.get('thumbnail') # return (poster, thumb, '', '', '', '', '', '', meta) return (poster, '', '', '', '', '', '', '', meta) except: log_utils.error() pass try: raise Exception( ) #kodi seems to use scraped artwork so retrival from library not needed if self.media_type != 'episode': raise Exception() meta = control.jsonrpc( '{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": {"filter":{"or": [{"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}]}, "properties" : ["title", "year", "thumbnail", "file"]}, "id": 1}' % (self.year, str(int(self.year) + 1), str(int(self.year) - 1))) meta = unicode(meta, 'utf-8', errors='ignore') meta = json.loads(meta)['result']['tvshows'] t = cleantitle.get(self.title) meta = [ i for i in meta if self.year == str(i['year']) and t == cleantitle.get(i['title']) ][0] tvshowid = meta['tvshowid'] poster = meta['thumbnail'] meta = control.jsonrpc( '{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params":{ "tvshowid": %d, "filter":{"and": [{"field": "season", "operator": "is", "value": "%s"}, {"field": "episode", "operator": "is", "value": "%s"}]}, "properties": ["title", "season", "episode", "showtitle", "firstaired", "runtime", "rating", "director", "writer", "plot", "thumbnail", "file"]}, "id": 1}' % (tvshowid, self.season, self.episode)) meta = unicode(meta, 'utf-8', errors='ignore') meta = json.loads(meta)['result']['episodes'][0] if 'mediatype' not in meta: meta.update({'mediatype': 'episode'}) for k, v in meta.iteritems(): if type(v) == list: try: meta[k] = str(' / '.join( [i.encode('utf-8') for i in v])) except: meta[k] = '' else: try: meta[k] = str(v.encode('utf-8')) except: meta[k] = str(v) if 'plugin' not in control.infoLabel('Container.PluginName'): self.DBID = meta.get('episodeid') thumb = meta['thumbnail'] # return (poster, thumb, '', '', '', '', '', '', meta) # poster gets dropped if also passed thumb from episode return (poster, '', '', '', '', '', '', '', meta) except: log_utils.error() pass poster, thumb, season_poster, fanart, banner, clearart, clearlogo, discart, meta = '', '', '', '', '', '', '', '', { 'title': self.name } return (poster, thumb, season_poster, fanart, banner, clearart, clearlogo, discart, meta)
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 sources(self, url, hostDict, hostprDict): try: sources = [] if url == None: return sources data = urlparse.parse_qs(url) data = dict([(i, data[i][0]) if data[i] else (i, '') for i in data]) type = 'episode' if 'tvshowtitle' in data else 'movie' years = (data['year'], str(int(data['year'])+1), str(int(data['year'])-1)) if type == 'movie': title = cleantitle.get(data['title']) ids = [data['imdb']] r = control.jsonrpc('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": {"filter":{"or": [{"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}]}, "properties": ["imdbnumber", "title", "originaltitle", "file"]}, "id": 1}' % years) r = unicode(r, 'utf-8', errors='ignore') r = json.loads(r)['result']['movies'] r = [i for i in r if str(i['imdbnumber']) in ids or title in [cleantitle.get(i['title'].encode('utf-8')), cleantitle.get(i['originaltitle'].encode('utf-8'))]] r = [i for i in r if not i['file'].encode('utf-8').endswith('.strm')][0] r = control.jsonrpc('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovieDetails", "params": {"properties": ["streamdetails", "file"], "movieid": %s }, "id": 1}' % str(r['movieid'])) r = unicode(r, 'utf-8', errors='ignore') r = json.loads(r)['result']['moviedetails'] elif type == 'episode': title = cleantitle.get(data['tvshowtitle']) season, episode = data['season'], data['episode'] ids = [data['imdb'], data['tvdb']] r = control.jsonrpc('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": {"filter":{"or": [{"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}]}, "properties": ["imdbnumber", "title"]}, "id": 1}' % years) r = unicode(r, 'utf-8', errors='ignore') r = json.loads(r)['result']['tvshows'] r = [i for i in r if str(i['imdbnumber']) in ids or title == cleantitle.get(i['title'].encode('utf-8'))][0] r = control.jsonrpc('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": {"filter":{"and": [{"field": "season", "operator": "is", "value": "%s"}, {"field": "episode", "operator": "is", "value": "%s"}]}, "properties": ["file"], "tvshowid": %s }, "id": 1}' % (str(season), str(episode), str(r['tvshowid']))) r = unicode(r, 'utf-8', errors='ignore') r = json.loads(r)['result']['episodes'] r = [i for i in r if not i['file'].encode('utf-8').endswith('.strm')][0] r = control.jsonrpc('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodeDetails", "params": {"properties": ["streamdetails", "file"], "episodeid": %s }, "id": 1}' % str(r['episodeid'])) r = unicode(r, 'utf-8', errors='ignore') r = json.loads(r)['result']['episodedetails'] url = r['file'].encode('utf-8') try: quality = int(r['streamdetails']['video'][0]['width']) except: quality = -1 if quality >= 1920: quality = '1080p' elif 1280 <= quality < 1920: quality = 'HD' elif 0 <= quality < 1280: quality = 'SD' else: quality = 'SD' info = 'LOCAL SOURCE' sources.append({'source': '0', 'quality': quality, 'provider': 'Library', 'url': url, 'info': info, 'local': True, 'direct': True, 'debridonly': False}) return sources except: return sources
def add(self, name, title, year, imdb, tmdb, range=False): if not control.condVisibility('Window.IsVisible(infodialog)') and not control.condVisibility('Player.HasVideo')\ and self.silentDialog is False: control.notification(title=name, message=32552, icon='default', time=10000000, sound=notificationSound) self.infoDialog = True try: if not self.dupe_setting == 'true': raise Exception() id = [imdb, tmdb] if not tmdb == '0' else [imdb] lib = control.jsonrpc( '{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": {"filter":{"or": [{"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}]}, "properties" : ["imdbnumber", "originaltitle", "year"]}, "id": 1}' % (year, str(int(year) + 1), str(int(year) - 1))) lib = unicode(lib, 'utf-8', errors='ignore') lib = json.loads(lib)['result']['movies'] lib = [ i for i in lib if str(i['imdbnumber']) in id or (i['originaltitle'].encode( 'utf-8') == title and str(i['year']) == year) ][0] except: lib = [] files_added = 0 try: if not lib == []: raise Exception() if self.check_setting == 'true': src = lib_tools.check_sources(title, year, imdb, None, None, None, None, None) if not src: raise Exception() self.strmFile({ 'name': name, 'title': title, 'year': year, 'imdb': imdb, 'tmdb': tmdb }) files_added += 1 except: pass if range is True: return if self.infoDialog is True: control.notification(title=name, message=32554, icon='default', time=1, sound=notificationSound) if self.library_setting == 'true' and not control.condVisibility( 'Library.IsScanningVideo') and files_added > 0: control.execute('UpdateLibrary(video)')
def execute_jsonrpc(command): if not isinstance(command, basestring): command = json.dumps(command) response = control.jsonrpc(command) return json.loads(response)
def getMeta(self, meta): try: poster = meta.get('poster3', '') or meta.get('poster2', '') or meta.get( 'poster', '') or control.addonPoster() thumb = meta.get('thumb', '') or poster fanart = meta.get('fanart2', '') or meta.get( 'fanart', '') or control.addonFanart() clearlogo = meta.get('clearlogo', '') or '' clearart = meta.get('clearart', '') or '' discart = meta.get('discart', '') or '' return poster, thumb, fanart, clearlogo, clearart, discart, meta except: pass try: if not self.content == 'movie': raise Exception() meta = control.jsonrpc( '{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": {"filter":{"or": [{"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}]}, "properties" : ["title", "originaltitle", "year", "genre", "studio", "country", "runtime", "rating", "votes", "mpaa", "director", "writer", "plot", "plotoutline", "tagline", "thumbnail", "file"]}, "id": 1}' % (self.year, str(int(self.year) + 1), str(int(self.year) - 1))) meta = six.ensure_text(meta, errors='ignore') meta = json.loads(meta)['result']['movies'] t = cleantitle.get(self.title) meta = [ i for i in meta if self.year == str(i['year']) and (t == cleantitle.get( i['title']) or t == cleantitle.get(i['originaltitle'])) ][0] for k, v in six.iteritems(meta): if type(v) == list: try: meta[k] = str(' / '.join( [six.ensure_str(i) for i in v])) except: meta[k] = '' else: try: meta[k] = str(six.ensure_str(v)) except: meta[k] = str(v) if not 'plugin' in control.infoLabel('Container.PluginName'): self.DBID = meta['movieid'] poster = thumb = meta['thumbnail'] return poster, thumb, '', '', '', '', meta except: pass try: if not self.content == 'episode': raise Exception() meta = control.jsonrpc( '{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": {"filter":{"or": [{"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}]}, "properties" : ["title", "year", "thumbnail", "file"]}, "id": 1}' % (self.year, str(int(self.year) + 1), str(int(self.year) - 1))) meta = six.ensure_text(meta, errors='ignore') meta = json.loads(meta)['result']['tvshows'] t = cleantitle.get(self.title) meta = [ i for i in meta if self.year == str(i['year']) and t == cleantitle.get(i['title']) ][0] tvshowid = meta['tvshowid'] poster = meta['thumbnail'] meta = control.jsonrpc( '{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params":{ "tvshowid": %d, "filter":{"and": [{"field": "season", "operator": "is", "value": "%s"}, {"field": "episode", "operator": "is", "value": "%s"}]}, "properties": ["title", "season", "episode", "showtitle", "firstaired", "runtime", "rating", "director", "writer", "plot", "thumbnail", "file"]}, "id": 1}' % (tvshowid, self.season, self.episode)) meta = six.ensure_text(meta, errors='ignore') meta = json.loads(meta)['result']['episodes'][0] for k, v in six.iteritems(meta): if type(v) == list: try: meta[k] = str(' / '.join( [six.ensure_str(i) for i in v])) except: meta[k] = '' else: try: meta[k] = str(six.ensure_str(v)) except: meta[k] = str(v) if not 'plugin' in control.infoLabel('Container.PluginName'): self.DBID = meta['episodeid'] thumb = meta['thumbnail'] return poster, thumb, '', '', '', '', meta except: pass poster, thumb, fanart, clearlogo, clearart, discart, meta = '', '', '', '', '', '', { 'title': self.name } return poster, thumb, fanart, clearlogo, clearart, discart, meta
def libraryProgrees(self, content, currentTime, totalTime, DBID): try: if content == 'movie': rpc = '{"jsonrpc": "2.0", "id": 1, "method": "VideoLibrary.SetMovieDetails", "params": {"movieid": %s , "resume": {"position": %s, "total": %s}}}' % (DBID, currentTime, totalTime) else: rpc = '{"jsonrpc": "2.0", "id": 1, "method": "VideoLibrary.SetEpisodeDetails", "params": {"episodeid": %s , "resume": {"position": %s, "total": %s}}}' % (DBID, currentTime, totalTime) control.jsonrpc(rpc) except: pass
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 sources(self, url, hostDict, hostprDict): try: sources = [] if url == None: return sources data = urlparse.parse_qs(url) data = dict([(i, data[i][0]) if data[i] else (i, '') for i in data]) type = 'episode' if 'tvshowtitle' in data else 'movie' years = (data['year'], str(int(data['year']) + 1), str(int(data['year']) - 1)) def add(result, title): link = result['file'].encode('utf-8') name = os.path.basename(link) try: videoQuality = int( result['streamdetails']['video'][0]['width']) except: videoQuality = -1 threshold = 20 # Some videos are a bit smaller. if videoQuality >= 8192 - threshold: videoQuality = 'HD8K' elif videoQuality >= 6144 - threshold: videoQuality = 'HD6K' elif videoQuality >= 3840 - threshold: videoQuality = 'HD4K' elif videoQuality >= 2048 - threshold: videoQuality = 'HD2K' elif videoQuality >= 1920 - threshold: videoQuality = 'HD1080' elif videoQuality >= 1280 - threshold: videoQuality = 'HD720' else: videoQuality = 'SD' try: videoCodec = result['streamdetails']['video'][0]['codec'] except: videoCodec = None try: video3D = len( result['streamdetails']['video'][0]['stereomode']) > 0 except: video3D = None try: audioChannels = result['streamdetails']['audio'][0][ 'channels'] except: audioChannels = None try: audioCodec = result['streamdetails']['audio'][0]['codec'] except: audioCodec = None try: subtitle = len(result['streamdetails']['subtitle']) > 0 except: subtitle = None try: file = control.openFile(link) size = file.size() file.close() except: size = None try: meta = metadata.Metadata(name=name, title=title, link=link, size=size) meta.setVideoQuality(videoQuality) meta.setVideoCodec(videoCodec) meta.setVideo3D(video3D) meta.setAudioChannels(audioChannels) meta.setAudioCodec(audioCodec) meta.setSubtitlesSoft(subtitle) except: pass sources.append({ 'source': '0', 'quality': meta.videoQuality(), 'language': self.language[0], 'url': link, 'file': name, 'local': True, 'direct': True, 'debridonly': False, 'metadata': meta }) if type == 'movie': title = cleantitle.get(data['title']) ids = [data['imdb']] results = control.jsonrpc( '{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": {"filter":{"or": [{"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}]}, "properties": ["imdbnumber", "title", "originaltitle", "file"]}, "id": 1}' % years) results = unicode(results, 'utf-8', errors='ignore') results = json.loads(results)['result']['movies'] results = [ i for i in results if str(i['imdbnumber']) in ids or title in [ cleantitle.get(i['title'].encode('utf-8')), cleantitle.get(i['originaltitle'].encode('utf-8')) ] ] results = [ i for i in results if not i['file'].encode('utf-8').endswith('.strm') ] for result in results: result = control.jsonrpc( '{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovieDetails", "params": {"properties": ["streamdetails", "file"], "movieid": %s }, "id": 1}' % str(result['movieid'])) result = unicode(result, 'utf-8', errors='ignore') result = json.loads(result)['result']['moviedetails'] add(result, title) elif type == 'episode': title = cleantitle.get(data['tvshowtitle']) season, episode = data['season'], data['episode'] ids = [data['imdb'], data['tvdb']] results = control.jsonrpc( '{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": {"filter":{"or": [{"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}]}, "properties": ["imdbnumber", "title"]}, "id": 1}' % years) results = unicode(results, 'utf-8', errors='ignore') results = json.loads(results)['result']['tvshows'] results = [ i for i in results if str(i['imdbnumber']) in ids or title == cleantitle.get(i['title'].encode('utf-8')) ][0] results = control.jsonrpc( '{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": {"filter":{"and": [{"field": "season", "operator": "is", "value": "%s"}, {"field": "episode", "operator": "is", "value": "%s"}]}, "properties": ["file"], "tvshowid": %s }, "id": 1}' % (str(season), str(episode), str(results['tvshowid']))) results = unicode(results, 'utf-8', errors='ignore') results = json.loads(results)['result']['episodes'] results = [ i for i in results if not i['file'].encode('utf-8').endswith('.strm') ] for result in results: result = control.jsonrpc( '{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodeDetails", "params": {"properties": ["streamdetails", "file"], "episodeid": %s }, "id": 1}' % str(result['episodeid'])) result = unicode(result, 'utf-8', errors='ignore') result = json.loads(result)['result']['episodedetails'] add(result, title) return sources except: return sources
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 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)')
def getMeta(self, meta): try: if not meta: raise Exception() poster = meta.get('poster3') or meta.get('poster2') or meta.get( 'poster') #poster2 and poster3 may not be passed anymore thumb = meta.get('thumb') thumb = thumb or poster or control.addonThumb() season_poster = meta.get('season_poster') or poster fanart = meta.get('fanart') banner = meta.get('banner') clearart = meta.get('clearart') clearlogo = meta.get('clearlogo') discart = meta.get('discart') if 'mediatype' not in meta: meta.update( {'mediatype': 'episode' if self.episode else 'movie'}) if self.episode: meta.update({'season': self.season}) meta.update({'episode': self.episode}) meta.update({'tvshowtitle': self.title}) return (poster, thumb, season_poster, fanart, banner, clearart, clearlogo, discart, meta) except: log_utils.error() try: if self.media_type != 'movie': raise Exception() meta = control.jsonrpc( '{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": {"filter":{"or": [{"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}]}, "properties" : ["title", "originaltitle", "year", "genre", "studio", "country", "runtime", "rating", "votes", "mpaa", "director", "writer", "plot", "plotoutline", "tagline", "thumbnail", "file"]}, "id": 1}' % (self.year, str(int(self.year) + 1), str(int(self.year) - 1))) meta = py_tools.ensure_text(meta, errors='ignore') meta = jsloads(meta)['result']['movies'] t = cleantitle.get(self.title) meta = [ i for i in meta if self.year == str(i['year']) and (t == cleantitle.get( i['title']) or t == cleantitle.get(i['originaltitle'])) ][0] if 'mediatype' not in meta: meta.update({'mediatype': 'movie'}) if 'duration' not in meta: meta.update({'duration': meta.get('runtime') / 60 }) # this doesn't make sense for k, v in control.iteritems(meta): if type(v) == list: try: meta[k] = str(' / '.join([i for i in v])) except: meta[k] = '' else: try: meta[k] = str(v) except: meta[k] = str(v) if 'plugin' not in control.infoLabel('Container.PluginName'): self.DBID = meta.get('movieid') poster = thumb = meta.get('thumbnail') return (poster, thumb, '', '', '', '', '', '', meta) except: log_utils.error() try: if self.media_type != 'episode': raise Exception() meta = control.jsonrpc( '{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": {"filter":{"or": [{"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}]}, "properties" : ["title", "year", "thumbnail", "file"]}, "id": 1}' % (self.year, str(int(self.year) + 1), str(int(self.year) - 1))) meta = py_tools.ensure_text(meta, errors='ignore') meta = jsloads(meta)['result']['tvshows'] t = cleantitle.get(self.title) meta = [ i for i in meta if self.year == str(i['year']) and t == cleantitle.get(i['title']) ][0] tvshowid = meta['tvshowid'] poster = meta['thumbnail'] meta = control.jsonrpc( '{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params":{ "tvshowid": %d, "filter":{"and": [{"field": "season", "operator": "is", "value": "%s"}, {"field": "episode", "operator": "is", "value": "%s"}]}, "properties": ["title", "season", "episode", "showtitle", "firstaired", "runtime", "rating", "director", "writer", "plot", "thumbnail", "file"]}, "id": 1}' % (tvshowid, self.season, self.episode)) meta = py_tools.ensure_text(meta, errors='ignore') meta = jsloads(meta)['result']['episodes'][0] if 'mediatype' not in meta: meta.update({'mediatype': 'episode'}) if 'duration' not in meta: meta.update({'duration': meta.get('runtime') / 60 }) # this doesn't make sense for k, v in control.iteritems(meta): if type(v) == list: try: meta[k] = str(' / '.join([i for i in v])) except: meta[k] = '' else: try: meta[k] = str(v) except: meta[k] = str(v) if 'plugin' not in control.infoLabel('Container.PluginName'): self.DBID = meta.get('episodeid') thumb = meta['thumbnail'] return (poster, thumb, '', '', '', '', '', '', meta) except: log_utils.error() poster, thumb, season_poster, fanart, banner, clearart, clearlogo, discart, meta = '', '', '', '', '', '', '', '', { 'title': self.name } return (poster, thumb, season_poster, fanart, banner, clearart, clearlogo, discart, meta)
def getMeta(self, meta): try: if not meta: raise Exception() poster = meta.get('poster3') or meta.get('poster2') or meta.get('poster') #poster2 and poster3 may not be passed anymore thumb = meta.get('thumb') thumb = thumb or poster or control.addonThumb() season_poster = meta.get('season_poster') or poster fanart = meta.get('fanart') banner = meta.get('banner') clearart = meta.get('clearart') clearlogo = meta.get('clearlogo') discart = meta.get('discart') if 'mediatype' not in meta: meta.update({'mediatype': 'episode' if self.episode else 'movie'}) if self.episode: meta.update({'tvshowtitle': self.title, 'season': self.season, 'episode': self.episode}) return (poster, thumb, season_poster, fanart, banner, clearart, clearlogo, discart, meta) except: log_utils.error() try: def cleanLibArt(art): from urllib.parse import unquote if not art: return '' art = unquote(art.replace('image://', '')) if art.endswith('/'): art = art[:-1] return art poster, thumb, season_poster, fanart, banner, clearart, clearlogo, discart, meta = '', '', '', '', '', '', '', '', {'title': self.name} if self.media_type != 'movie': raise Exception() meta = control.jsonrpc('{"jsonrpc": "2.0", "method": "VideoLibrary.GetMovies", "params": {"filter":{"or": [{"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}]}, "properties" : ["title", "originaltitle", "year", "premiered", "genre", "studio", "country", "runtime", "rating", "votes", "mpaa", "director", "writer", "plot", "plotoutline", "tagline", "thumbnail", "art", "file"]}, "id": 1}' % (self.year, str(int(self.year) + 1), str(int(self.year) - 1))) meta = jsloads(meta)['result']['movies'] t = cleantitle.get(self.title.replace('&', 'and')) years = [str(self.year), str(int(self.year)+1), str(int(self.year)-1)] meta = [i for i in meta if str(i['year']) in years and (t == cleantitle.get(i['title'].replace('&', 'and')) or t == cleantitle.get(i['originaltitle'].replace('&', 'and')))] if meta: meta = meta[0] else: raise Exception() if 'mediatype' not in meta: meta.update({'mediatype': 'movie'}) if 'duration' not in meta: meta.update({'duration': meta.get('runtime')}) # Trakt scrobble resume needs this for lib playback thumb = cleanLibArt(meta.get('art').get('thumb', '')) poster = cleanLibArt(meta.get('art').get('poster', '')) or self.poster fanart = cleanLibArt(meta.get('art').get('fanart', '')) or self.fanart banner = cleanLibArt(meta.get('art').get('banner', '')) clearart = cleanLibArt(meta.get('art').get('clearart', '')) clearlogo = cleanLibArt(meta.get('art').get('clearlogo', '')) discart = cleanLibArt(meta.get('art').get('discart')) for k, v in iter(meta.items()): if type(v) == list: try: meta[k] = str(' / '.join([i for i in v])) except: meta[k] = '' else: try: meta[k] = str(v) except: meta[k] = str(v) if 'plugin' not in control.infoLabel('Container.PluginName'): self.DBID = meta.get('movieid') return (poster, thumb, '', fanart, banner, clearart, clearlogo, discart, meta) except: log_utils.error() try: if self.media_type != 'episode': raise Exception() show_meta = control.jsonrpc('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": {"filter":{"or": [{"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}, {"field": "year", "operator": "is", "value": "%s"}]}, "properties" : ["title", "originaltitle", "mpaa", "year", "runtime", "thumbnail", "file"]}, "id": 1}' % (self.year, str(int(self.year)+1), str(int(self.year)-1))) show_meta = jsloads(show_meta)['result']['tvshows'] t = cleantitle.get(self.title.replace('&', 'and')) show_meta = [i for i in show_meta if self.year == str(i['year']) and (t == cleantitle.get(i['title'].replace('&', 'and')) or t == cleantitle.get(i['originaltitle'].replace('&', 'and')))] if show_meta: show_meta = show_meta[0] else: raise Exception() tvshowid = show_meta['tvshowid'] meta = control.jsonrpc('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params":{ "tvshowid": %d, "filter":{"and": [{"field": "season", "operator": "is", "value": "%s"}, {"field": "episode", "operator": "is", "value": "%s"}]}, "properties": ["title", "season", "episode", "showtitle", "firstaired", "runtime", "rating", "director", "writer", "plot", "thumbnail", "art", "file"]}, "id": 1}' % (tvshowid, self.season, self.episode)) meta = jsloads(meta)['result']['episodes'] if meta: meta = meta[0] else: raise Exception() if 'mediatype' not in meta: meta.update({'mediatype': 'episode'}) if 'duration' not in meta: meta.update({'duration': meta.get('runtime')}) # Trakt scrobble resume needs this for lib playback if 'mpaa' not in meta: meta.update({'mpaa': show_meta.get('mpaa')}) if 'premiered' not in meta: meta.update({'premiered': meta.get('firstaired')}) if 'year' not in meta: meta.update({'year': meta.get('firstaired')[:4]}) thumb = cleanLibArt(meta.get('art').get('thumb', '')) season_poster = poster = cleanLibArt(meta.get('art').get('season.poster', '')) or self.poster fanart = cleanLibArt(meta.get('art').get('tvshow.fanart', '')) or self.poster banner = cleanLibArt(meta.get('art').get('tvshow.banner', '')) clearart = cleanLibArt(meta.get('art').get('tvshow.clearart', '')) clearlogo = cleanLibArt(meta.get('art').get('tvshow.clearlogo', '')) discart = cleanLibArt(meta.get('art').get('discart')) for k, v in iter(meta.items()): if type(v) == list: try: meta[k] = str(' / '.join([i for i in v])) except: meta[k] = '' else: try: meta[k] = str(v) except: meta[k] = str(v) if 'plugin' not in control.infoLabel('Container.PluginName'): self.DBID = meta.get('episodeid') return (poster, thumb, season_poster, fanart, banner, clearart, clearlogo, discart, meta) except: log_utils.error() return (poster, thumb, season_poster, fanart, banner, clearart, clearlogo, discart, meta)