def list_music(self, speech, langauge, matchedRegex): found, lst = 0, UIDisambiguationList() lst.items = [] anchor = UIAddViews(self.refId) anchor.dialogPhase = anchor.DialogPhaseCompletionValue stripped_artistname = ''.join(ch for ch in matchedRegex.group('artistname') if ch.isalnum()).lower() if stripped_artistname == 'latest': result = json.AudioLibrary.GetRecentlyAddedAlbums(properties=['artist'], limits={'end': 10}) for album in result['albums']: lst.items.append(CreateListItem(album['albumid'], 'album')) anchor.views = [lst] self.say("", "Last 10 albums added...") self.sendRequestWithoutAnswer(anchor) else: result = json.AudioLibrary.GetAlbums(properties=['artist']) for album in result['albums']: if stripped_artistname in ''.join(ch for ch in album['artist'] if ch.isalnum()).lower(): lst.items.append(CreateListItem(album['albumid'], 'album')) found = 1 if found == 0: self.say("Sorry, I couldn't find the artist you're looking for") else: anchor.views = [lst] self.say("", "Albums for '%s'" %(string.capwords(matchedRegex.group('artistname')))) self.sendRequestWithoutAnswer(anchor) self.complete_request()
def play(self, results, language): collection = MPTitleCollection() collection.items = [] for result in results: if not hasattr(result, "genre"): result.genre = "" if not hasattr(result, "trackNumber"): result.trackNumber = "" if not hasattr(result, "artist"): result.artist = "" if not hasattr(result, "title"): result.title = "" if not hasattr(result, "sortTitle"): result.sortTitle = "" if not hasattr(result, "playCount"): result.playCount = "" if not hasattr(result, "rating"): result.rating = "" if not hasattr(result, "album"): result.album = "" if not hasattr(result, "identifier"): result.identifier = "" song = MPSong() song.album = result.album song.artist = result.artist song.genre = result.genre song.playCount = result.playCount song.rating = result.rating song.sortTitle = result.sortTitle song.title = result.title song.trackNumber = result.trackNumber song.identifier = result.identifier collection.items.append(song) collection.sortTitle = result.title collection.title = result.sortTitle collection.identifier = result.identifier complete = MPSetQueue(self.refId) complete.mediaItems = collection self.getResponseForRequest(complete) commands = MPSetState(self.refId) commands.state = "Playing" commands2 = MPEnableShuffle(self.refId) commands2.enable = False code = 0 root = UIAddViews(self.refId) root.dialogPhase = "Summary" assistant = UIAssistantUtteranceView() assistant.dialogIdentifier = "PlayMedia#nowPlayingMediaItemByTitle" assistant.speakableText = assistant.text = res["play"][language] root.views = [(assistant)] root.callbacks = [ResultCallback([commands, commands2], code)] callback = [ResultCallback([root], code)] self.send_object(RequestCompleted(self.refId, callback)) self.complete_request()
def play(self, results, language): collection = MPTitleCollection() collection.items = [] for result in results: if not hasattr(result, 'genre'): result.genre = "" if not hasattr(result, 'trackNumber'): result.trackNumber = "" if not hasattr(result, 'artist'): result.artist = "" if not hasattr(result, 'title'): result.title = "" if not hasattr(result, 'sortTitle'): result.sortTitle = "" if not hasattr(result, 'playCount'): result.playCount = "" if not hasattr(result, 'rating'): result.rating = "" if not hasattr(result, 'album'): result.album = "" if not hasattr(result, 'identifier'): result.identifier = "" song = MPSong() song.album = result.album song.artist = result.artist song.genre = result.genre song.playCount = result.playCount song.rating = result.rating song.sortTitle = result.sortTitle song.title = result.title song.trackNumber = result.trackNumber song.identifier = result.identifier collection.items.append(song) collection.sortTitle = result.title collection.title = result.sortTitle collection.identifier = result.identifier complete = MPSetQueue(self.refId) complete.mediaItems = collection self.getResponseForRequest(complete) commands = MPSetState(self.refId) commands.state = "Playing" commands2 = MPEnableShuffle(self.refId) commands2.enable = False code = 0 root = UIAddViews(self.refId) root.dialogPhase = "Summary" assistant = UIAssistantUtteranceView() assistant.dialogIdentifier = "PlayMedia#nowPlayingMediaItemByTitle" assistant.speakableText = assistant.text = res["play"][language] root.views = [(assistant)] root.callbacks = [ResultCallback([commands, commands2], code)] callback = [ResultCallback([root], code)] self.send_object(RequestCompleted(self.refId, callback)) self.complete_request()
def listlatestmovies(self, speech, langauge): lst = UIDisambiguationList() lst.items = [] x = UIAddViews(self.refId) x.dialogPhase = x.DialogPhaseCompletionValue result = json.VideoLibrary.GetRecentlyAddedMovies(limits={'end': 10}) for movie in result['movies']: lst.items.append(CreateListItem(movie['movieid'], 'movie')) x.views = [lst] self.say("", "Last 10 movies added...") self.sendRequestWithoutAnswer(x) self.complete_request()
def resume(self, language): commands = MPSetState(self.refId) commands.state = "Playing" code = 0 root = UIAddViews(self.refId) root.dialogPhase = "Summary" assistant = UIAssistantUtteranceView() assistant.dialogIdentifier = "PlayMedia#SkipToNext" assistant.speakableText = assistant.text = res["resume"][language] root.views = [(assistant)] root.callbacks = [ResultCallback([commands], code)] callback = [ResultCallback([root], code)] self.send_object(RequestCompleted(self.refId, callback)) self.complete_request()
def pause(self, language): commands = MPSetState(self.refId) commands.state = "Paused" code = 0 root = UIAddViews(self.refId) root.dialogPhase = "Summary" assistant = UIAssistantUtteranceView() assistant.dialogIdentifier = "PlayMedia#Paused" assistant.speakableText = assistant.text = res["pause"][language] root.views = [(assistant)] root.callbacks = [ResultCallback([commands], code)] callback = [ResultCallback([root], code)] self.send_object(RequestCompleted(self.refId, callback)) self.complete_request()
def back(self, language): commands = MPSetState(self.refId) commands.state = "Playing" commands2 = MPSetPlaybackPosition(self.refId) commands2.position = "PreviousItem" code = 0 root = UIAddViews(self.refId) root.dialogPhase = "Summary" assistant = UIAssistantUtteranceView() assistant.dialogIdentifier = "PlayMedia#Previous" assistant.speakableText = assistant.text = res["back"][language] root.views = [(assistant)] root.callbacks = [ResultCallback([commands, commands2], code)] callback = [ResultCallback([root], code)] self.send_object(RequestCompleted(self.refId, callback)) self.complete_request()
def beginning(self, language): commands = MPSetState(self.refId) commands.state = "Playing" commands2 = MPSetPlaybackPosition(self.refId) commands2.position = "Beginning" code = 0 root = UIAddViews(self.refId) root.dialogPhase = "Summary" assistant = UIAssistantUtteranceView() assistant.dialogIdentifier = "PlayMedia#SkipToBeginning" assistant.speakableText = assistant.text = res["beginning"][language] root.views = [(assistant)] root.callbacks = [ResultCallback([commands, commands2], code)] callback = [ResultCallback([root], code)] self.send_object(RequestCompleted(self.refId, callback)) self.complete_request()
def CreateUIView(self): dialog = UIAddViews(self.refId) dialog.dialogPhase = dialog.DialogPhaseCompletionValue return dialog