Exemple #1
0
class Monitor(xbmc.Monitor):
    def __init__(self):
        self.player = Player()
        self.api = Api()
        self.playback_manager = PlaybackManager()
        xbmc.Monitor.__init__(self)

    def log(self, msg, lvl=1):
        class_name = self.__class__.__name__
        utils.log("%s %s" % (utils.addon_name(), class_name), str(msg),
                  int(lvl))

    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 onNotification(self, sender, method, data):

        if method.split('.')[1].lower(
        ) != 'upnext_data':  # method looks like Other.upnext_data
            return

        data = utils.decode_data(data)
        data['id'] = "%s_play_action" % str(sender.replace(".SIGNAL", ""))

        self.api.addon_data_received(data)
Exemple #2
0
def play(item_id):
    item = plugin.get_window_property(item_id) or plugin.items.instantiate(item_id=item_id)
    si = plugin.kwargs.get("season_index")
    i = plugin.kwargs.get("index")
    playable_li = plugin.items.get_playable(item, season_index=si, index=i).playable_list_item
    player = Player(list_item=playable_li)
    xbmcplugin.setResolvedUrl(plugin.handle, True, playable_li)
    while player.is_playing:
        player.set_marktime()
        xbmc.sleep(1000)
 def set_defaultplayer(self):
     player = Player()
     tmdbtype = self.params.get('set_defaultplayer')
     setting = 'default_player_episodes' if tmdbtype == 'tv' else 'default_player_{0}s'.format(tmdbtype)
     player.setup_players(tmdbtype=tmdbtype, clearsetting=True, assertplayers=False)
     idx = xbmcgui.Dialog().select(
         'Choose Default Player for {0}'.format(utils.type_convert(tmdbtype, 'plural')), player.itemlist)
     if idx == 0:
         self.addon.setSettingString(setting, '')
     if idx > 0:
         selected = player.itemlist[idx].getLabel()
         self.addon.setSettingString(setting, selected)
Exemple #4
0
def play(item_id, index):
    properties = {}
    if ("hls" in plugin.settings.stream_type
            and plugin.settings.inputstream_adaptive_enabled == "true"
            and inputstreamhelper):
        helper = inputstreamhelper.Helper("hls")
        if not helper.check_inputstream():
            return
        else:
            properties.update({
                "inputstreamaddon": helper.inputstream_addon,
                "inputstream.adaptive.manifest_type": "hls",
            })
    playback_data = get_window_property(index)
    video_data = playback_data.get("video_data")
    video_info = playback_data["video_info"]
    if not video_data:
        response = plugin.client("items/{}".format(item_id)).get()
        video_data = response["item"]["videos"][0]
        video_info = extract_video_info(response["item"], video_info)
    if "files" not in video_data:
        notice("Видео обновляется и временно не доступно!",
               "Видео в обработке",
               time=8000)
        return
    url = get_mlink(
        video_data,
        quality=plugin.settings.video_quality,
        stream_type=plugin.settings.stream_type,
        ask_quality=plugin.settings.ask_quality,
    )
    properties.update({
        "item_id": item_id,
        "play_duration": video_info["duration"],
        "play_resumetime": video_info["time"],
        "video_number": video_info.get("episode", 1),
        "season_number": video_info.get("season", ""),
        "playcount": video_info["playcount"],
        "imdbnumber": video_info["imdbnumber"],
    })
    li = plugin.list_item(
        playback_data["title"],
        path=url,
        properties=properties,
        poster=playback_data["poster"],
        subtitles=[subtitle["url"] for subtitle in video_data["subtitles"]],
    )
    player = Player(list_item=li)
    xbmcplugin.setResolvedUrl(plugin.handle, True, li)
    while player.is_playing:
        player.set_marktime()
        xbmc.sleep(1000)
