def getTraktLastActivity(self, typ='movie'): res = [] try: if trakt.getTraktCredentialsInfo() == True: if sctop.traktlistlast is None: loc = self.cache.get('lastActivity') rem = str(trakt.getWatchedActivity()) util.debug("[SC] loc: [%s] rem: [%s]" % (loc, rem)) if loc is None or rem != loc: self.cache.set('lastActivity', str(rem)) alres = { 'movie': trakt.syncMovies(), 'series': trakt.syncTVShows() } self.cache.set('LastActivityList', repr(alres)) else: alres = eval(self.cache.get('LastActivityList')) else: alres = sctop.traktlistlast sctop.traktlistlast = alres res = alres.get(typ) except: util.debug('[SC] getTraktLastActivity ERR: %s' % str(traceback.format_exc())) pass util.debug('[SC] getTraktLastActivity ret: %s' % str(res)) return res
def setWatched(self): if self.ids is not None and trakt.getTraktCredentialsInfo() == True \ and trakt.getTraktAddonMovieInfo() == False: util.debug( "[SC] nemame instalovany trakt.tv, tak oznacime film/serial za videny" ) if self.se is not None and self.se.isdigit( ) and self.ep is not None and self.ep.isdigit(): util.debug("[SC] serial [%s]x[%s]" % (str(self.se), str(self.ep))) trakt.markEpisodeAsWatchedT(self.ids, self.se, self.ep) else: util.debug("[SC] film") trakt.markMovieAsWatchedT(self.ids) if self.itemDBID == None: return if self.itemType == 'episode': metaReq = { "jsonrpc": "2.0", "method": "VideoLibrary.SetEpisodeDetails", "params": { "episodeid": self.itemDBID, "playcount": 1 }, "id": 1 } self.executeJSON(metaReq) elif self.itemType == 'movie': metaReq = { "jsonrpc": "2.0", "method": "VideoLibrary.SetMovieDetails", "params": { "movieid": self.itemDBID, "playcount": 1 }, "id": 1 } self.executeJSON(metaReq)
def ctx(self, item, data): try: from collections import OrderedDict menu = OrderedDict() except ImportError as e: menu = {} #util.debug("CTX ITM: %s" % str(item)) #util.debug("CTX DAT: %s" % str(data)) #if 'dir' in data and data['dir'] == 'tvshows': if 'csearch' in item: menu.update({ "Edit": { "action": "csearch-edit", "id": item['id'], "title": item['csearch'] } }) menu.update({ "Remove": { "action": "csearch-remove", "id": item['id'], "title": item['csearch'] } }) if 'tl' in item: menu.update({ "$30918": { "action": "add-to-lib-trakt", "tl": item['tl'], "title": data['title'], 'tu': item['tu'] if 'tu' in item else 'me' } }) if 'list' in item and item['list'] == 'liked': menu.update({ "$30977": { "action": "traktListUnlike", "title": item['title'], "tu": item['tu'], "id": item['id'] } }) elif 'list' in item and item['tu'] != 'me': menu.update({ "$30978": { "action": "traktListLike", "title": data['title'], "tu": item['tu'], "id": item['id'] } }) if 'list' in item and item['list'] == 'user' and item['tu'] == 'me': menu.update({ "$30979": { 'action': 'traktListCustomRemove', 'title': data['title'], 'id': item['id'], } }) elif 'list' in item: menu.update({ "$30980": { 'action': 'traktListClone', 'title': data['title'], 'id': item['id'], 'tu': item['tu'] } }) menu.update({ "$30981": { 'action': 'traktListAppendToCustom', 'id': item['id'], 'tu': item['tu'] } }) if 'id' in data and data['id'].isdigit(): if 'imdb' in data and data['imdb'] > 0: menu.update({ "$30942": { "action": "info", 'imdb': "tt%07d" % int(data['imdb']) } }) #{"cmd":'Action("Info")'}}) else: menu.update({"$30942": {"cmd": 'Action("Info")'}}) params = self.parent.params() params.update({ 'action': 'play-force', 'url': item['url'], 'play': item['url'], 'dtitle': item['title'], 'force': 'true' }) menu.update({"$30949": params}) try: id = int(data['id']) #menu.update({"report stream": {"action": "report", "id": data['id'], "title": data['title']}}) except Exception: pass if 'trakt' in data and data['trakt'].isdigit( ) and trakt.getTraktCredentialsInfo() == True: #name, imdb, tvdb, content content = 'series' if 'season' in data and data['season'].isdigit( ) else 'movie' menu.update({ "Trakt menu": { "action": "traktManager", 'name': data['title'], 'trakt': data['trakt'], 'content': content } }) if 'id' in data and data['id'].isdigit() and 'season' not in data: menu.update({ "$30918": { "action": "add-to-lib", "id": 'movies/%d' % int(data['id']), "title": data['title'] } }) if 'id' in data and data['id'] == 'series': menu.update({ "$30923": { "action": "add-to-lib-sub", "id": data['id'], "title": data['title'] } }) if 'id' in data and data['id'] == 'movies': menu.update({ "$30918": { "action": "add-to-lib", "id": data['id'], "title": data['title'] } }) menu.update({ "$30926": { "action": "add-to-lib", "id": data['id'], "title": data['title'], "force": "1" } }) #util.debug("[SC] MAME menu!") #util.debug("[SC] data %s" % str(data)) if 'season' in data or data.get('id') == 'series': if data['id'] in self.subs.keys() and data['id'] != 'series': item['title'] = "[COLOR red]*[/COLOR] %s" % item['title'] #util.debug("[SC] Serial je v odoberani: %s" % data['title']) menu.update({ "$30924": { "action": "remove-from-sub", "id": data['id'], "title": data['title'] } }) else: #util.debug("[SC] Serial neodoberam: %s" % data['title']) menu.update({ "$30918": { "action": "add-to-lib", "id": data['id'], "title": data['title'] } }) menu.update({ "$30923": { "action": "add-to-lib-sub", "id": data['id'], "title": data['title'] } }) #menu.update({"$30922": {"cmd":'Addon.OpenSettings("%s")' % sctop.__scriptid__}}) #menu.update({"run Schedule": {"action": "subs"}}) #menu.update({"test": {"action": "test"}}) #menu.update({"last": {'cp': 'czsklib', 'list': 'http://stream-cinema.online/json/movies-a-z'}}) item['menu'] = menu return item
def onPlayBackStarted(self): if self.scid is not None: self.onPlayBackStopped() self.upNextEnable = True self.se = None self.ep = None self.libItem = None self.watchedTime = 0 self.log("[SC] Zacalo sa prehravat") mojPlugin = self.win.getProperty(sctop.__scriptid__) if sctop.__scriptid__ not in mojPlugin: util.debug("[SC] Nieje to moj plugin ... ") return util.debug("[SC] JE to moj plugin ... %s" % str(mojPlugin)) self.scid = self.win.getProperty('scid') try: self.ids = json.loads( self.win.getProperty('%s.ids' % sctop.__scriptid__)) except: self.ids = {} pass try: stream = json.loads( self.win.getProperty('%s.stream' % sctop.__scriptid__)) util.debug("[SC] stream %s" % str(stream)) except: stream = {} pass self.stream = stream self.win.clearProperty(sctop.__scriptid__) self.win.clearProperty('%s.ids' % sctop.__scriptid__) self.win.clearProperty('%s.stream' % sctop.__scriptid__) self.win.clearProperty('scid') self.win.clearProperty('scresume') try: if sctop.getSettingAsBool('filter_audio'): util.debug("[SC] skusam vybrat spravne audio") self.selectAudio() else: util.debug("[SC] nemame filter pre audio") except: util.debug( "[SC] XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" ) pass try: if not self.isPlayingVideo(): return self.itemDuration = self.getTotalTime() # plánovaný čas dokončení 100 % přehrání self.estimateFinishTime = xbmc.getInfoLabel( 'Player.FinishTime(hh:mm:ss)') if 'originaltitle' in stream: season = stream.get('season') episode = stream.get('episode') if episode is not None and season is not None: showtitle = stream.get('originaltitle') else: showtitle = None year = stream.get('year') title = stream.get('originaltitle') try: imdb = 'tt%07d' % int(stream.get('imdb')) if stream.get( 'imdb').isdigit() else None except: imdb = None util.debug("[SC] imdb %s" % str(traceback.format_exc())) self.se = season self.ep = episode else: season = xbmc.getInfoLabel('VideoPlayer.Season') episode = xbmc.getInfoLabel('VideoPlayer.Episode') self.se = season self.ep = episode showtitle = xbmc.getInfoLabel('VideoPlayer.TVShowTitle') year = xbmc.getInfoLabel('VideoPlayer.Year') title = xbmc.getInfoLabel('VideoPlayer.Title') imdb = xbmc.getInfoLabel( "VideoPlayer.IMDBNumber") #"ListItem.IMDBNumber") if episode is not None: util.debug("[SC] Serial") self.itemType = 'episode' else: util.debug("[SC] Film") self.itemType = 'movie' try: if self.itemType == 'movie': method = 'VideoLibrary.GetMovies' try: if self.ids is not None and trakt.getTraktCredentialsInfo( ) == True: #trakt.addTraktCollection({'movies':[{'ids':self.ids}]}) pass except: self.log( "[SC] trakt.tv error - nepodarilo sa pridat film do kolekcie: %s" % str(traceback.format_exc())) pass value = "%s (%s).strm" % (self.parent.normalize_filename( str(title)), str(year)) field = 'filename' res = self.executeJSON({ 'jsonrpc': '2.0', 'method': method, 'params': { 'filter': { 'operator': 'contains', 'field': field, 'value': value }, 'properties': ['file', 'resume'], }, 'id': 1 }) if 'result' in res and 'movies' in res['result']: for m in res['result']['movies']: util.debug("[SC] m: %s" % str(m)) if 'movieid' in m: self.libItem = m self.itemDBID = m['movieid'] break else: if self.ids is not None and trakt.getTraktCredentialsInfo( ) == True: #trakt.addTraktCollection({'shows':[{'ids':self.ids}]}) pass if self.parent is not None: try: self.parent.addLast(self.scid) except Exception, e: util.error(e) pass method = 'VideoLibrary.GetTVShows' value = self.parent.normalize_filename( str(showtitle) ) #/Season %s/%sx%s.strm" % (showtitle, season, season, episode) field = 'path' res = self.executeJSON({ 'jsonrpc': '2.0', 'method': method, 'params': { 'filter': { 'operator': 'contains', 'field': field, 'value': value } }, 'id': 1 }) if 'result' in res: for m in res['result']['tvshows']: if 'tvshowid' in m: self.itemDBID = int(m['tvshowid']) res = self.executeJSON({ 'jsonrpc': '2.0', 'method': 'VideoLibrary.GetEpisodes', 'params': { 'tvshowid': int(m['tvshowid']), 'season': int(season), 'properties': ['episode', 'file', 'resume'], 'sort': { 'method': 'episode' } }, 'id': 1 }) util.info("[SC] tvshow json: %s" % str(res)) for e in res['result']['episodes']: if int(e['episode']) == int(episode): self.libItem = e self.itemDBID = e['episodeid'] break break except Exception: self.log("[SC] Chyba JSONRPC: %s" % str(traceback.format_exc())) pass res = self.executeJSON({ 'jsonrpc': '2.0', 'method': 'Player.GetItem', 'params': { 'playerid': 1 }, 'id': 1 }) if res: _filename = None try: _filename = os.path.basename(self.getPlayingFile()) except: util.debug( "[SC] onPlayBackStarted() - Exception trying to get playing filename, player suddenly stopped." ) return util.debug( "[SC] Zacalo sa prehravat: DBID: [%s], SCID: [%s] imdb: %s dur: %s est: %s fi: [%s] | %sx%s - title: %s (year: %s) showtitle: %s" % (str(self.itemDBID), str( self.scid), str(imdb), str(self.itemDuration), self.estimateFinishTime, _filename, str(season), str(episode), str(title), str(year), str(showtitle))) data = { 'scid': self.scid, 'action': 'start', 'ep': episode, 'se': season } util.debug("[SC] prehravanie %s" % str(res)) self.action(data) if 'item' in res and 'id' not in res['item']: util.debug("[SC] prehravanie mimo kniznice") except Exception: self.log("[SC] Chyba MyPlayer: %s" % str(traceback.format_exc())) pass try: if 'resume' in self.libItem: util.debug("[SC] resume! %s" % str(self.libItem)) pos = self.libItem['resume'].get('position', 0) maxPos = self.getTotalTime() * .75 if pos > 3 * 60 and pos < maxPos: self.seekTime(pos) except: pass
def ctx(self, item, data): menu = {} #util.debug("CTX ITM: %s" % str(item)) util.debug("CTX DAT: %s" % str(data)) #if 'dir' in data and data['dir'] == 'tvshows': if 'id' in data and data['id'].isdigit(): menu.update({"$30942": {"cmd": 'Action("Info")'}}) try: id = int(data['id']) #menu.update({"report stream": {"action": "report", "id": data['id'], "title": data['title']}}) except Exception: pass if 'trakt' in data and data['trakt'].isdigit( ) and trakt.getTraktCredentialsInfo() == True: #name, imdb, tvdb, content content = 'series' if 'season' in data and data['season'].isdigit( ) else 'movie' imdb = 'tt%07d' % int(data['imdb']) if 'imdb' in data else 0 tvdb = data['tvdb'] if 'tvdb' in data else 0 menu.update({ "Trakt menu": { "action": "traktManager", 'name': data['title'], 'imdb': imdb, 'tvdb': tvdb, 'content': content } }) if 'id' in data and data['id'].isdigit() and 'season' not in data: menu.update({ "$30918": { "action": "add-to-lib", "id": 'movies/%d' % int(data['id']), "title": data['title'] } }) if 'id' in data and data['id'] == 'series': menu.update({ "$30923": { "action": "add-to-lib-sub", "id": data['id'], "title": data['title'] } }) if 'id' in data and data['id'] == 'movies': menu.update({ "$30918": { "action": "add-to-lib", "id": data['id'], "title": data['title'] } }) menu.update({ "$30926": { "action": "add-to-lib", "id": data['id'], "title": data['title'], "force": "1" } }) #util.debug("[SC] MAME menu!") util.debug("[SC] data %s" % str(data)) if 'season' in data or data.get('id') == 'series': if data['id'] in self.subs.keys() and data['id'] != 'series': item['title'] = "[COLOR red]*[/COLOR] %s" % item['title'] #util.debug("[SC] Serial je v odoberani: %s" % data['title']) menu.update({ "$30924": { "action": "remove-from-sub", "id": data['id'], "title": data['title'] } }) else: #util.debug("[SC] Serial neodoberam: %s" % data['title']) menu.update({ "$30918": { "action": "add-to-lib", "id": data['id'], "title": data['title'] } }) menu.update({ "$30923": { "action": "add-to-lib-sub", "id": data['id'], "title": data['title'] } }) #menu.update({"$30922": {"cmd":'Addon.OpenSettings("%s")' % sctop.__scriptid__}}) #menu.update({"run Schedule": {"action": "subs"}}) #menu.update({"clean Schedule": {"action": "test"}}) #menu.update({"last": {'cp': 'czsklib', 'list': 'http://stream-cinema.online/json/movies-a-z'}}) item['menu'] = menu return item
def run_custom(self, params): util.debug("RUN CUSTOM: %s" % str(params)) if 'action' in params: util.debug("ACTION: %s" % str(params['action'])) action = params['action'] subs = False if action == 'remove-from-sub': subs = self.getSubs() if params['id'] in subs.keys(): del subs[params['id']] self.setSubs(subs) self.showNotification(params['title'], 'Removed from subscription') xbmc.executebuiltin('Container.Refresh') if action == 'add-to-lib-sub': subs = True action = 'add-to-lib' if action == 'add-to-lib': if params['id'] in ['movies', 'series' ] or 'movies' in params['id']: self.add_multi_item(params, subs) else: self.add_item(params, subs) if subs: xbmc.executebuiltin('Container.Refresh') if action == 'subs': self.evalSchedules() if action == 'rsubs': self.setSubs({}) if action == 'last': self.list( self.provider.items( self.provider._url("/Last/?%s" % urllib.urlencode( {'ids': json.dumps(self.getLast())})))) return xbmcplugin.endOfDirectory(int(sys.argv[1])) if action == 'traktManager': if trakt.getTraktCredentialsInfo() == True: trakt.manager(params['name'], params['imdb'], params['tvdb'], params['content']) return if action == 'traktWatchlist': if trakt.getTraktCredentialsInfo() == True: self.list( self.provider.items(data={'menu': trakt.getLists()})) else: self.list([]) return xbmcplugin.endOfDirectory(int(sys.argv[1])) if action == 'traktShowList': if trakt.getTraktCredentialsInfo() == True: util.debug("[SC] params: %s" % str(params)) ids = trakt.getList(params['id']) self.list( self.provider.items( self.provider._url( "/Search/?%s" % urllib.urlencode({'ids': json.dumps(ids)})))) return xbmcplugin.endOfDirectory(int(sys.argv[1])) if action == 'authTrakt': trakt.authTrakt() if action == 'speedtest': # 1:350 2:500 3:750 4:1000 5:1500 6:2000 7:2500 8:3000 9:3500 10:4000 g = sctop.getString x = [ g(30551), g(30552), g(30553), g(30554), g(30555), g(30556), g(30557), g(30558), g(30559), g(30560) ] ret = [1500, 2000] try: ret = sctop.dialog.multiselect(g(30501), x, preselect=[5, 6]) except: try: xret = sctop.dialog.select(g(30501), x) ret = [xret] except: pass _files = [ 0, 350, 500, 750, 1000, 1500, 2000, 2500, 3000, 3500, 4000 ] out = [] for i in ret: out.append(_files[i]) if len(out) < 1: out = [1500, 2000] from speedtest import speedTest, pretty_speed run = 2 pg = sctop.progressDialog pg.create(g(30050)) pg.update(0) wspeedtest = speedTest('speedtest.webshare.cz', run, out) pg.update(10, wspeedtest.host) wsdown = wspeedtest.download() pg.update(50) speedtest = speedTest(None, run, out) pg.update(60, speedtest.host) bedown = speedtest.download() pg.update(100) pg.close() sctop.dialog.ok( g(30050), "%s: %s" % (wspeedtest.host, str(pretty_speed(wsdown))), "%s: %s" % (speedtest.host, str(pretty_speed(bedown)))) sctop.openSettings('1.0') if action == 'trakt': movies = self.getTraktLastActivity( 'series') #trakt.getWatchedActivity() util.debug("[SC] movies: %s" % str(movies)) if action == 'test': data = myPlayer.MyPlayer.executeJSON({ 'jsonrpc': '2.0', 'id': 0, 'method': 'VideoLibrary.GetMovies', 'params': { 'properties': [ 'title', 'imdbnumber', 'year', 'playcount', 'lastplayed', 'file', 'dateadded', 'runtime', 'userrating' ] } }) util.debug("[SC] RPC: %s" % str(json.dumps(data))) elif 'cmd' in params: try: if '^;^' in params['cmd']: tmp = params['cmd'].split('^;^') else: tmp = [params['cmd']] for cmd in tmp: util.debug("[SC] RUN CMD: %s" % str(cmd)) xbmc.executebuiltin(cmd) except Exception: util.debug("[SC] ERROR: %s" % str(traceback.format_exc())) pass