def iStream_fix(show_id, showtitle, episode, season): # streams from iStream dont provide the showid and epid for above # they come through as tvshowid = -1, but it has episode no and season no and show name # need to insert work around here to get showid from showname, and get epid from season and episode no's # then need to ignore self.s['prevcheck'] redo = True count = 0 while redo and count < 2: # this ensures the section of code only runs twice at most redo = False count += 1 if show_id == -1 and showtitle and episode and season: raw_shows = T.json_query(show_request_all,True) if 'tvshows'in raw_shows: for x in raw_shows['tvshows']: if x['label'] == showtitle: show_id = x['tvshowid'] eps_query['params']['tvshowid'] = show_id tmp_eps = T.json_query(eps_query,True) if 'episodes' in tmp_eps: for y in tmp_eps['episodes']: if fix_SE(y['season']) == season and fix_SE(y['episode']) == episode: ep_id = y['episodeid'] # get odlist tmp_od = ast.literal_eval(WINDOW.getProperty("%s.%s.odlist" % ('LazyTV', show_npid))) if show_npid in randos: tmpoff = WINDOW.getProperty("%s.%s.offlist" % ('LazyTV', show_npid)) if tmp_off: tmp_od += ast.literal_eval(tmp_off) if ep_id not in tmp_od: Main.get_eps([show_npid]) redo = True return False, show_npid, ep_npid
def convert_pl_to_showlist(pop): # derive filtered_showids from smart playlist filename = os.path.split(pop)[1] clean_path = 'special://profile/playlists/video/' + filename #retrieve the shows in the supplied playlist, save their ids to a list plf['params']['directory'] = clean_path playlist_contents = T.json_query(Q.plf, True) if 'files' not in playlist_contents: gracefail('files not in playlist contents') else: if not playlist_contents['files']: gracefail('playlist contents empty') else: for x in playlist_contents['files']: filtered_showids = [ x['id'] for x in playlist_contents['files'] if x['type'] == 'tvshow' ] log(filtered_showids, 'showids in playlist') if not filtered_showids: gracefail('no tv shows in playlist') #returns the list of all and filtered shows and episodes return filtered_showids
def create_new_episode_list(self): ''' returns all the episodes for the TV show, including the episodeid, the season and episode numbers, the playcount, the resume point, and the file location ''' self.log(self.show_title, 'create_new_episode_list called: ') Q.eps_query['params']['tvshowid'] = self.showID raw_episodes = T.json_query(Q.eps_query) # this produces a list of lists with the sub-list being # [season * 1m + episode, epid, 'w' or 'u' based on playcount] if 'episodes' in raw_episodes: self.episode_list = [[ int(ep['season']) * 1000000 + int(ep['episode']), ep['episodeid'], int(ep[ 'season']), int(ep['episode']), 'w' if ep['playcount'] > 0 else 'u', ] for ep in raw_episodes.get('episodes',[])] # sorts the list from smallest season10k-episode to highest self.episode_list.sort() self.log(self.episode_list, 'create_new_episode_list result: ') return self.episode_list
def resume_partials(self, resume): ''' Jumps to a specific point in the episode. ''' log('Resume Partials Test; resume_partials: {}, self.playlist:: {}'. format(self.s['resume_partials'], self.playlist)) if self.s['resume_partials'] and self.playlist: position = resume.get('position', 0) total = resume.get('total', 0) if position: # call resume partials only if there is a resume point in the show seek_point = int((float(position) / float(total)) * 100) seek['params']['value'] = seek_point log('seeking to : {}'.format(seek_point)) T.json_query(seek, True)
def onPlayBackStarted(self): ''' checks if the show is an episode returns a dictionary of {allow_prev: x, showid: x, epid: x, duration: x} ''' #check if an episode is playing self.ep_details = T.json_query(Q.whats_playing) raw_details = self.ep_details.get('item','') self.log(raw_details, 'raw details') allow_prev = True if raw_details: video_type = raw_details.get('type','') if video_type in ['unknown','episode']: showid = int(raw_details.get('tvshowid', 'none')) epid = int(raw_details.get('id', 'none')) if showid != 'none' and epid != 'none': if not raw_details.get('episode',0): return else: showtitle = raw_details.get('showtitle','') episode_np = T.fix_SE(raw_details.get('episode')) season_np = T.fix_SE(raw_details.get('season')) duration = raw_details.get('runtime','') resume_details = raw_details.get('resume',{}) # allow_prev, show_npid, ep_id = iStream_fix(show_id, showtitle, episode, season) #FUNCTION: REPLACE ISTREAM FIX self.queue.put({'episode_is_playing': {'allow_prev': allow_prev, 'showid': showid, 'epid': epid, 'duration': duration, 'resume': resume_details}}) elif video_type == 'movie': # a movie might be playing in the random player, send the details to MAIN self.queue.put({'movie_is_playing': {'movieid': movieid}})
def retrieve_details(self): Q.ep_details_query['params']['episodeid'] = self.epid raw_ep_details = T.json_query(Q.ep_details_query) ep_details = raw_ep_details.get('episodedetails', False) if not ep_details: return if ep_details.get('resume',{}).get('position',0) and ep_details.get('resume',{}).get('total', 0): resume = "true" played = '%s%%'%int((float(ep_details['resume']['position']) / float(ep_details['resume']['total'])) * 100) else: resume = "false" played = '0%' season = "%.2d" % float(ep_details.get('season', 0)) episode = "%.2d" % float(ep_details.get('episode',0)) self.Episode = episode self.Season = season self.EpisodeNo = "s%se%s" % (season,episode) self.Resume = resume self.PercentPlayed = played self.Rating = str(round(float(ep_details.get('rating',0)),1)) self.Plot = ep_details.get('plot','') self.EpisodeID = self.epid self.Title = ep_details.get('title','') self.TVshowTitle = ep_details.get('showtitle','') self.OrderShowTitle = T.order_name(self.TVshowTitle) self.File = ep_details.get('file','') self.fanart = ep_details.get('art',{}).get('tvshow.fanart','') self.thumb = ep_details.get('art',{}).get('thumb','') self.poster = ep_details.get('art',{}).get('tvshow.poster','') self.banner = ep_details.get('art',{}).get('tvshow.banner','') self.clearlogo = ep_details.get('art',{}).get('tvshow.clearlogo','') self.clearart = ep_details.get('art',{}).get('tvshow.clearart','') self.landscape = ep_details.get('art',{}).get('tvshow.landscape','') self.characterart = ep_details.get('art',{}).get('tvshow.characterart','') self.Runtime = int((ep_details.get('runtime', 0) / 60) + 0.5) self.Premiered = ep_details.get('firstaired','')
def next_show_engine(showid, epid=[], eps=[], Season='null', Episode='null'): log('nextep_engine_start', showid) if showid in randos: newod = eps.remove(epid) if not eps: return 'null', ['null', 'null', 'null', 'null'] random.shuffle(newod) next_ep = newod[0] else: if not eps: return 'null', ['null', 'null', 'null', 'null'] try: next_ep = eps[1] except: return 'null', ['null', 'null', 'null', 'null'] newod = eps[1:] #get details of next_ep ep_details_query = { "jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodeDetails", "params": { "properties": ["season", "episode"], "episodeid": next_ep }, "id": "1" } epd = T.json_query(Q.ep_details_query, True) if 'episodedetails' in epd and epd['episodedetails']: return next_ep, [ epd['episodedetails']['season'], epd['episodedetails']['episode'], newod, next_ep ] else: return 'null', ['null', 'null', 'null', 'null'] log('nextep_engine_End', showid)
def playlist_selection_window(lang): ''' Purpose: launch Select Window populated with smart playlists ''' raw_playlist_files = T.json_query(Q.plf) playlist_files = raw_playlist_files.get('files',False) if playlist_files != None: plist_files = dict((x['label'],x['file']) for x in playlist_files) playlist_list = plist_files.keys() playlist_list.sort() inputchoice = xbmcgui.Dialog().select(lang(32104), playlist_list) return plist_files[playlist_list[inputchoice]] else: return 'empty'
def playlist_selection_window(lang): ''' Purpose: launch Select Window populated with smart playlists ''' raw_playlist_files = T.json_query(Q.plf) playlist_files = raw_playlist_files.get('files', False) if playlist_files != None: plist_files = dict((x['label'], x['file']) for x in playlist_files) playlist_list = plist_files.keys() playlist_list.sort() inputchoice = xbmcgui.Dialog().select(lang(32104), playlist_list) return plist_files[playlist_list[inputchoice]] else: return 'empty'
def create_next_episode_list(population): #creates a list of next episodes for all shows or a filtered subset and adds them to a playlist log('create_nextep_list') global stay_puft global play_now global refresh_now stored_data_filtered = process_stored(population) if excl_randos: stored_data_filtered = [ x for x in stored_data_filtered if x[1] not in randos ] log(refresh_now) log(stay_puft) while stay_puft and not xbmc.abortRequested: if refresh_now: log('refreshing now') refresh_now = False try: del list_window del window_returner stored_data_filtered = process_stored(population) if excl_randos: stored_data_filtered = [ x for x in stored_data_filtered if x[1] not in randos ] except: pass if skin == 1: xmlfile = "main.xml" elif skin == 2: xmlfile = "BigScreenList.xml" else: xmlfile = "DialogSelect.xml" list_window = yGUI(xmlfile, __scriptPath__, 'Default', data=stored_data_filtered) window_returner = myPlayer(parent=list_window) list_window.doModal() da_show = list_window.selected_show if da_show != 'null' and play_now: log('da_show not null, or play_now') play_now = False # this fix clears the playlist, adds the episode to the playlist, and then starts the playlist # it is needed because .strms will not start if using the executeJSONRPC method WINDOW.setProperty("%s.playlist_running" % ('LazyTV'), 'listview') T.json_query(Q.clear_playlist, False) try: for ep in da_show: add_this_ep['params']['item']['episodeid'] = int(ep) T.json_query(Q.add_this_ep, False) except: add_this_ep['params']['item']['episodeid'] = int(da_show) T.json_query(Q.add_this_ep, False) xbmc.sleep(50) window_returner.play(xbmc.PlayList(1)) xbmc.executebuiltin('ActivateWindow(12005)') da_show = 'null' WINDOW.setProperty("LazyTV.rando_shuffle", 'true') if not skin_return: stay_puft = False xbmc.sleep(500) del list_window del window_returner WINDOW.setProperty( "LazyTV.rando_shuffle", 'true') # notifies the service to re-randomise the randos
def random_playlist(population): global movies global movieweight #get the showids and such from the playlist stored_data_filtered = process_stored(population) log('random_playlist_started', reset=True) #clear the existing playlist T.json_query(Q.clear_playlist, False) added_ep_dict = {} count = 0 movie_list = [] if movies or moviesw: if movies and moviesw: mov = T.json_query(Q.get_moviesa, True) elif movies: mov = T.json_query(Q.get_movies, True) elif moviesw: mov = T.json_query(Q.get_moviesw, True) movies = True if 'movies' in mov and mov['movies']: movie_list = [x['movieid'] for x in mov['movies']] log('all movies = ' + str(movie_list)) if not movie_list: movies = False else: random.shuffle(movie_list) else: movies = False storecount = len(stored_data_filtered) moviecount = len(movie_list) if noshow: movieweight = 0.0 stored_data_filtered = [] if movieweight != 0.0: movieint = min(max(int(round(storecount * movieweight, 0)), 1), moviecount) else: movieint = moviecount if movies: movie_list = movie_list[:movieint] log('truncated movie list = ' + str(movie_list)) candidate_list = ['t' + str(x[1]) for x in stored_data_filtered ] + ['m' + str(x) for x in movie_list] random.shuffle(candidate_list) watch_partial_now = False if start_partials: if candidate_list: red_candy = [int(x[1:]) for x in candidate_list if x[0] == 't'] else: red_candy = [] lst = [] for showid in red_candy: if WINDOW.getProperty("%s.%s.Resume" % ('LazyTV', showid)) == 'true': temp_ep = WINDOW.getProperty("%s.%s.EpisodeID" % ('LazyTV', showid)) if temp_ep: lst.append({ "jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodeDetails", "params": { "properties": ["lastplayed", "tvshowid"], "episodeid": int(temp_ep) }, "id": "1" }) lwlist = [] if lst: xbmc_request = json.dumps(lst) result = xbmc.executeJSONRPC(xbmc_request) if result: reslist = ast.literal_eval(result) for res in reslist: if 'result' in res: if 'episodedetails' in res['result']: lwlist.append( (res['result']['episodedetails']['lastplayed'], res['result']['episodedetails']['tvshowid'])) lwlist.sort(reverse=True) if lwlist: log(lwlist, label="lwlist = ") R = candidate_list.index('t' + str(lwlist[0][1])) watch_partial_now = True log(R, label="R = ") while count < length and candidate_list: #while the list isnt filled, and all shows arent abandoned or movies added log('candidate list = ' + str(candidate_list)) multi = False if start_partials and watch_partial_now: watch_partial_now = False else: R = random.randint(0, len(candidate_list) - 1) #get random number log('R = ' + str(R)) curr_candi = candidate_list[R][1:] candi_type = candidate_list[R][:1] if candi_type == 't': log('tvadd attempt') if curr_candi in added_ep_dict.keys(): log(str(curr_candi) + ' in added_shows') if multipleshows: #check added_ep list if multiples allowed multi = True tmp_episode_id, tmp_details = next_show_engine( showid=curr_candi, epid=added_ep_dict[curr_candi][3], eps=added_ep_dict[curr_candi][2], Season=added_ep_dict[curr_candi][0], Episode=added_ep_dict[curr_candi][1]) if tmp_episode_id == 'null': tg = 't' + str(curr_candi) if tg in candidate_list: candidate_list.remove('t' + str(curr_candi)) log( str(curr_candi) + ' added to abandonded shows (no next show)') continue else: continue else: log(str(curr_candi) + ' not in added_showss') tmp_episode_id = int( WINDOW.getProperty("%s.%s.EpisodeID" % ('LazyTV', curr_candi))) if not multipleshows: #check added_ep list if multiples allowed, if not then abandon the show tg = 't' + str(curr_candi) if tg in candidate_list: candidate_list.remove('t' + str(curr_candi)) log( str(curr_candi) + ' added to abandonded shows (no multi)') if not premieres: if WINDOW.getProperty( "%s.%s.EpisodeNo" % ('LazyTV', curr_candi)) == 's01e01': #if desired, ignore s01e01 tg = 't' + str(curr_candi) if tg in candidate_list: candidate_list.remove('t' + str(curr_candi)) log( str(curr_candi) + ' added to abandonded shows (premieres)') continue #add episode to playlist if tmp_episode_id: add_this_ep['params']['item']['episodeid'] = int( tmp_episode_id) T.json_query(Q.add_this_ep, False) log('episode added = ' + str(tmp_episode_id)) else: tg = 't' + str(curr_candi) if tg in candidate_list: candidate_list.remove('t' + str(curr_candi)) continue #add episode to added episode dictionary if not multi: if multipleshows: if curr_candi in randos: eps_list = ast.literal_eval( WINDOW.getProperty( "%s.%s.odlist" % ('LazyTV', curr_candi))) + ast.literal_eval( WINDOW.getProperty("%s.%s.offlist" % ('LazyTV', curr_candi))) else: eps_list = ast.literal_eval( WINDOW.getProperty("%s.%s.odlist" % ('LazyTV', curr_candi))) added_ep_dict[curr_candi] = [ WINDOW.getProperty("%s.%s.Season" % ('LazyTV', curr_candi)), WINDOW.getProperty("%s.%s.Episode" % ('LazyTV', curr_candi)), eps_list, WINDOW.getProperty("%s.%s.EpisodeID" % ('LazyTV', curr_candi)) ] else: added_ep_dict[curr_candi] = '' else: added_ep_dict[curr_candi] = [ tmp_details[0], tmp_details[1], tmp_details[2], tmp_details[3] ] elif candi_type == 'm': #add movie to playlist log('movieadd') add_this_movie['params']['item']['movieid'] = int(curr_candi) T.json_query(Q.add_this_movie, False) candidate_list.remove('m' + str(curr_candi)) else: count = 99999 count += 1 WINDOW.setProperty( "%s.playlist_running" % ('LazyTV'), 'true') # notifies the service that a playlist is running WINDOW.setProperty( "LazyTV.rando_shuffle", 'true') # notifies the service to re-randomise the randos xbmc.Player().play(xbmc.PlayList(1)) #xbmc.executebuiltin('ActivateWindow(MyVideoPlaylist)') log('random_playlist_End')