Exemple #5
0
 def play(self):
     utils.kodi_log('Script -- Attempting to play item:\n{0}'.format(self.params), 2)
     if not self.params.get('play') or not self.params.get('tmdb_id'):
         return
     Player().play(
         itemtype=self.params.get('play'), tmdb_id=self.params.get('tmdb_id'),
         season=self.params.get('season'), episode=self.params.get('episode'))
Exemple #6
0
class PlayItem:
    _shared_state = {}

    def __init__(self):
        self.__dict__ = self._shared_state
        self.api = Api()
        self.player = Player()
        self.state = State()

    def log(self, msg, lvl=2):
        class_name = self.__class__.__name__
        utils.log("%s %s" % (utils.addon_name(), class_name), msg, int(lvl))

    def get_episode(self):
        current_file = self.player.getPlayingFile()
        if not self.api.has_addon_data():
            # Get the active player
            result = self.api.get_now_playing()
            self.handle_now_playing_result(result)
            # get the next episode from kodi
            episode = (self.api.handle_kodi_lookup_of_episode(
                self.state.tv_show_id, current_file,
                self.state.include_watched, self.state.current_episode_id))
        else:
            episode = self.api.handle_addon_lookup_of_next_episode()
            current_episode = self.api.handle_addon_lookup_of_current_episode()
            self.state.current_episode_id = current_episode["episodeid"]
            if self.state.current_tv_show_id != current_episode["tvshowid"]:
                self.state.current_tv_show_id = current_episode["tvshowid"]
                self.state.played_in_a_row = 1
        return episode

    def handle_now_playing_result(self, result):
        if 'result' in result:
            item_type = result["result"]["item"]["type"]
            current_episode_number = result["result"]["item"]["episode"]
            current_season_id = result["result"]["item"]["season"]
            current_show_title = result["result"]["item"]["showtitle"].encode(
                'utf-8')
            current_show_title = utils.unicode_to_ascii(current_show_title)
            self.state.tv_show_id = result["result"]["item"]["tvshowid"]
            if item_type == "episode":
                if int(self.state.tv_show_id) == -1:
                    self.state.tv_show_id = self.api.showtitle_to_id(
                        title=current_show_title)
                    self.log(
                        "Fetched missing tvshowid " +
                        json.dumps(self.state.tv_show_id), 2)

                # Get current episodeid
                current_episode_id = self.api.get_episode_id(
                    showid=str(self.state.tv_show_id),
                    show_season=current_season_id,
                    show_episode=current_episode_number)
                self.state.current_episode_id = current_episode_id
                if self.state.current_tv_show_id != self.state.tv_show_id:
                    self.state.current_tv_show_id = self.state.tv_show_id
                    self.state.played_in_a_row = 1
Exemple #7
0
class Monitor(xbmc.Monitor):

    def __init__(self):
        self.player = Player()
        self.api = Api()
        self.playback_manager = PlaybackManager()
        xbmc.Monitor.__init__(self)

    def log(self, msg, lvl=1):
        class_name = self.__class__.__name__
        utils.log("%s %s" % (utils.addon_name(), class_name), str(msg), int(lvl))

    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 onNotification(self, sender, method, data):

        if method.split('.')[1].lower() != 'upnext_data':  # method looks like Other.upnext_data
            return

        data = utils.decode_data(data)
        data['id'] = "%s_play_action" % str(sender.replace(".SIGNAL", ""))

        self.api.addon_data_received(data)
 def play(self):
     utils.kodi_log(u'Script -- Attempting to play item:\n{0}'.format(self.params), 2)
     if not self.params.get('play') or not self.params.get('tmdb_id'):
         return
     Player().play(
         itemtype=self.params.get('play'), tmdb_id=self.params.get('tmdb_id'),
         season=self.params.get('season'), episode=self.params.get('episode'),
         force_dialog=self.params.get('force_dialog'))
     self.home.clearProperty('TMDbHelper.Player.ResolvedUrl')  # Clear our lock property
