示例#1
0
 def play_serieepisode():
     episode = TV.get_serie_episode()
     if episode is not None:
         shared_data = SharedData()
         shared_data.set('playing', {
             'what': 'episode_nba_tv',
         })
         common.play(episode)
示例#2
0
 def play_live():
     live = TV.get_live()
     if live is not None:
         shared_data = SharedData()
         shared_data.set('playing', {
             'what': 'nba_tv_live',
         })
         common.play(live)
    def playLive():
        video_url = LiveTV.getLiveUrl()
        if video_url:
            shared_data = SharedData()
            shared_data.set("playing", {
                "what": "nba_tv_live",
            })

            item = xbmcgui.ListItem(path=video_url)
            xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, item)
    def playLive():
        video_url = LiveTV.getLiveUrl()
        if video_url:
            shared_data = SharedData()
            shared_data.set("playing", {
                "what": "nba_tv_live",
            })

            item = xbmcgui.ListItem(path=video_url)
            xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, item)
示例#5
0
    def play_live():
        video_url = TV.get_live_url()
        if video_url is not None:
            shared_data = SharedData()
            shared_data.set('playing', {
                'what': 'nba_tv_live',
            })

            item = common.getPlayableItem(video_url)
            if item is not None:
                xbmcplugin.setResolvedUrl(handle=int(sys.argv[1]),
                                          succeeded=True,
                                          listitem=item)
示例#6
0
 def play_episode():
     start_timestamp = vars.params.get('start_timestamp')
     duration = vars.params.get('duration')
     episode = TV.get_episode(start_timestamp, duration)
     if episode is not None:
         shared_data = SharedData()
         shared_data.set('playing', {
             'what': 'nba_tv_episode',
             'data': {
                 'start_timestamp': start_timestamp,
                 'duration': duration,
             },
         })
         common.play(episode)
示例#7
0
    def play_episode():
        start_timestamp = vars.params.get('start_timestamp')
        duration = vars.params.get('duration')
        video_url = TV.get_episode_url(start_timestamp, duration)
        if video_url is not None:
            shared_data = SharedData()
            shared_data.set(
                'playing', {
                    'what': 'nba_tv_episode',
                    'data': {
                        'start_timestamp': start_timestamp,
                        'duration': duration,
                    },
                })

            item = common.getPlayableItem(video_url)
            if item is not None:
                xbmcplugin.setResolvedUrl(handle=int(sys.argv[1]),
                                          succeeded=True,
                                          listitem=item)
示例#8
0
def main():
    utils.log("starting service...")

    #Reset currently playing video
    shared_data = SharedData()
    shared_data.set("playing", {})

    polling_thread = PollingThread()
    polling_thread.start()

    if xbmc.__version__ >= '2.19.0':
        monitor = xbmc.Monitor()
        while not monitor.abortRequested():
            if monitor.waitForAbort(100):
                break
    else:
        while not xbmc.abortRequested:
            xbmc.sleep(100)

    utils.log("stopping service..")

    polling_thread.stop()
示例#9
0
class PollingThread(BaseThread):

    def __init__(self):
        super(PollingThread, self).__init__()

        self.expires = 0
        self.last_refresh = time.time()
        self.player = MyPlayer()
        self.shared_data = SharedData()

    def refreshLiveUrl(self):
        if self.shared_data.get('playing.what') == 'nba_tv_live':
            video_url = TV.get_live_url(force_login=True)
        elif self.shared_data.get('playing.what') == 'nba_tv_episode':
            start_timestamp = self.shared_data.get('playing.data.start_timestamp')
            duration = self.shared_data.get('playing.data.duration')
            video_url = TV.get_episode_url(start_timestamp, duration, force_login=True)

        if video_url:
            self.readExpiresFromUrl(video_url)
            utils.log("Updating live url from service, new url (%s) and expire (%d)" 
                % (video_url, self.expires))

            self.player.play(video_url)

    def readExpiresFromUrl(self, url):
        url_parts = urlparse(url)

        #Parse query string to dictionary
        query_params = parse_qs(url_parts.query)

        #Get the hdnea param, where the "expires" param is
        hdnea_params = query_params.get("hdnea")[0]
        hdnea_params = hdnea_params.replace('~', '&')
        hdnea_params = urllib.unquote(hdnea_params)

        self.expires = parse_qs(hdnea_params).get("expires", 0)[0]
        self.expires = int(self.expires)

    def run(self):
        while True:
            try:
                current_playing_url = self.player.getPlayingFile()
                self.readExpiresFromUrl(current_playing_url)
                utils.log("Playing url: %s - playing cache: %s" % 
                    (current_playing_url, self.shared_data.get("playing")), xbmc.LOGDEBUG)
            except:
                pass

            if self.shared_data.get("playing.what"):
                #Wait second iteration before checking the expiration
                if self.shared_data.get("playing.second_iteration") != "1":
                    xbmc.sleep(2000);
                    self.shared_data.set("playing.second_iteration", "1")
                    continue;

                timestamp = time.time()

                #Avoid refreshing too fast, let at least one minute pass from the last refresh
                expire_timestamp = max(self.expires, self.last_refresh + 60)

                utils.log("%d seconds to url refresh" % (expire_timestamp - timestamp))
                if timestamp > expire_timestamp:
                    self.refreshLiveUrl()
                    self.last_refresh = timestamp

            xbmc.sleep(1000)

            if not self.should_keep_running():
                utils.log("Interrupting service loop")
                break 
示例#10
0
    def onPlayBackStopped(self):
        utils.log("Playback STOPPED...")

        shared_data = SharedData()
        shared_data.set("playing", {})
示例#11
0
    def onPlayBackEnded(self):
        utils.log("Playback ENDED...")

        shared_data = SharedData()
        shared_data.set("playing", {})
示例#12
0
    def onPlayBackEnded(self):
        utils.log("Playback ENDED...")

        shared_data = SharedData()
        shared_data.set("playing", {})
示例#13
0
    def onPlayBackStopped(self):
        utils.log("Playback STOPPED...")

        shared_data = SharedData()
        shared_data.set("playing", {})