def play(self, title, year, imdb, tvdb, season, episode, tvshowtitle, premiered, meta, select): try: url = None control.moderator() items = self.getSources(title, year, imdb, tvdb, season, episode, tvshowtitle, premiered) select = control.setting( 'hosts.mode') if select == None else select title = tvshowtitle if not tvshowtitle == None else title if control.window.getProperty('PseudoTVRunning') == 'True': return control.resolve( int(sys.argv[1]), True, control.item(path=str(self.sourcesDirect(items)))) if len(items) > 0: if select == '1' and 'plugin' in control.infoLabel( 'Container.PluginName'): control.window.clearProperty(self.itemProperty) control.window.setProperty(self.itemProperty, json.dumps(items)) control.window.clearProperty(self.metaProperty) control.window.setProperty(self.metaProperty, meta) control.sleep(200) return control.execute( 'Container.Update(%s?action=addItem&title=%s)' % (sys.argv[0], urllib.quote_plus(title))) elif select == '0' or select == '1': url = self.sourcesDialog(items) else: url = self.sourcesDirect(items) if url == None: return self.errorForSources() try: meta = json.loads(meta) except: pass from resources.lib.addon.player import player player().run(title, year, season, episode, imdb, tvdb, url, meta) except: pass
def sourcesDirect(self, items): items = [i for i in items] if control.setting('autoplay.sd') == 'true': items = [ i for i in items if not i['quality'] in ['4K', '2k', '1080p', 'HD'] ] u = None header = control.addonInfo('name') header2 = header.upper() try: control.sleep(1000) progressDialog = control.progressDialog progressDialog.create(header, '') progressDialog.update(0) except: pass for i in range(len(items)): try: if progressDialog.iscanceled(): break progressDialog.update(int((100 / float(len(items))) * i), str(items[i]['label']), str(' ')) except: progressDialog.update(int((100 / float(len(items))) * i), str(header2), str(items[i]['label'])) try: if xbmc.abortRequested == True: return sys.exit() url = self.sourcesResolve(items[i]) if u == None: u = url if not url == None: break except: pass try: progressDialog.close() except: pass return u
def sourcesDirect(self, items): filter = [i for i in items if i['source'].lower() in self.hostcapDict and i['debrid'] == ''] items = [i for i in items if not i in filter] filter = [i for i in items if i['source'].lower() in self.hostblockDict and i['debrid'] == ''] items = [i for i in items if not i in filter] items = [i for i in items if ('autoplay' in i and i['autoplay'] == True) or not 'autoplay' in i] if control.setting('autoplay.sd') == 'true': items = [i for i in items if not i['quality'] in ['4K', '1440p', '1080p', 'HD']] u = None header = control.addonInfo('name') header2 = header.upper() try: control.sleep(1000) progressDialog = control.progressDialog if control.setting('progress.dialog') == '0' else control.progressDialogBG progressDialog.create(header, '') progressDialog.update(0) except: pass for i in range(len(items)): try: if progressDialog.iscanceled(): break progressDialog.update(int((100 / float(len(items))) * i), str(items[i]['label']), str(' ')) except: progressDialog.update(int((100 / float(len(items))) * i), str(header2), str(items[i]['label'])) try: if xbmc.abortRequested == True: return sys.exit() url = self.sourcesResolve(items[i]) if u == None: u = url if not url == None: break except: pass try: progressDialog.close() except: pass return u
def play(self, title, year, imdb, tvdb, season, episode, tvshowtitle, premiered, meta, select): try: url = None control.moderator() items = self.getSources(title, year, imdb, tvdb, season, episode, tvshowtitle, premiered) select = control.setting('hosts.mode') if select == None else select title = tvshowtitle if not tvshowtitle == None else title if control.window.getProperty('PseudoTVRunning') == 'True': return control.resolve(int(sys.argv[1]), True, control.item(path=str(self.sourcesDirect(items)))) if len(items) > 0: if select == '1' and 'plugin' in control.infoLabel('Container.PluginName'): control.window.clearProperty(self.itemProperty) control.window.setProperty(self.itemProperty, json.dumps(items)) control.window.clearProperty(self.metaProperty) control.window.setProperty(self.metaProperty, meta) control.sleep(200) return control.execute('Container.Update(%s?action=addItem&title=%s)' % (sys.argv[0], urllib.quote_plus(title))) elif select == '0' or select == '1': url = self.sourcesDialog(items) else: url = self.sourcesDirect(items) if url == None: return self.errorForSources() try: meta = json.loads(meta) except: pass from resources.lib.addon.player import player player().run(title, year, season, episode, imdb, tvdb, url, meta) except: pass
def setView(content, viewDict=None): for i in range(0, 200): if control.condVisibility('Container.Content(%s)' % content): try: skin = control.skin record = (skin, content) dbcon = database.connect(control.viewsFile) dbcur = dbcon.cursor() dbcur.execute("SELECT * FROM views WHERE skin = '%s' AND view_type = '%s'" % (record[0], record[1])) view = dbcur.fetchone() view = view[2] if view == None: raise Exception() return control.execute('Container.SetViewMode(%s)' % str(view)) except: try: return control.execute('Container.SetViewMode(%s)' % str(viewDict[skin])) except: return control.sleep(100)
def run(self, title, year, season, episode, imdb, tvdb, url, meta): try: control.sleep(200) self.totalTime = 0 ; self.currentTime = 0 self.content = 'movie' if season == None or episode == None else 'episode' self.title = title ; self.year = year self.name = urllib.quote_plus(title) + urllib.quote_plus(' (%s)' % year) if self.content == 'movie' else urllib.quote_plus(title) + urllib.quote_plus(' S%02dE%02d' % (int(season), int(episode))) self.name = urllib.unquote_plus(self.name) self.season = '%01d' % int(season) if self.content == 'episode' else None self.episode = '%01d' % int(episode) if self.content == 'episode' else None self.DBID = None self.imdb = imdb if not imdb == None else '0' self.tvdb = tvdb if not tvdb == None else '0' self.ids = {'imdb': self.imdb, 'tvdb': self.tvdb} self.ids = dict((k,v) for k, v in self.ids.iteritems() if not v == '0') self.offset = bookmarks().get(self.name, self.year) poster, thumb, meta = self.getMeta(meta) item = control.item(path=url) item.setArt({'icon': thumb, 'thumb': thumb, 'poster': poster, 'tvshow.poster': poster, 'season.poster': poster}) item.setInfo(type='Video', infoLabels = meta) if 'plugin' in control.infoLabel('Container.PluginName'): control.player.play(url, item) control.resolve(int(sys.argv[1]), True, item) control.window.setProperty('script.trakt.ids', json.dumps(self.ids)) self.keepPlaybackAlive() control.window.clearProperty('script.trakt.ids') except: return
def playItem(self, title, source): try: meta = control.window.getProperty(self.metaProperty) meta = json.loads(meta) year = meta['year'] if 'year' in meta else None season = meta['season'] if 'season' in meta else None episode = meta['episode'] if 'episode' in meta else None imdb = meta['imdb'] if 'imdb' in meta else None tvdb = meta['tvdb'] if 'tvdb' in meta else None next = [] ; prev = [] ; total = [] for i in range(1,1000): try: u = control.infoLabel('ListItem(%s).FolderPath' % str(i)) if u in total: raise Exception() total.append(u) u = dict(urlparse.parse_qsl(u.replace('?',''))) u = json.loads(u['source'])[0] next.append(u) except: break for i in range(-1000,0)[::-1]: try: u = control.infoLabel('ListItem(%s).FolderPath' % str(i)) if u in total: raise Exception() total.append(u) u = dict(urlparse.parse_qsl(u.replace('?',''))) u = json.loads(u['source'])[0] prev.append(u) except: break items = json.loads(source) items = [i for i in items+next+prev][:40] header = control.addonInfo('name') header2 = header.upper() progressDialog = control.progressDialog if control.setting('progress.dialog') == '0' else control.progressDialogBG progressDialog.create(header, '') progressDialog.update(0) block = None for i in range(len(items)): try: try: if progressDialog.iscanceled(): break progressDialog.update(int((100 / float(len(items))) * i), str(items[i]['label']), str(' ')) except: progressDialog.update(int((100 / float(len(items))) * i), str(header2), str(items[i]['label'])) if items[i]['source'] == block: raise Exception() w = workers.Thread(self.sourcesResolve, items[i]) w.start() offset = 60 * 2 if items[i].get('source') in self.hostcapDict else 0 m = '' for x in range(3600): try: if xbmc.abortRequested == True: return sys.exit() if progressDialog.iscanceled(): return progressDialog.close() except: pass k = control.condVisibility('Window.IsActive(virtualkeyboard)') if k: m += '1'; m = m[-1] if (w.is_alive() == False or x > 30 + offset) and not k: break k = control.condVisibility('Window.IsActive(yesnoDialog)') if k: m += '1'; m = m[-1] if (w.is_alive() == False or x > 30 + offset) and not k: break time.sleep(0.5) for x in range(30): try: if xbmc.abortRequested == True: return sys.exit() if progressDialog.iscanceled(): return progressDialog.close() except: pass if m == '': break if w.is_alive() == False: break time.sleep(0.5) if w.is_alive() == True: block = items[i]['source'] if self.url == None: raise Exception() try: progressDialog.close() except: pass control.sleep(200) control.execute('Dialog.Close(virtualkeyboard)') control.execute('Dialog.Close(yesnoDialog)') from resources.lib.addon.player import player player().run(title, year, season, episode, imdb, tvdb, self.url, meta) return self.url except: pass try: progressDialog.close() except: pass self.errorForSources() except: pass
def playItem(self, title, source): try: meta = control.window.getProperty(self.metaProperty) meta = json.loads(meta) year = meta['year'] if 'year' in meta else None season = meta['season'] if 'season' in meta else None episode = meta['episode'] if 'episode' in meta else None imdb = meta['imdb'] if 'imdb' in meta else None tvdb = meta['tvdb'] if 'tvdb' in meta else None next = [] prev = [] total = [] for i in range(1, 1000): try: u = control.infoLabel('ListItem(%s).FolderPath' % str(i)) if u in total: raise Exception() total.append(u) u = dict(urlparse.parse_qsl(u.replace('?', ''))) u = json.loads(u['source'])[0] next.append(u) except: break for i in range(-1000, 0)[::-1]: try: u = control.infoLabel('ListItem(%s).FolderPath' % str(i)) if u in total: raise Exception() total.append(u) u = dict(urlparse.parse_qsl(u.replace('?', ''))) u = json.loads(u['source'])[0] prev.append(u) except: break items = json.loads(source) items = [i for i in items + next + prev][:40] header = control.addonInfo('name') header2 = header.upper() progressDialog = control.progressDialog progressDialog.create(header, '') progressDialog.update(0) block = None for i in range(len(items)): try: try: if progressDialog.iscanceled(): break progressDialog.update( int((100 / float(len(items))) * i), str(items[i]['label']), str(' ')) except: progressDialog.update( int((100 / float(len(items))) * i), str(header2), str(items[i]['label'])) if items[i]['source'] == block: raise Exception() w = workers.Thread(self.sourcesResolve, items[i]) w.start() m = '' for x in range(3600): try: if xbmc.abortRequested == True: return sys.exit() if progressDialog.iscanceled(): return progressDialog.close() except: pass k = control.condVisibility( 'Window.IsActive(virtualkeyboard)') if k: m += '1' m = m[-1] if (w.is_alive() == False or x > 30) and not k: break k = control.condVisibility( 'Window.IsActive(yesnoDialog)') if k: m += '1' m = m[-1] if (w.is_alive() == False or x > 30) and not k: break time.sleep(0.5) for x in range(30): try: if xbmc.abortRequested == True: return sys.exit() if progressDialog.iscanceled(): return progressDialog.close() except: pass if m == '': break if w.is_alive() == False: break time.sleep(0.5) if w.is_alive() == True: block = items[i]['source'] if self.url == None: raise Exception() try: progressDialog.close() except: pass control.sleep(200) control.execute('Dialog.Close(virtualkeyboard)') control.execute('Dialog.Close(yesnoDialog)') from resources.lib.addon.player import player player().run(title, year, season, episode, imdb, tvdb, self.url, meta) return self.url except: pass try: progressDialog.close() except: pass self.errorForSources() except: pass
def play_dialog(self, title, year, imdb, tvdb, season, episode, tvshowtitle, premiered, meta, select): try: url = None items = self.getSource_dialog(title, year, imdb, tvdb, season, episode, tvshowtitle, premiered) title = tvshowtitle if not tvshowtitle == None else title header = control.addonInfo('name') header2 = header.upper() try: meta = json.loads(meta) except: meta = '' progressDialog = control.progressDialog progressDialog.create(header, '') progressDialog.update(0) filter = [] for i in range(len(items)): try: try: label = '[B]%s[/B] | %s | [B][I]%s [/I][/B]' % ( items[i]['scraper'], items[i]['source'], items[i]['quality']) if progressDialog.iscanceled(): break progressDialog.update( int((100 / float(len(items))) * i), label.upper(), '') except: progressDialog.update( int((100 / float(len(items))) * i), str(header2), label.upper()) w = workers.Thread(self.sourcesResolve, items[i]) w.start() m = '' for x in range(3600): try: if xbmc.abortRequested == True: return sys.exit() if progressDialog.iscanceled(): return progressDialog.close() except: pass k = control.condVisibility( 'Window.IsActive(virtualkeyboard)') if k: m += '1' m = m[-1] if (w.is_alive() == False or x > 30) and not k: break k = control.condVisibility( 'Window.IsActive(yesnoDialog)') if k: m += '1' m = m[-1] if (w.is_alive() == False or x > 30) and not k: break time.sleep(0.5) for x in range(30): try: if xbmc.abortRequested == True: return sys.exit() if progressDialog.iscanceled(): return progressDialog.close() except: pass if m == '': break if w.is_alive() == False: break time.sleep(0.5) if w.is_alive() == True: block = items[i] if self.url == None: raise Exception() try: progressDialog.close() except: pass control.sleep(200) control.execute('Dialog.Close(virtualkeyboard)') control.execute('Dialog.Close(yesnoDialog)') from resources.lib.addon.player import player player().run(title, year, season, episode, imdb, tvdb, self.url, meta) return self.url except: pass try: progressDialog.close() except: pass self.errorForSources() except: pass
def idleForPlayback(self): for i in range(0, 200): if control.condVisibility('Window.IsActive(busydialog)') == 1: control.idle() else: break control.sleep(100)
def service(self): try: lib_tools.create_folder(os.path.join(control.transPath(control.setting('library.movie')), '')) lib_tools.create_folder(os.path.join(control.transPath(control.setting('library.tv')), '')) except: pass try: control.makeFile(control.dataPath) dbcon = database.connect(control.libcacheFile) dbcur = dbcon.cursor() dbcur.execute("CREATE TABLE IF NOT EXISTS service (""setting TEXT, ""value TEXT, ""UNIQUE(setting)"");") dbcur.execute("SELECT * FROM service WHERE setting = 'last_run'") fetch = dbcur.fetchone() if fetch == None: serviceProperty = "1970-01-01 23:59:00.000000" dbcur.execute("INSERT INTO service Values (?, ?)", ('last_run', serviceProperty)) dbcon.commit() else: serviceProperty = str(fetch[1]) dbcon.close() except: try: return dbcon.close() except: return try: control.window.setProperty(self.property, serviceProperty) except: return while not xbmc.abortRequested: try: serviceProperty = control.window.getProperty(self.property) t1 = datetime.timedelta(hours=6) t2 = datetime.datetime.strptime(serviceProperty, '%Y-%m-%d %H:%M:%S.%f') t3 = datetime.datetime.now() check = abs(t3 - t2) > t1 if check == False: raise Exception() if (control.player.isPlaying() or control.condVisibility('Library.IsScanningVideo')): raise Exception() serviceProperty = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f') control.window.setProperty(self.property, serviceProperty) try: dbcon = database.connect(control.libcacheFile) dbcur = dbcon.cursor() dbcur.execute("CREATE TABLE IF NOT EXISTS service (""setting TEXT, ""value TEXT, ""UNIQUE(setting)"");") dbcur.execute("DELETE FROM service WHERE setting = 'last_run'") dbcur.execute("INSERT INTO service Values (?, ?)", ('last_run', serviceProperty)) dbcon.commit() dbcon.close() except: try: dbcon.close() except: pass if not control.setting('library.service.update') == 'true': raise Exception() info = control.setting('library.service.notification') or 'true' self.update(info=info) except: pass control.sleep(10000)
def sourcesDirect(self, items): filter = [ i for i in items if i['source'].lower() in self.hostcapDict and i['debrid'] == '' ] items = [i for i in items if not i in filter] filter = [ i for i in items if i['source'].lower() in self.hostblockDict and i['debrid'] == '' ] items = [i for i in items if not i in filter] items = [ i for i in items if ('autoplay' in i and i['autoplay'] == True) or not 'autoplay' in i ] if control.setting('autoplay.sd') == 'true': items = [ i for i in items if not i['quality'] in ['4K', '1440p', '1080p', 'HD'] ] u = None header = control.addonInfo('name') header2 = header.upper() try: control.sleep(1000) progressDialog = control.progressDialog if control.setting( 'progress.dialog') == '0' else control.progressDialogBG progressDialog.create(header, '') progressDialog.update(0) except: pass for i in range(len(items)): try: if progressDialog.iscanceled(): break progressDialog.update(int((100 / float(len(items))) * i), str(items[i]['label']), str(' ')) except: progressDialog.update(int((100 / float(len(items))) * i), str(header2), str(items[i]['label'])) try: if xbmc.abortRequested == True: return sys.exit() url = self.sourcesResolve(items[i]) if u == None: u = url if not url == None: break except: pass try: progressDialog.close() except: pass return u