Exemple #9
0
class PlayItem:
    _shared_state = {}

    def __init__(self):
        self.__dict__ = self._shared_state
        self.api = Api()
        self.player = Player()
        self.state = State()

    def log(self, msg, lvl=2):
        class_name = self.__class__.__name__
        utils.log("%s %s" % (utils.addon_name(), class_name), msg, int(lvl))

    def get_episode(self):
        current_file = self.player.getPlayingFile()
        if not self.api.has_addon_data():
            # Get the active player
            result = self.api.get_now_playing()
            self.handle_now_playing_result(result)
            # get the next episode from kodi
            episode = (
                self.api.handle_kodi_lookup_of_episode(
                    self.state.tv_show_id, current_file, self.state.include_watched, self.state.current_episode_id))
        else:
            episode = self.api.handle_addon_lookup_of_next_episode()
            current_episode = self.api.handle_addon_lookup_of_current_episode()
            self.state.current_episode_id = current_episode["episodeid"]
            if self.state.current_tv_show_id != current_episode["tvshowid"]:
                self.state.current_tv_show_id = current_episode["tvshowid"]
                self.state.played_in_a_row = 1
        return episode

    def handle_now_playing_result(self, result):
        if 'result' in result:
            item_type = result["result"]["item"]["type"]
            current_episode_number = result["result"]["item"]["episode"]
            current_season_id = result["result"]["item"]["season"]
            current_show_title = result["result"]["item"]["showtitle"].encode('utf-8')
            current_show_title = utils.unicode_to_ascii(current_show_title)
            self.state.tv_show_id = result["result"]["item"]["tvshowid"]
            if item_type == "episode":
                if int(self.state.tv_show_id) == -1:
                    self.state.tv_show_id = self.api.showtitle_to_id(title=current_show_title)
                    self.log("Fetched missing tvshowid " + json.dumps(self.state.tv_show_id), 2)

                # Get current episodeid
                current_episode_id = self.api.get_episode_id(
                    showid=str(self.state.tv_show_id), show_season=current_season_id,
                    show_episode=current_episode_number)
                self.state.current_episode_id = current_episode_id
                if self.state.current_tv_show_id != self.state.tv_show_id:
                    self.state.current_tv_show_id = self.state.tv_show_id
                    self.state.played_in_a_row = 1
Exemple #10
0
    def ServiceEntryPoint(self):

        self.player = Player()
        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 = utils.settings("autoPlaySeasonTime")
                    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.logMsg(
                                "Calling autoplayback totaltime - playtime is %s"
                                % (total_time - play_time), 2)
                            self.player.autoPlayPlayback()
                            self.logMsg("Up Next style autoplay succeeded.", 2)

                except Exception as e:
                    self.logMsg("Exception in Playback Monitor Service: %s" %
                                e)

        self.logMsg("======== STOP %s ========" % utils.addon_name(), 0)
def play_tv(url, name, channel_id=None, index=None):
    listitem = xbmcgui.ListItem(name)
    listitem.setInfo(type="Video", infoLabels={'Title': name})

    # patch url
    if url.startswith('http://itv.hdpfans.com/ty/hdp_ty.php?uuid='):
        location = urllib2.urlopen(
            'http://proxy.shntv.cn/cntv-5-cctv1.m3u8').geturl()
        ip = re.compile(r'http:\/\/(.+?)[:\/]').match(location).group(1)
        url += '&ip=' + ip

    if url.startswith('http://live.hdpfans.com/'):
        url = urllib2.urlopen(url).geturl()

    player = Player()
    player.play(url, listitem)
    if channel_id is not None and index is not None:
        last_indexes = plugin.get_storage('last_tvlink_indexes')
        last_indexes[channel_id] = index
        try:
            last_indexes.sync()
        except:
            plugin.log.debug('last_tvlink_indexes storage save failed')
Exemple #12
0
 def __init__(self):
     self.__dict__ = self._shared_state
     self.api = Api()
     self.play_item = PlayItem()
     self.state = State()
     self.player = Player()
# -*- coding: utf-8 -*-

import sys
import xbmc, xbmcgui
from resources.lib.player import Player
from resources.lib.utils import log, check_config, notify

