Beispiel #1
0
    def notification_time(self, total_time=None):
        # Alway use metadata, when available
        if self.data.get('notification_time'):
            self.offset_used = True
            return int(self.data.get('notification_time'))

        # Some consumers send the offset when the credits start (e.g. Netflix)
        if total_time and self.data.get('notification_offset'):
            self.offset_used = True
            return total_time - int(self.data.get('notification_offset'))

        # Use a customized notification time, when configured
        if total_time and get_setting_bool('customAutoPlayTime'):
            if total_time > 60 * 60:
                return get_setting_int('autoPlayTimeXL')
            if total_time > 40 * 60:
                return get_setting_int('autoPlayTimeL')
            if total_time > 20 * 60:
                return get_setting_int('autoPlayTimeM')
            if total_time > 10 * 60:
                return get_setting_int('autoPlayTimeS')
            return get_setting_int('autoPlayTimeXS')

        # Use one global default, regardless of episode length
        return get_setting_int('autoPlaySeasonTime')
Beispiel #2
0
    def onInit(self):  # pylint: disable=invalid-name
        self.set_info()
        self.prepare_progress_control()

        if get_setting_bool('stopAfterClose'):
            self.getControl(3013).setLabel(localize(30033))  # Stop
        else:
            self.getControl(3013).setLabel(localize(30034))  # Close
Beispiel #3
0
 def onClick(self, controlId):  # pylint: disable=invalid-name
     if controlId == 3012:  # Watch now
         self.set_watch_now(True)
         self.close()
     elif controlId == 3013:  # Close / Stop
         self.set_cancel(True)
         if get_setting_bool('stopAfterClose'):
             Player().stop()
         self.close()
Beispiel #4
0
 def __init__(self):
     self.__dict__ = self._shared_state
     self.play_mode = get_setting_int('autoPlayMode')
     self.include_watched = get_setting_bool('includeWatched')
     self.current_tv_show_id = None
     self.current_episode_id = None
     self.tv_show_id = None
     self.played_in_a_row = 1
     self.last_file = None
     self.track = False
     self.pause = False
 def handle_demo(self):
     if get_setting_bool('enableDemoMode'):
         self.log(
             'Up Next DEMO mode enabled, skipping automatically to the end',
             0)
         self.demo.show()
         try:
             total_time = self.player.getTotalTime()
             self.player.seekTime(total_time - 15)
         except RuntimeError as exc:
             self.log('Failed to seekTime(): %s' % exc, 0)
     else:
         self.demo.hide()
 def launch_up_next(self):
     playlist_item = get_setting_bool('enablePlaylist')
     episode = self.play_item.get_next()
     self.log('Playlist setting: %s' % playlist_item)
     if episode and not playlist_item:
         self.log('Playlist integration disabled', 2)
         return
     if not episode:
         playlist_item = False
         episode = self.play_item.get_episode()
         if episode is None:
             # No episode get out of here
             self.log(
                 'Error: no episode could be found to play next...exiting',
                 1)
             return
     self.log('episode details %s' % episode, 2)
     self.launch_popup(episode, playlist_item)
     self.api.reset_addon_data()
    def launch_up_next(self):
        enable_playlist = get_setting_bool('enablePlaylist')
        episode, source = self.play_item.get_next()
        self.log('Playlist setting: %s' % enable_playlist)
        if source == 'playlist' and not enable_playlist:
            self.log('Playlist integration disabled', 2)
            return
        if not episode:
            # No episode get out of here
            self.log('Error: no episode could be found to play next...exiting',
                     1)
            return
        self.log('episode details %s' % episode, 2)
        play_next, keep_playing = self.launch_popup(episode, source)
        self.state.playing_next = play_next

        # Dequeue and stop playback if not playing next file
        if not play_next and self.state.queued:
            self.state.queued = self.api.dequeue_next_item()
        if not keep_playing:
            self.log('Stopping playback', 2)
            self.player.stop()

        self.api.reset_addon_data()
    def launch_popup(self, episode, source=None):
        episode_id = episode.get('episodeid')
        no_play_count = episode.get('playcount') is None or episode.get(
            'playcount') == 0
        include_play_count = True if self.state.include_watched else no_play_count
        if not include_play_count or self.state.current_episode_id == episode_id:
            # play_next = False
            # keep_playing = True
            # return play_next, keep_playing
            # Don't play next file, but keep playing current file
            return False, True

        # Add next file to playlist if existing playlist is not being used
        if source != 'playlist':
            self.state.queued = self.api.queue_next_item(episode)

        # We have a next up episode choose mode
        if get_setting_int('simpleMode') == 0:
            next_up_page = UpNext('script-upnext-upnext-simple.xml',
                                  addon_path(), 'default', '1080i')
            still_watching_page = StillWatching(
                'script-upnext-stillwatching-simple.xml', addon_path(),
                'default', '1080i')
        else:
            next_up_page = UpNext('script-upnext-upnext.xml', addon_path(),
                                  'default', '1080i')
            still_watching_page = StillWatching(
                'script-upnext-stillwatching.xml', addon_path(), 'default',
                '1080i')

        showing_next_up_page, showing_still_watching_page = self.show_popup_and_wait(
            episode, next_up_page, still_watching_page)
        should_play_default, should_play_non_default = self.extract_play_info(
            next_up_page, showing_next_up_page, showing_still_watching_page,
            still_watching_page)
        if not self.state.track:
            self.log('exit launch_popup early due to disabled tracking', 2)
            # play_next = False
            # keep_playing = showing_next_up_page
            # return play_next, keep_playing
            # Don't play next file
            # Stop if Still Watching? popup was shown to prevent unwanted playback when using FF or skip
            return False, showing_next_up_page

        play_item_option_1 = (should_play_default
                              and self.state.play_mode == 0)
        play_item_option_2 = (should_play_non_default
                              and self.state.play_mode == 1)
        if not play_item_option_1 and not play_item_option_2:
            # play_next = False
            # keep_playing = next_up_page.is_cancel() if showing_next_up_page else still_watching_page.is_cancel()
            # keep_playing = keep_playing and not get_setting_bool('stopAfterClose')
            # return play_next, keep_playing
            # Don't play next file, and stop current file if no playback option selected
            return False, ((next_up_page.is_cancel() if showing_next_up_page
                            else still_watching_page.is_cancel())
                           and not get_setting_bool('stopAfterClose'))

        self.log('playing media episode', 2)
        # Signal to trakt previous episode watched
        event(message='NEXTUPWATCHEDSIGNAL',
              data=dict(episodeid=self.state.current_episode_id),
              encoding='base64')
        if source == 'playlist' or self.state.queued:
            # Play playlist media
            if should_play_non_default:
                # Only start the next episode if the user asked for it specifically
                self.player.playnext()
        elif self.api.has_addon_data():
            # Play add-on media
            self.api.play_addon_item()
        else:
            # Play local media
            self.api.play_kodi_item(episode)

        # play_next = True
        # keep_playing = True
        # return play_next, keep_playing
        # Play next file, and keep playing current file
        return True, True
