def NowPlaying(self): playlist = mc.PlayList(mc.PlayList.PLAYLIST_MUSIC) n = playlist.Size() data = [] songs = [] for i in range(n): song = playlist.GetItem(i) name = song.GetProperty('info') if 'play?' in name: name = name.split('?')[1] parts = name.split('&') songId = parts[0].split('=')[1] artistId = parts[1].split('=')[1] albumId = parts[2].split('=')[1] image = decode(parts[3].split('=')[1]) songName = decode(parts[4].split('=')[1]) artistName = decode(parts[5].split('=')[1]) albumName = decode(parts[6].split('=')[1]) options = parts[7].split('=')[1] item = { 'SongID': songId, 'Name': songName, 'AlbumName': albumName, 'ArtistName': artistName, 'ArtistID': artistId, 'AlbumID': albumId, 'ArtistID': artistId, 'CoverArt': image } data.append(item) else: print 'Song passed' songs = Songs(data, defaultCoverArt=self.defaultCoverArt) return songs._list(self, self.gs)
def SavePlaylistItemsAsFiles(self): videoPlaylist = mc.PlayList(mc.PlayList.PLAYLIST_VIDEO) for index in range(videoPlaylist.Size()): singleItem = videoPlaylist.GetItem(index) filePath = self.GeneratePlayFileForItem(singleItem, True) if None != filePath: singleItem.SetPath(filePath)
def PlayEpisodesWithMenu(self, playListItem, episodesList): self.referenceItem = playListItem videoPlaylist = mc.PlayList(mc.PlayList.PLAYLIST_VIDEO) videoPlaylist.Clear() for episode in episodesList: mc.LogInfo("added to playlist item with name: %s" % episode.GetLabel()) videoPlaylist.Add(episode) #show playlist selection dialog (playlistSelect.xml) mc.ActivateWindow(14100) mc.LogInfo("show playlist selection dialog called")
def queueAll(self, gsapi, playlist=None, append=False): if playlist == None: playlist = mc.PlayList(mc.PlayList.PLAYLIST_MUSIC) if append == False: playlist.Clear() offset = 0 else: offset = playlist.Size() for i in range(self.count()): song = self.get(i) self.queue(gsapi, song, playlist=playlist, index=i + offset)
def queue(self, gsapi, song=None, playlist=None, index=-1, options='', url=None): if playlist == None: playlist = mc.PlayList(mc.PlayList.PLAYLIST_MUSIC) url2 = self.defaultUrl(song) if playlist.Size() > 1: url = url2 else: url = gsapi.getStreamURL(str(song.id)) listItem = self.createListItem(url, song, url2) playlist.Add(listItem)
def __init__(self): mc.ShowDialogWait() self.useCoverArt = True self.player = mc.GetPlayer() self.defaultCoverArt = 'default-cover.png' self.xbmcPlaylist = mc.PlayList(mc.PlayList.PLAYLIST_MUSIC) self.gs = GrooveAPI(enableDebug=__debugging__, cwd=__cwd__, clientUuid=None, clientVersion=None) username = __settings__.GetValue("username") password = __settings__.GetValue("password") self.gs.startSession(username, password) self.gs.setRemoveDuplicates(True) self._search = None self.start() mc.HideDialogWait()
def playMusicUrl(self, fullUrl): trackUrl = self.getUrl(self.getRootUrl(), fullUrl) data = mc.Http().Get(trackUrl) if data: tree = ElementTree.fromstring(data) trackNode = tree[0] title = trackNode.attrib.get("title", "Plex Track") playlist = mc.PlayList(mc.PlayList.PLAYLIST_MUSIC) playlist.Clear() for part in trackNode.findall("Media/Part"): li = mc.ListItem(mc.ListItem.MEDIA_AUDIO_MUSIC) li.SetTitle(title) li.SetLabel(title) li.SetPath(self.getUrl(self.getRootUrl(), part.attrib.get('key'))) playlist.Add(li) playlist.Play(0) else: return None
def OnDialogLoad(self): # external caller is responsible to prepare shared boxee video playlist # before show this dialog videoPlaylist = mc.PlayList(mc.PlayList.PLAYLIST_VIDEO) videos = mc.ListItems() for i in range(videoPlaylist.Size()): playlistItem = videoPlaylist.GetItem(i) item = mc.ListItem(mc.ListItem.MEDIA_VIDEO_EPISODE) item.SetLabel(playlistItem.GetLabel()) item.SetDescription(playlistItem.GetDescription()) item.SetPath(playlistItem.GetPath()) videos.append(item) self.GetPlaylistList().SetItems(videos) index = exPlayer.GetPlayer().GetLastViewedEpisodeIndexInPlaylist() self.GetPlaylistList().SetFocusedItem(index) self.GetPlaylistList().SetSelected(index, True) dialogTitle = mc.GetLocalizedString(559) + ": " + videoPlaylist.GetItem(0).GetTitle() self.GetDialogTitleLabel().SetLabel(dialogTitle) mc.LogInfo("Playlist thumbnail: %s" % videoPlaylist.GetItem(0).GetThumbnail()) self.GetFineArtImage().SetTexture(videoPlaylist.GetItem(0).GetThumbnail()) # fill up actions buttons list actionItems = mc.ListItems() actionItem = mc.ListItem(mc.ListItem.MEDIA_UNKNOWN) # localize with 'more info' # actionItem.SetLabel(mc.GetLocalizedString(53710)) actionItem.SetLabel(exlocalizer.GetSharedLocalizer().localizedString('Info')) actionItem.SetThumbnail('action_more.png') actionItems.append(actionItem) actionItem = mc.ListItem(mc.ListItem.MEDIA_UNKNOWN) # localize with 'add to favorites' #actionItem.SetLabel(mc.GetLocalizedString(53729)) actionItem.SetLabel(exlocalizer.GetSharedLocalizer().localizedString('Add to Favorites')) actionItem.SetThumbnail('action_queue_add.png') actionItems.append(actionItem) self.GetActionsList().SetItems(actionItems) mc.LogInfo("Select playlist window is loaded")
def playVideoUrl(self, fullUrl): videoUrl = self.getUrl(self.getRootUrl(), fullUrl) data = mc.Http().Get(videoUrl) if data: tree = ElementTree.fromstring(data) videoNode = tree[0] title = videoNode.attrib.get("title", "Plex Video") playlist = mc.PlayList(mc.PlayList.PLAYLIST_VIDEO) playlist.Clear() for part in videoNode.findall("Media/Part"): li = mc.ListItem(mc.ListItem.MEDIA_UNKNOWN) li.SetTitle(title) li.SetLabel(title) li.SetPath( self.getUrl(self.getRootUrl(), part.attrib.get('key'))) playlist.Add(li) playlist.Play(0) else: return None
def play(self, selected, gsapi, playlist=None): if playlist == None: playlist = mc.PlayList(mc.PlayList.PLAYLIST_MUSIC) song = self.get(selected) url = gsapi.getStreamURL(str(song.id)) url2 = self.defaultUrl(song) count = playlist.Size() direct = True itemnr = 0 if count > 0: for i in range(count): item = playlist.GetItem(i) if item.GetTitle() == song.name.encode('utf-8'): direct = False itemnr = i if direct: listItem = self.createListItem(url, song, url2) playlist.Clear() playlist.Add(listItem) mc.GetPlayer().PlaySelected(0) else: mc.GetPlayer().PlaySelected(itemnr - 1)
if (playSong != None): print 'GrooveShark: Song ID: ' + str(playSong) url = gs.getStreamURL(str(playSong)) if url != "": listItem = mc.ListItem(mc.ListItem.MEDIA_AUDIO_MUSIC) listItem.SetPath(str(url)) listItem.SetProperty('info', str(org_url)) listItem.SetContentType('audio/mpeg') listItem.SetTitle(songName) listItem.SetThumbnail(image) listItem.SetIcon(image) listItem.SetAlbum(albumName) listItem.SetArtist(artistName) print 'GrooveShark: Found stream url: (' + url + ')' playlist = mc.PlayList(mc.PlayList.PLAYLIST_MUSIC) listItems = [] append = False for i in range(playlist.Size()): item = playlist.GetItem(i) if item.GetTitle() == songName: append = True listItems.append(listItem) elif append: listItems.append(item) playlist.Clear() for item in listItems: playlist.Add(item) mc.GetPlayer().PlaySelected(0) print 'GrooveShark: ####### Finished' else: print 'GrooveShark: No stream url returned for song id'
def playVideoUrl(self, fullUrl, subitem = None, offset=0): videoUrl = self.getUrl(self.getRootUrl(), fullUrl) data = mc.Http().Get(videoUrl) if data: tree = ElementTree.fromstring(data) videoNode = tree[0] playlist = mc.PlayList(mc.PlayList.PLAYLIST_VIDEO) playlist.Clear() thumbnailUrl = self.getThumbUrl(videoNode.attrib.get("thumb"), 100, 100) description = util.cleanString(videoNode.attrib.get("summary","")) title = util.cleanString(videoNode.attrib.get("title", "Plex Video")) contentRating = util.cleanString(videoNode.attrib.get("contentRating","")) for part in videoNode.findall("Media/Part"): li = mc.ListItem(mc.ListItem.MEDIA_VIDEO_CLIP) li.SetTitle(title) li.SetLabel(title) li.SetPath(self.getUrl(self.getRootUrl(), part.attrib.get("key"))) li.SetThumbnail(thumbnailUrl) li.SetDescription(description, False) li.SetContentRating(contentRating) #TV Episode extras mediaType = videoNode.attrib.get("type","movie") if mediaType == 'episode': li.SetTVShowTitle(util.cleanString(videoNode.attrib.get("grandparentTitle",""))) li.SetEpisode(int(videoNode.attrib.get('index'))) li.SetSeason(int(videoNode.attrib.get('parentIndex'))) playlist.Add(li) playlist.Play(0) #ok wait for player to start loop = 0 util.logDebug("Waiting on player") while not xbmc.Player().isPlaying(): xbmc.sleep(1000) loop = loop + 1 if loop > 10: break util.logDebug("Player started...") #set any offset if offset != 0: xbmc.Player().seekTime(offset/1000) #Set subtitles subtitleKey = "" if subitem != None: subtitleKey = subitem.GetPath() if subtitleKey == "": import os noSubPath = os.path.join(mc.GetApp().GetAppMediaDir(), "media", "no_subs.srt") xbmc.Player().setSubtitles(noSubPath) else: util.logInfo("Setting subtitles to: " + subtitleKey) xbmc.Player().setSubtitles(subtitleKey) #Monitor playback and update progress to plex key = videoNode.attrib.get('ratingKey') self.monitorPlayback(key, offset) else: return None