log("addon.py started")

# make sure a valid playlist exists and up-to-date
if check_config():
    notify('Invalid settings', icon=xbmcgui.NOTIFICATION_ERROR)
    sys.exit()

player = Player()
player.play_bgm()

# Ugly! but Blocking methods such as Tread.join or Lock.acquire do not work.
# They block all processes following and even callback functions of Player seem not to be called.
while xbmc.getCondVisibility('Slideshow.IsActive'):
    xbmc.sleep(500)

player.stop()

log('addon.py ended')
Exemple #14
0
class PlaybackManager:
    _shared_state = {}

    def __init__(self):
        self.__dict__ = self._shared_state
        self.api = Api()
        self.play_item = PlayItem()
        self.state = State()
        self.player = Player()

    def log(self, msg, lvl=2):
        class_name = self.__class__.__name__
        utils.log("%s %s" % (utils.addon_name(), class_name), msg, int(lvl))

    def launch_up_next(self):
        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" % json.dumps(episode), 2)
        self.launch_popup(episode)

    def launch_popup(self, episode):
        episode_id = episode["episodeid"]
        no_play_count = episode["playcount"] is None or episode[
            "playcount"] == 0
        include_play_count = True if self.state.include_watched else no_play_count
        if include_play_count and self.state.current_episode_id != episode_id:
            # we have a next up episode choose mode
            next_up_page, still_watching_page = pages.set_up_pages()
            showing_next_up_page, showing_still_watching_page, total_time = (
                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, total_time))

            play_item_option_1 = (should_play_default
                                  and self.state.playMode == "0")
            play_item_option_2 = (should_play_non_default
                                  and self.state.playMode == "1")
            if play_item_option_1 or play_item_option_2:
                self.log("playing media episode", 2)
                # Signal to trakt previous episode watched
                utils.event("NEXTUPWATCHEDSIGNAL",
                            {'episodeid': self.state.current_episode_id})
                # Play media
                if not self.api.has_addon_data():
                    self.api.play_kodi_item(episode)
                else:
                    self.api.play_addon_item()

    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 extract_play_info(self, next_up_page, showing_next_up_page,
                          showing_still_watching_page, still_watching_page,
                          total_time):
        if self.state.short_play_length >= total_time and self.state.short_play_mode == "true":
            # play short video and don't add to playcount
            self.state.played_in_a_row += 0
            if next_up_page.isWatchNow(
            ) or still_watching_page.isStillWatching():
                self.state.played_in_a_row = 1
            should_play_default = not next_up_page.isCancel()
        else:
            if showing_next_up_page:
                next_up_page.close()
                utils.window('service.upnext.dialog', clear=True)
                should_play_default = not next_up_page.isCancel()
                should_play_non_default = next_up_page.isWatchNow()
            elif showing_still_watching_page:
                still_watching_page.close()
                utils.window('service.upnext.dialog', clear=True)
                should_play_default = still_watching_page.isStillWatching()
                should_play_non_default = still_watching_page.isStillWatching()

            if next_up_page.isWatchNow(
            ) or still_watching_page.isStillWatching():
                self.state.played_in_a_row = 1
            else:
                self.state.played_in_a_row += 1
        return should_play_default, should_play_non_default
Exemple #15
0
 def __init__(self):
     self.player = Player()
     self.api = Api()
     self.playback_manager = PlaybackManager()
     xbmc.Monitor.__init__(self)
Exemple #16
0
 def __init__(self):
     self.player = Player()
     self.api = Api()
     self.playback_manager = PlaybackManager()
     xbmc.Monitor.__init__(self)