Beispiel #9
0
    def run(self):
        """Main service loop"""
        self.log('Service started', 0)

        while not self.abortRequested():
            # check every 1 sec
            if self.waitForAbort(1):
                # Abort was requested while waiting. We should exit
                break

            if not self.player.is_tracking():
                continue

            if bool(get_property('PseudoTVRunning') == 'True'):
                self.player.disable_tracking()
                self.playback_manager.demo.hide()
                continue

            if get_setting_bool('disableNextUp'):
                # Next Up is disabled
                self.player.disable_tracking()
                self.playback_manager.demo.hide()
                continue

            # Method isExternalPlayer() was added in Kodi v18 onward
            if kodi_version_major() >= 18 and self.player.isExternalPlayer():
                self.log('Up Next tracking stopped, external player detected',
                         2)
                self.player.disable_tracking()
                self.playback_manager.demo.hide()
                continue

            last_file = self.player.get_last_file()
            try:
                current_file = self.player.getPlayingFile()
            except RuntimeError:
                self.log(
                    'Up Next tracking stopped, failed player.getPlayingFile()',
                    2)
                self.player.disable_tracking()
                self.playback_manager.demo.hide()
                continue

            if last_file and last_file == from_unicode(current_file):
                # Already processed this playback before
                continue

            try:
                total_time = self.player.getTotalTime()
            except RuntimeError:
                self.log(
                    'Up Next tracking stopped, failed player.getTotalTime()',
                    2)
                self.player.disable_tracking()
                self.playback_manager.demo.hide()
                continue

            if total_time == 0:
                self.log('Up Next tracking stopped, no file is playing', 2)
                self.player.disable_tracking()
                self.playback_manager.demo.hide()
                continue

            try:
                play_time = self.player.getTime()
            except RuntimeError:
                self.log('Up Next tracking stopped, failed player.getTime()',
                         2)
                self.player.disable_tracking()
                self.playback_manager.demo.hide()
                continue

            notification_time = self.api.notification_time(
                total_time=total_time)
            if total_time - play_time > notification_time:
                # Media hasn't reach notification time yet, waiting a bit longer...
                continue

            self.player.set_last_file(from_unicode(current_file))
            self.log(
                'Show notification as episode (of length %d secs) ends in %d secs'
                % (total_time, notification_time), 2)
            self.playback_manager.launch_up_next()
            self.log('Up Next style autoplay succeeded', 2)
            self.player.disable_tracking()

        self.log('Service stopped', 0)