Example #1
0
def init_playqueues():
    """
    Call this once on startup to initialize the PKC playqueue objects in
    the list PLAYQUEUES
    """
    if PLAYQUEUES:
        LOG.debug('Playqueues have already been initialized')
        return
    # Initialize Kodi playqueues
    with LOCK:
        for i in (0, 1, 2):
            # Just in case the Kodi response is not sorted correctly
            for queue in js.get_playlists():
                if queue['playlistid'] != i:
                    continue
                playqueue = PL.Playqueue_Object()
                playqueue.playlistid = i
                playqueue.type = queue['type']
                # Initialize each Kodi playlist
                if playqueue.type == v.KODI_TYPE_AUDIO:
                    playqueue.kodi_pl = PlayList(PLAYLIST_MUSIC)
                elif playqueue.type == v.KODI_TYPE_VIDEO:
                    playqueue.kodi_pl = PlayList(PLAYLIST_VIDEO)
                else:
                    # Currently, only video or audio playqueues available
                    playqueue.kodi_pl = PlayList(PLAYLIST_VIDEO)
                    # Overwrite 'picture' with 'photo'
                    playqueue.type = v.KODI_TYPE_PHOTO
                PLAYQUEUES.append(playqueue)
    LOG.debug('Initialized the Kodi playqueues: %s', PLAYQUEUES)
Example #2
0
 def get_next(self):
     playlist = PlayList(PLAYLIST_VIDEO)
     position = playlist.getposition()
     # A playlist with only one element has no next item and PlayList().getposition() starts counting from zero
     if playlist.size() > 1 and position < (playlist.size() - 1):
         return self.api.get_next_in_playlist(position)
     return False
Example #3
0
    def __init__(self, callback=None):
        self.__dict__ = self.__shared_state
        if self.playqueues is not None:
            log.debug('Playqueue thread has already been initialized')
            Thread.__init__(self)
            return
        self.mgr = callback

        # Initialize Kodi playqueues
        with lock:
            self.playqueues = []
            for queue in PL.get_kodi_playqueues():
                playqueue = PL.Playqueue_Object()
                playqueue.playlistid = queue['playlistid']
                playqueue.type = queue['type']
                # Initialize each Kodi playlist
                if playqueue.type == 'audio':
                    playqueue.kodi_pl = PlayList(PLAYLIST_MUSIC)
                elif playqueue.type == 'video':
                    playqueue.kodi_pl = PlayList(PLAYLIST_VIDEO)
                else:
                    # Currently, only video or audio playqueues available
                    playqueue.kodi_pl = PlayList(PLAYLIST_VIDEO)
                    # Overwrite 'picture' with 'photo'
                    playqueue.type = v.KODI_TYPE_PHOTO
                self.playqueues.append(playqueue)
            # sort the list by their playlistid, just in case
            self.playqueues = sorted(self.playqueues,
                                     key=lambda i: i.playlistid)
        log.debug('Initialized the Kodi play queues: %s' % self.playqueues)
        Thread.__init__(self)
Example #4
0
    def get_playlist_position():
        """Function to get current playlist playback position"""

        playlist = PlayList(PLAYLIST_VIDEO)
        position = playlist.getposition()
        # A playlist with only one element has no next item and PlayList().getposition() starts counting from zero
        if playlist.size() > 1 and position < (playlist.size() - 1):
            # Return 1 based index value
            return position + 1
        return False
    def add_upnext(self, video_id):
        """Add Up Next url to Kodi Player"""
        # Reset vrtnu_resumepoints property
        set_property('vrtnu_resumepoints', None)

        url = url_for('play_upnext', video_id=video_id)
        self.update_position()
        self.update_total()
        if self.isPlaying() and self.total - self.last_pos < 1:
            log(3,
                '[PlayerInfo {id}] Add {url} to Kodi Playlist',
                id=self.thread_id,
                url=url)
            PlayList(1).add(url)
        else:
            log(3,
                '[PlayerInfo {id}] Add {url} to Kodi Player',
                id=self.thread_id,
                url=url)
            self.play(url)
Example #6
0
    def _playAV(self,
                playlist: xbmc.PlayList,
                startpos=0,
                seektime=None,
                repeat=player_utils.REPEAT_OFF,
                shuffled=False,
                speed=1.0) -> None:

        self._playlist = playlist
        self._seektime = seektime
        self._skip_next_stop_event_until_started = True

        if playlist.getPlayListId() == TYPES.index(VIDEO):
            self.stopPlayer(PICTURE)

        self.setRepeat(repeat)
        self.setShuffled(shuffled)
        self.setSpeed(speed)
        xbmc.executebuiltin("CECActivateSource")
        self.play(playlist, startpos=startpos)
Example #7
0
def play_video(videoId):
    video = repository.get_video(videoId)
    streams = repository.get_video_streams(video.streamId)

    item = ListItem(path=streams[0].url)
    item.setProperty(u'IsPlayable', u'true')
    item.setInfo(
        type='Video',
        infoLabels={'Title': video.title, 'Plot': video.description}
    )

    analytics.trackVideoPlayed(video.slug)

    playlist = PlayList(PLAYLIST_VIDEO)
    playlist.clear()
    playlist.add(streams[0].url, item)

    player = Player()
    player.play(playlist)
Example #8
0
def wrapper_PlayList(*args, **kwargs):
    rv = PlayList(*args, **kwargs)
    cls = type("PlayListProxy", (Proxy, ), {"add": wrapper_PlayList_add})
    return cls(rv)