class PlaybackManager:
    _shared_state = {}

    def __init__(self):
        self.__dict__ = self._shared_state
        self.api = Api()
        self.play_item = PlayItem()
        self.state = State()
        self.player = Player()

    def log(self, msg, lvl=2):
        class_name = self.__class__.__name__
        utils.log("%s %s" % (utils.addon_name(), class_name), msg, int(lvl))

    def launch_up_next(self):
        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" % json.dumps(episode), 2)
        self.launch_popup(episode)
        self.api.reset_addon_data()

    def launch_popup(self, episode):
        episode_id = episode["episodeid"]
        no_play_count = episode["playcount"] is None or episode["playcount"] == 0
        include_play_count = True if self.state.include_watched else no_play_count
        if include_play_count and self.state.current_episode_id != episode_id:
            # we have a next up episode choose mode
            next_up_page, still_watching_page = pages.set_up_pages()
            showing_next_up_page, showing_still_watching_page, total_time = (
                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, total_time))

            play_item_option_1 = (should_play_default and self.state.playMode == "0")
            play_item_option_2 = (should_play_non_default and self.state.playMode == "1")
            if play_item_option_1 or play_item_option_2:
                self.log("playing media episode", 2)
                # Signal to trakt previous episode watched
                utils.event("NEXTUPWATCHEDSIGNAL", {'episodeid': self.state.current_episode_id})
                # Play media
                if not self.api.has_addon_data():
                    self.api.play_kodi_item(episode)
                else:
                    self.api.play_addon_item()

    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 extract_play_info(self, next_up_page, showing_next_up_page, showing_still_watching_page, still_watching_page,
                          total_time):
        if self.state.short_play_length >= total_time and self.state.short_play_mode == "true":
            # play short video and don't add to playcount
            self.state.played_in_a_row += 0
            if next_up_page.isWatchNow() or still_watching_page.isStillWatching():
                self.state.played_in_a_row = 1
            should_play_default = not next_up_page.isCancel()
        else:
            if showing_next_up_page:
                next_up_page.close()
                utils.window('service.upnext.dialog', clear=True)
                should_play_default = not next_up_page.isCancel()
                should_play_non_default = next_up_page.isWatchNow()
            elif showing_still_watching_page:
                still_watching_page.close()
                utils.window('service.upnext.dialog', clear=True)
                should_play_default = still_watching_page.isStillWatching()
                should_play_non_default = still_watching_page.isStillWatching()

            if next_up_page.isWatchNow() or still_watching_page.isStillWatching():
                self.state.played_in_a_row = 1
            else:
                self.state.played_in_a_row += 1
        return should_play_default, should_play_non_default
 def __init__(self):
     self.__dict__ = self._shared_state
     self.api = Api()
     self.play_item = PlayItem()
     self.state = State()
     self.player = Player()
Exemple #19
0
class Service(xbmc.Monitor):
    def __init__(self, *args):
        self.logMsg("Starting UpNext Service", 0)
        self.logMsg("========  START %s  ========" % utils.addon_name(), 0)
        self.logMsg(
            "KODI Version: %s" % xbmc.getInfoLabel("System.BuildVersion"), 0)
        self.logMsg(
            "%s Version: %s" % (utils.addon_name(), utils.addon_version()), 0)

        xbmc.Monitor.__init__(self)

    def logMsg(self, msg, lvl=1):
        class_name = self.__class__.__name__
        utils.logMsg("%s %s" % (utils.addon_name(), class_name), str(msg),
                     int(lvl))

    def ServiceEntryPoint(self):

        self.player = Player()
        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 = utils.settings("autoPlaySeasonTime")
                    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.logMsg(
                                "Calling autoplayback totaltime - playtime is %s"
                                % (total_time - play_time), 2)
                            self.player.autoPlayPlayback()
                            self.logMsg("Up Next style autoplay succeeded.", 2)

                except Exception as e:
                    self.logMsg("Exception in Playback Monitor Service: %s" %
                                e)

        self.logMsg("======== STOP %s ========" % utils.addon_name(), 0)

    def onNotification(self, sender, method, data):

        if method.split('.')[1].lower(
        ) != 'upnext_data':  # method looks like Other.upnext_data
            return

        data = utils.decode_data(data)
        data['id'] = "%s_play_action" % str(sender)

        self.player.addon_data_received(data)