def launch_popup(self, episode, playlist_item):
        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:
            return

        if not playlist_item:
            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)
            return
        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:
            return

        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 playlist_item or self.state.queued:
            try:
                # Play playlist media, only seek/skip if media has not already played through
                if should_play_non_default:
                    self.player.seekTime(self.player.getTotalTime())
                    self.player.playnext()
            except RuntimeError:
                pass
        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)
Exemplo n.º 2
0
    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