def __init__(self): self.__dict__ = self._shared_state self.playMode = utils.settings("autoPlayMode") self.short_play_mode = utils.settings("shortPlayMode") self.short_play_notification = utils.settings("shortPlayNotification") self.short_play_length = int(utils.settings("shortPlayLength")) * 60 self.include_watched = utils.settings("includeWatched") == "true" self.current_tv_show_id = None self.current_episode_id = None self.tv_show_id = None self.played_in_a_row = 1
def developer_play_back(): episode = utils.load_test_data() next_up_page, next_up_page_simple, still_watching_page, still_watching_page_simple = ( pages.set_up_developer_pages(episode)) if utils.settings("windowMode") == "0": next_up_page.show() elif utils.settings("windowMode") == "1": next_up_page_simple.show() elif utils.settings("windowMode") == "2": still_watching_page.show() elif utils.settings("windowMode") == "3": still_watching_page_simple.show() utils.window('service.upnext.dialog', 'true') player = xbmc.Player() while (player.isPlaying() and not next_up_page.isCancel() and not next_up_page.isWatchNow() and not still_watching_page.isStillWatching() and not still_watching_page.isCancel()): xbmc.sleep(100) next_up_page.updateProgressControl() next_up_page_simple.updateProgressControl() still_watching_page.updateProgressControl() still_watching_page_simple.updateProgressControl() if utils.settings("windowMode") == "0": next_up_page.close() elif utils.settings("windowMode") == "1": next_up_page_simple.close() elif utils.settings("windowMode") == "2": still_watching_page.close() elif utils.settings("windowMode") == "3": still_watching_page_simple.close() utils.window('service.upnext.dialog', clear=True)
def run(self): while not self.abortRequested(): # check every 1 sec if self.waitForAbort(1): # Abort was requested while waiting. We should exit break if self.player.is_tracking(): try: play_time = self.player.getTime() total_time = self.player.getTotalTime() last_file = self.player.get_last_file() current_file = self.player.getPlayingFile() notification_time = self.api.notification_time() up_next_disabled = utils.settings("disableNextUp") == "true" if utils.window("PseudoTVRunning") != "True" and not up_next_disabled and total_time > 300: if (total_time - play_time <= int(notification_time) and ( last_file is None or last_file != current_file)) and total_time != 0: self.player.set_last_file(current_file) self.log("Calling autoplayback totaltime - playtime is %s" % (total_time - play_time), 2) self.playback_manager.launch_up_next() self.log("Up Next style autoplay succeeded.", 2) self.player.disable_tracking() except Exception as e: self.log("Exception in Playback Monitor Service: %s" % repr(e)) self.log("======== STOP %s ========" % utils.addon_name(), 0)
def run(self): last_file = None while not self.abortRequested(): # check every 1 sec if self.waitForAbort(1): # Abort was requested while waiting. We should exit break if self.player.isPlaying(): try: play_time = self.player.getTime() total_time = self.player.getTotalTime() current_file = self.player.getPlayingFile() notification_time = self.api.notification_time() up_next_disabled = utils.settings( "disableNextUp") == "true" if utils.window( "PseudoTVRunning" ) != "True" and not up_next_disabled and total_time > 300: if (total_time - play_time <= int(notification_time) and (last_file is None or last_file != current_file)) and total_time != 0: last_file = current_file self.log( "Calling autoplayback totaltime - playtime is %s" % (total_time - play_time), 2) self.playback_manager.launch_up_next() self.log("Up Next style autoplay succeeded.", 2) except Exception as e: self.log("Exception in Playback Monitor Service: %s" % repr(e)) self.log("======== STOP %s ========" % utils.addon_name(), 0)
def onPlayBackStarted(self): # Will be called when kodi starts playing a file xbmc.sleep(5000) # Delay for slower devices, should really use onAVStarted for Leia if not xbmc.getCondVisibility("videoplayer.content(episodes)"): return self.state.track = True if utils.settings("developerMode") == "true": self.developer.developer_play_back()
def show_popup_and_wait(self, episode, next_up_page, still_watching_page): play_time = self.player.getTime() total_time = self.player.getTotalTime() progress_step_size = utils.calculate_progress_steps(total_time - play_time) next_up_page.setItem(episode) next_up_page.setProgressStepSize(progress_step_size) still_watching_page.setItem(episode) still_watching_page.setProgressStepSize(progress_step_size) played_in_a_row_number = utils.settings("playedInARow") self.log( "played in a row settings %s" % json.dumps(played_in_a_row_number), 2) self.log("played in a row %s" % json.dumps(self.state.played_in_a_row), 2) showing_next_up_page = False showing_still_watching_page = False hide_for_short_videos = ( self.state.short_play_notification == "false") and (self.state.short_play_length >= total_time) and ( self.state.short_play_mode == "true") if int(self.state.played_in_a_row) <= int( played_in_a_row_number) and not hide_for_short_videos: self.log( "showing next up page as played in a row is %s" % json.dumps(self.state.played_in_a_row), 2) next_up_page.show() utils.window('service.upnext.dialog', 'true') showing_next_up_page = True elif not hide_for_short_videos: self.log( "showing still watching page as played in a row %s" % json.dumps(self.state.played_in_a_row), 2) still_watching_page.show() utils.window('service.upnext.dialog', 'true') showing_still_watching_page = True while (self.player.isPlaying() and (total_time - play_time > 1) and not next_up_page.isCancel() and not next_up_page.isWatchNow() and not still_watching_page.isStillWatching() and not still_watching_page.isCancel()): xbmc.sleep(100) try: play_time = self.player.getTime() total_time = self.player.getTotalTime() if showing_next_up_page: next_up_page.updateProgressControl() elif showing_still_watching_page: still_watching_page.updateProgressControl() except Exception as e: self.log("error show_popup_and_wait %s" % repr(e), 1) pass return showing_next_up_page, showing_still_watching_page, total_time
def set_up_pages(): if utils.settings("simpleMode") == "0": next_up_page = UpNext("script-upnext-upnext-simple.xml", utils.addon_path(), "default", "1080i") still_watching_page = StillWatching( "script-upnext-stillwatching-simple.xml", utils.addon_path(), "default", "1080i") else: next_up_page = UpNext("script-upnext-upnext.xml", utils.addon_path(), "default", "1080i") still_watching_page = StillWatching("script-upnext-stillwatching.xml", utils.addon_path(), "default", "1080i") return next_up_page, still_watching_page
def set_up_pages(): if utils.settings("simpleMode") == "0": next_up_page = UpNext("script-upnext-upnext-simple.xml", utils.addon_path(), "default", "1080i") still_watching_page = StillWatching( "script-upnext-stillwatching-simple.xml", utils.addon_path(), "default", "1080i") else: next_up_page = UpNext("script-upnext-upnext.xml", utils.addon_path(), "default", "1080i") still_watching_page = StillWatching( "script-upnext-stillwatching.xml", utils.addon_path(), "default", "1080i") return next_up_page, still_watching_page
def show_popup_and_wait(self, episode, next_up_page, still_watching_page): play_time = self.player.getTime() total_time = self.player.getTotalTime() progress_step_size = utils.calculate_progress_steps(total_time - play_time) episode_runtime = episode.get("runtime") is not None next_up_page.setItem(episode) next_up_page.setProgressStepSize(progress_step_size) still_watching_page.setItem(episode) still_watching_page.setProgressStepSize(progress_step_size) played_in_a_row_number = utils.settings("playedInARow") self.log("played in a row settings %s" % json.dumps(played_in_a_row_number), 2) self.log("played in a row %s" % json.dumps(self.state.played_in_a_row), 2) showing_next_up_page = False showing_still_watching_page = False hide_for_short_videos = (self.state.short_play_notification == "false") and ( self.state.short_play_length >= total_time) and ( self.state.short_play_mode == "true") if int(self.state.played_in_a_row) <= int(played_in_a_row_number) and not hide_for_short_videos: self.log( "showing next up page as played in a row is %s" % json.dumps(self.state.played_in_a_row), 2) next_up_page.show() utils.window('service.upnext.dialog', 'true') showing_next_up_page = True elif not hide_for_short_videos: self.log( "showing still watching page as played in a row %s" % json.dumps(self.state.played_in_a_row), 2) still_watching_page.show() utils.window('service.upnext.dialog', 'true') showing_still_watching_page = True while (self.player.isPlaying() and ( total_time - play_time > 1) and not next_up_page.isCancel() and not next_up_page.isWatchNow() and not still_watching_page.isStillWatching() and not still_watching_page.isCancel()): xbmc.sleep(100) try: play_time = self.player.getTime() total_time = self.player.getTotalTime() if episode_runtime: end_time = total_time - play_time + episode["runtime"] end_time = datetime.now() + timedelta(seconds=end_time) end_time = end_time.strftime("%I:%M %p" if self.clock_twelve else "%H:%M").lstrip("0") # remove leading zero on all platforms else: end_time = None if not self.state.pause: if showing_next_up_page: next_up_page.updateProgressControl(end_time) elif showing_still_watching_page: still_watching_page.updateProgressControl(end_time) except Exception as e: self.log("error show_popup_and_wait %s" % repr(e), 1) return showing_next_up_page, showing_still_watching_page, total_time
def onClick(self, control_id): if control_id == 3012: # watch now self.setWatchNow(True) self.close() elif control_id == 3013: # cancel self.setCancel(True) if utils.settings("stopAfterClose") == "true": xbmc.Player().stop() self.close() pass
def show_popup_and_wait(self, episode, next_up_page, still_watching_page): play_time = self.player.getTime() total_time = self.player.getTotalTime() progress_step_size = utils.calculate_progress_steps(total_time - play_time) next_up_page.setItem(episode) next_up_page.setProgressStepSize(progress_step_size) still_watching_page.setItem(episode) still_watching_page.setProgressStepSize(progress_step_size) played_in_a_row_number = utils.settings("playedInARow") self.log("played in a row settings %s" % json.dumps(played_in_a_row_number), 2) self.log("played in a row %s" % json.dumps(self.state.played_in_a_row), 2) showing_next_up_page = False showing_still_watching_page = False hide_for_short_videos = (self.state.short_play_notification == "false") and ( self.state.short_play_length >= total_time) and ( self.state.short_play_mode == "true") if int(self.state.played_in_a_row) <= int(played_in_a_row_number) and not hide_for_short_videos: self.log( "showing next up page as played in a row is %s" % json.dumps(self.state.played_in_a_row), 2) next_up_page.show() utils.window('service.upnext.dialog', 'true') showing_next_up_page = True elif not hide_for_short_videos: self.log( "showing still watching page as played in a row %s" % json.dumps(self.state.played_in_a_row), 2) still_watching_page.show() utils.window('service.upnext.dialog', 'true') showing_still_watching_page = True while (self.player.isPlaying() and ( total_time - play_time > 1) and not next_up_page.isCancel() and not next_up_page.isWatchNow() and not still_watching_page.isStillWatching() and not still_watching_page.isCancel()): xbmc.sleep(100) try: play_time = self.player.getTime() total_time = self.player.getTotalTime() if showing_next_up_page: next_up_page.updateProgressControl() elif showing_still_watching_page: still_watching_page.updateProgressControl() except Exception as e: self.log("error show_popup_and_wait %s" % repr(e), 1) pass return showing_next_up_page, showing_still_watching_page, total_time
def developerPlayPlayback(self): episode = self.loadTestData() nextUpPageSimple = UpNext("script-upnext-upnext-simple.xml", utils.addon_path(), "default", "1080i") stillWatchingPageSimple = StillWatching( "script-upnext-stillwatching-simple.xml", utils.addon_path(), "default", "1080i") nextUpPage = UpNext("script-upnext-upnext.xml", utils.addon_path(), "default", "1080i") stillWatchingPage = StillWatching("script-upnext-stillwatching.xml", utils.addon_path(), "default", "1080i") nextUpPage.setItem(episode) nextUpPageSimple.setItem(episode) stillWatchingPage.setItem(episode) stillWatchingPageSimple.setItem(episode) if utils.settings("windowMode") == "0": nextUpPage.show() elif utils.settings("windowMode") == "1": nextUpPageSimple.show() elif utils.settings("windowMode") == "2": stillWatchingPage.show() elif utils.settings("windowMode") == "3": stillWatchingPageSimple.show() while xbmc.Player().isPlaying( ) and not nextUpPage.isCancel() and not nextUpPage.isWatchNow( ) and not stillWatchingPage.isStillWatching( ) and not stillWatchingPage.isCancel(): xbmc.sleep(100) if utils.settings("windowMode") == "0": nextUpPage.close() elif utils.settings("windowMode") == "1": nextUpPageSimple.close() elif utils.settings("windowMode") == "2": stillWatchingPage.close() elif utils.settings("windowMode") == "3": stillWatchingPageSimple.close()
def set_up_developer_pages(episode): next_up_page_simple = UpNext("script-upnext-upnext-simple.xml", utils.addon_path(), "default", "1080i") still_watching_page_simple = StillWatching( "script-upnext-stillwatching-simple.xml", utils.addon_path(), "default", "1080i") next_up_page = UpNext("script-upnext-upnext.xml", utils.addon_path(), "default", "1080i") still_watching_page = StillWatching("script-upnext-stillwatching.xml", utils.addon_path(), "default", "1080i") next_up_page.setItem(episode) next_up_page_simple.setItem(episode) still_watching_page.setItem(episode) still_watching_page_simple.setItem(episode) notification_time = utils.settings("autoPlaySeasonTime") progress_step_size = utils.calculate_progress_steps(notification_time) next_up_page.setProgressStepSize(progress_step_size) next_up_page_simple.setProgressStepSize(progress_step_size) still_watching_page.setProgressStepSize(progress_step_size) still_watching_page_simple.setProgressStepSize(progress_step_size) return next_up_page, next_up_page_simple, still_watching_page, still_watching_page_simple
def run(self): while not self.abortRequested(): # check every 1 sec if self.waitForAbort(1): # Abort was requested while waiting. We should exit break if self.player.is_tracking(): try: play_time = self.player.getTime() total_time = self.player.getTotalTime() last_file = self.player.get_last_file() current_file = self.player.getPlayingFile() notification_time = self.api.notification_time() up_next_disabled = utils.settings( "disableNextUp") == "true" if utils.window("PseudoTVRunning" ) != "True" and not up_next_disabled: if (total_time - play_time <= int(notification_time) and (last_file is None or last_file != current_file)) and total_time != 0: self.player.set_last_file(current_file) self.log( "Calling autoplayback totaltime - playtime is %s" % (total_time - play_time), 2) self.playback_manager.launch_up_next() self.log("Up Next style autoplay succeeded.", 2) self.player.disable_tracking() except Exception as e: self.log("Exception in Playback Monitor Service: %s" % repr(e)) if 'not playing any media file' in str(e): self.log("No file is playing - stop up next tracking.", 2) self.player.disable_tracking() self.log("======== STOP service.upnext ========", 0)
def set_up_developer_pages(episode): next_up_page_simple = UpNext("script-upnext-upnext-simple.xml", utils.addon_path(), "default", "1080i") still_watching_page_simple = StillWatching( "script-upnext-stillwatching-simple.xml", utils.addon_path(), "default", "1080i") next_up_page = UpNext("script-upnext-upnext.xml", utils.addon_path(), "default", "1080i") still_watching_page = StillWatching( "script-upnext-stillwatching.xml", utils.addon_path(), "default", "1080i") next_up_page.setItem(episode) next_up_page_simple.setItem(episode) still_watching_page.setItem(episode) still_watching_page_simple.setItem(episode) notification_time = utils.settings("autoPlaySeasonTime") progress_step_size = utils.calculate_progress_steps(notification_time) next_up_page.setProgressStepSize(progress_step_size) next_up_page_simple.setProgressStepSize(progress_step_size) still_watching_page.setProgressStepSize(progress_step_size) still_watching_page_simple.setProgressStepSize(progress_step_size) return next_up_page, next_up_page_simple, still_watching_page, still_watching_page_simple
def onPlayBackStarted(self): # Will be called when kodi starts playing a file self.track = True if utils.settings("developerMode") == "true": self.developer.developer_play_back()
def setupFromSettings(self): self.playMode = utils.settings("autoPlayMode") self.shortplayMode = utils.settings("shortPlayMode") self.shortplayNotification = utils.settings("shortPlayNotification") self.shortplayLength = int(utils.settings("shortPlayLength")) * 60 self.includeWatched = utils.settings("includeWatched") == "true"
def autoPlayPlayback(self): currentFile = xbmc.Player().getPlayingFile() if not self.addon_data: # Get the active player result = self.getNowPlaying() if not self.handle_now_playing_result(result): self.logMsg( "Error: no result returned from check on now playing...exiting", 1) return # get the next episode from kodi episode = self.handle_kodi_lookup_of_episode( self.tvshowid, currentFile, self.includeWatched) else: episode = self.handle_addon_lookup_of_next_episode() current_episode = self.handle_addon_lookup_of_current_episode() self.currentepisodeid = current_episode["episodeid"] if self.currenttvshowid != current_episode["tvshowid"]: self.currenttvshowid = current_episode["tvshowid"] self.playedinarow = 1 if episode is None: # no episode get out of here self.logMsg( "Error: no episode could be found to play next...exiting", 1) return self.logMsg("episode details %s" % str(episode), 2) episodeid = episode["episodeid"] includePlaycount = True if self.includeWatched else episode[ "playcount"] == 0 if includePlaycount and self.currentepisodeid != episodeid: # we have a next up episode choose mode if utils.settings("simpleMode") == "0": nextUpPage = UpNext("script-upnext-upnext-simple.xml", utils.addon_path(), "default", "1080i") stillWatchingPage = StillWatching( "script-upnext-stillwatching-simple.xml", utils.addon_path(), "default", "1080i") else: nextUpPage = UpNext("script-upnext-upnext.xml", utils.addon_path(), "default", "1080i") stillWatchingPage = StillWatching( "script-upnext-stillwatching.xml", utils.addon_path(), "default", "1080i") nextUpPage.setItem(episode) stillWatchingPage.setItem(episode) playedinarownumber = utils.settings("playedInARow") playTime = xbmc.Player().getTime() totalTime = xbmc.Player().getTotalTime() self.logMsg( "played in a row settings %s" % str(playedinarownumber), 2) self.logMsg("played in a row %s" % str(self.playedinarow), 2) if int(self.playedinarow) <= int(playedinarownumber): self.logMsg( "showing next up page as played in a row is %s" % str(self.playedinarow), 2) if (self.shortplayNotification == "false") and (self.shortplayLength >= totalTime ) and (self.shortplayMode == "true"): self.logMsg("hiding notification for short videos") else: nextUpPage.show() else: self.logMsg( "showing still watching page as played in a row %s" % str(self.playedinarow), 2) if (self.shortplayNotification == "false") and (self.shortplayLength >= totalTime ) and (self.shortplayMode == "true"): self.logMsg("hiding notification for short videos") else: stillWatchingPage.show() while xbmc.Player().isPlaying() and ( totalTime - playTime > 1 ) and not nextUpPage.isCancel() and not nextUpPage.isWatchNow( ) and not stillWatchingPage.isStillWatching( ) and not stillWatchingPage.isCancel(): xbmc.sleep(100) try: playTime = xbmc.Player().getTime() totalTime = xbmc.Player().getTotalTime() except: pass if self.shortplayLength >= totalTime and self.shortplayMode == "true": #play short video and don't add to playcount self.playedinarow += 0 self.logMsg("Continuing short video autoplay - %s") if nextUpPage.isWatchNow( ) or stillWatchingPage.isStillWatching(): self.playedinarow = 1 shouldPlayDefault = not nextUpPage.isCancel() else: if int(self.playedinarow) <= int(playedinarownumber): nextUpPage.close() shouldPlayDefault = not nextUpPage.isCancel() shouldPlayNonDefault = nextUpPage.isWatchNow() else: stillWatchingPage.close() shouldPlayDefault = stillWatchingPage.isStillWatching() shouldPlayNonDefault = stillWatchingPage.isStillWatching() if nextUpPage.isWatchNow( ) or stillWatchingPage.isStillWatching(): self.playedinarow = 1 else: self.playedinarow += 1 if (shouldPlayDefault and self.playMode == "0") or (shouldPlayNonDefault and self.playMode == "1"): self.logMsg("playing media episode id %s" % str(episodeid), 2) # Signal to trakt previous episode watched utils.event("NEXTUPWATCHEDSIGNAL", {'episodeid': self.currentepisodeid}) # Play media if not self.addon_data: xbmc.executeJSONRPC( '{ "jsonrpc": "2.0", "id": 0, "method": "Player.Open", ' '"params": { "item": {"episodeid": ' + str(episode["episodeid"]) + '} } }') else: self.logMsg( "sending data to addon to play: %s " % str(self.addon_data['play_info']), 2) utils.event(self.addon_data['id'], self.addon_data['play_info'], "upnextprovider")
def notification_time(self): return self.data.get('notification_time') or utils.settings('autoPlaySeasonTime')
def onPlayBackStarted(self): # Will be called when kodi starts playing a file self.addon_data = {} if utils.settings("developerMode") == "true": self.developerPlayPlayback()
def onPlayBackStarted(self): # Will be called when kodi starts playing a file xbmc.sleep(5000) # Delay for slower devices, should really use onAVStarted for Leia self.state.track = True if utils.settings("developerMode") == "true": self.developer.developer_play_back()
def onPlayBackStarted(self): # Will be called when kodi starts playing a file self.track = True if utils.settings("developerMode") == "true": self.developer.developer_play_back()
def onPlayBackStarted(self): # Will be called when kodi starts playing a file self.api.reset_addon_data() if utils.settings("developerMode") == "true": self.developer.developer_play_back()