Esempio n. 1
0
    def populateRadioStations(self):
        sonosDevice = Sonos.createSonosDevice()

        # Make sure a Sonos speaker was found
        if sonosDevice is not None:
            totalCollected = 0
            totalEntries = 1

            # Need to get all the tracks in batches
            while (totalCollected < totalEntries) and not self._listLimitReached(totalCollected):
                # Get the items from the sonos system
                list = None
                try:
                    list = sonosDevice.get_favorite_radio_stations(
                        start=totalCollected, max_items=Settings.getBatchSize()
                    )
                except:
                    log("SonosPlugin: %s" % traceback.format_exc(), xbmc.LOGERROR)
                    xbmcgui.Dialog().ok(__addon__.getLocalizedString(32068), __addon__.getLocalizedString(32071))
                    return

                # Processes the list returned from Sonos, creating the list display on the screen
                totalEntries = int(list["total"])
                log("SonosPlugin: Total Radio Station Matches %d" % totalEntries)
                numberReturned = list["returned"]
                log("SonosPlugin: Total Radio Stations in this batch %d" % numberReturned)

                # Makes sure some items are returned
                if numberReturned < 1:
                    numberReturned = len(list["favorites"])
                    if numberReturned < 1:
                        log("SonosPlugin: Zero items returned from request")
                        break

                for item in list["favorites"]:
                    # Add the radio station to the list
                    url = self._build_url(
                        {
                            "mode": "action",
                            "action": ActionManager.ACTION_RADIO_PLAY,
                            "itemId": item["uri"],
                            "title": item["title"],
                        }
                    )

                    li = xbmcgui.ListItem(item["title"], path=url, iconImage=MediaFiles.RadioStationIcon)
                    # Set the right click context menu for the ratio station
                    li.addContextMenuItems([], replaceItems=True)  # Clear the Context Menu
                    self._addPlayerToContextMenu(li)

                    xbmcplugin.addDirectoryItem(
                        handle=self.addon_handle, url=url, listitem=li, isFolder=False, totalItems=totalEntries
                    )

                # Add the number returned this time to the running total
                totalCollected = totalCollected + numberReturned
            del sonosDevice

        xbmcplugin.endOfDirectory(self.addon_handle)
Esempio n. 2
0
    def populateQueueList(self):
        sonosDevice = Sonos.createSonosDevice()

        # Make sure a Sonos speaker was found
        if sonosDevice is not None:
            totalCollected = 0
            numberReturned = Settings.getBatchSize()

            # Need to get all the tracks in batches
            # Only get the next batch if all the items requested were in the last batch
            while (numberReturned == Settings.getBatchSize()) and not self._listLimitReached(totalCollected):
                # Get the items from the sonos system
                list = None
                try:
                    list = sonosDevice.get_queue(totalCollected, Settings.getBatchSize(), True)
                except:
                    log("SonosPlugin: %s" % traceback.format_exc(), xbmc.LOGERROR)
                    xbmcgui.Dialog().ok(__addon__.getLocalizedString(32068), __addon__.getLocalizedString(32070))
                    return

                # Processes the list returned from Sonos, creating the list display on the screen
                numberReturned = len(list)
                log("SonosPlugin: Total queue entries in this batch %d" % numberReturned)

                itemNum = 0

                for item in list:
                    # Get a suitable display title
                    displayTitle = None
                    if (item.creator is not None) and (item.creator != ""):
                        displayTitle = "%s - %s" % (item.title, item.creator)
                    else:
                        displayTitle = item.title

                    # Create the list item for the track
                    if hasattr(item, 'album_art_uri') and (item.album_art_uri is not None) and (item.album_art_uri != ""):
                        li = xbmcgui.ListItem(displayTitle, iconImage=item.album_art_uri, thumbnailImage=item.album_art_uri)
                    else:
                        li = xbmcgui.ListItem(displayTitle, iconImage=MediaFiles.TracksIcon)
                    # Set addition information about the track - will be seen in info view
                    li.setInfo('music', {'title': item.title, 'artist': item.creator, 'album': item.album})

                    # Create the action to be performed when clicking a queue item
                    url = self._build_url({'mode': 'action', 'action': ActionManager.ACTION_QUEUE_PLAY_ITEM, 'itemId': itemNum})

                    # Add the context menu for the queue
                    self._addQueueContextMenu(li, itemNum + totalCollected)
                    itemNum = itemNum + 1

                    xbmcplugin.addDirectoryItem(handle=self.addon_handle, url=url, listitem=li, isFolder=False)

                totalCollected = totalCollected + numberReturned
            del sonosDevice

        xbmcplugin.endOfDirectory(self.addon_handle)
Esempio n. 3
0
    def populateRadioShows(self):
        sonosDevice = Sonos.createSonosDevice()

        # Make sure a Sonos speaker was found
        if sonosDevice is not None:
            totalCollected = 0
            totalEntries = 1

            # Need to get all the tracks in batches
            while (totalCollected < totalEntries) and not self._listLimitReached(totalCollected):
                # Get the items from the sonos system
                list = None
                try:
                    list = sonosDevice.get_favorite_radio_shows(start=totalCollected, max_items=Settings.getBatchSize())
                except:
                    log("SonosPlugin: %s" % traceback.format_exc(), xbmc.LOGERROR)
                    xbmcgui.Dialog().ok(__addon__.getLocalizedString(32068), __addon__.getLocalizedString(32072))
                    return

                # Processes the list returned from Sonos, creating the list display on the screen
                totalEntries = int(list['total'])
                log("SonosPlugin: Total Radio Shows Matches %d" % totalEntries)
                numberReturned = list['returned']
                log("SonosPlugin: Total Radio Shows in this batch %d" % numberReturned)

                # Makes sure some items are returned
                if numberReturned < 1:
                    numberReturned = len(list['favorites'])
                    if numberReturned < 1:
                        log("SonosPlugin: Zero items returned from request")
                        break

                for item in list['favorites']:
                    # Add the radio station to the list
                    url = self._build_url({'mode': 'action', 'action': ActionManager.ACTION_RADIO_PLAY, 'itemId': item['uri'], 'title': item['title']})

                    li = xbmcgui.ListItem(item['title'], path=url, iconImage=MediaFiles.RadioStationIcon)
                    # Set the right click context menu for the ratio station
                    li.addContextMenuItems([], replaceItems=True)  # Clear the Context Menu
                    self._addPlayerToContextMenu(li)

                    xbmcplugin.addDirectoryItem(handle=self.addon_handle, url=url, listitem=li, isFolder=False, totalItems=totalEntries)

                # Add the number returned this time to the running total
                totalCollected = totalCollected + numberReturned
            del sonosDevice

        xbmcplugin.endOfDirectory(self.addon_handle)
Esempio n. 4
0
    def __init__(self, sonos, playlists=None):
        NavigationScene.__init__(self, "Playlists")

        self.sonos = sonos
        self.background_color = colors.NAVY        

        if playlists == None:
            playlists = Sonos.playlists()
        self.playlists = playlists
        self.playlist_titles = []
        for playlist in self.playlists:
            self.playlist_titles.append(playlist.title)       

        # Add list of playlists
        self.playlist_list_view = ListView(Rect(0,80,Window.frame.width, Window.frame.height - 80),self.playlist_titles)
        self.playlist_list_view.on_selected.connect(self.playlist_selected)
        self.add_child(self.playlist_list_view)
    def __init__(self, sonos, genres=None):
        NavigationScene.__init__(self, "Genres")

        self.sonos = sonos
        self.background_color = colors.NAVY        

        if genres == None:
            genres = Sonos.genres()
        self.genres = genres
        self.genre_titles = []
        for genre in self.genres:
            self.genre_titles.append(genre.title)       

        # Add list of genres
        self.genre_list_view = ListView(Rect(0,80,Window.frame.width, Window.frame.height - 80),self.genre_titles)
        self.genre_list_view.on_selected.connect(self.genre_selected)
        self.add_child(self.genre_list_view)
    def generate_room_list(self):
        ''' Generates a list of rooms/zones

        If a room is a zone coordinator and has members in its group,
        it will be displayed first with all its members appended to it
        with commas'''
        y = 80
        for zone in Sonos.get_zone_groups():
            if zone["is_coordinator"]:
                button_text = zone["name"]
                for member in zone["members"]:
                    button_text += ", {}".format(member)
                room_button = Button(Rect(20, y, 280, 40),
                                     30,
                                     text=button_text)
                room_button.on_tapped.connect(self.change_room)
                self.add_child(room_button)
                y += 60
    def __init__(self, sonos, title="Albums", albums=None):
        NavigationScene.__init__(self, title)

        self.sonos = sonos
        self.background_color = colors.NAVY

        if albums == None:
            albums = Sonos.albums()
        self.albums = albums
        self.album_titles = []
        for album in self.albums:
            self.album_titles.append(album.title)

        # Add list of albums
        self.album_list_view = ListView(
            Rect(0, 80, Window.frame.width, Window.frame.height - 80),
            self.album_titles)
        self.album_list_view.on_selected.connect(self.album_selected)
        self.add_child(self.album_list_view)
    def __init__(self, sonos):
        ModalScene.__init__(self, sonos.current_zone)

        self.sonos = sonos

        in_party_mode = Sonos.in_party_mode()

        ##### Party Mode On Button #####
        icon_party_on_image = Image('icon_party_on',
                                    filename='icon_party_on.png')
        self.party_on_button = Button(Rect(270, 20, 30, 30),
                                      image=icon_party_on_image)
        self.party_on_button.hidden = in_party_mode
        self.party_on_button.on_tapped.connect(self.group_all)
        self.add_child(self.party_on_button)

        ##### Party Mode Off Button #####
        icon_party_off_image = Image('icon_party_off',
                                     filename='icon_party_off.png')
        self.party_off_button = Button(Rect(270, 20, 30, 30),
                                       image=icon_party_off_image)
        self.party_off_button.on_tapped.connect(self.group_none)
        self.party_off_button.hidden = not in_party_mode
        self.add_child(self.party_off_button)

        ##### Done Button #####
        self.done_button = Button(Rect(20, 430, 280, 40), 40, text='Done')
        self.done_button.on_tapped.connect(self.done)
        self.add_child(self.done_button)

        self.room_buttons = []

        self.unchanged = True

        self.layout()
        self.generate_rooms()
Esempio n. 9
0
    # Removes the Sonos keymap
    def cleanup(self):
        if self.keymapCopied is True:
            try:
                xbmcvfs.delete(self.KEYMAPDESTFILE)
                log("KeyMaps: Removed custom keymap")
            except:
                log("KeyMaps: Failed to remove & load custom keymap: %s" % traceback.format_exc(), xbmc.LOGERROR)

            # Force a re-load
            xbmc.executebuiltin('Action(reloadkeymaps)')


if __name__ == '__main__':

    sonosDevice = Sonos.createSonosDevice()

    # Make sure a Sonos speaker was found
    if sonosDevice is not None:
        # Setup the keymap for the controller
        keyMapCtrl = KeyMaps()
        keyMapCtrl.enable()

        try:
            if Settings.displayArtistInfo():
                sonosCtrl = SonosArtistSlideshow.createSonosArtistSlideshow(sonosDevice)
            else:
                sonosCtrl = SonosControllerWindow.createSonosControllerWindow(sonosDevice)

            # Record the fact that the Sonos controller window is displayed
            xbmcgui.Window(10000).setProperty("SonosControllerShowing", "true")
 def album_selected(self, list_view, title, index):
     # Browse the tracks for this album
     scene = SelectTrack(self.sonos, title,
                         Sonos.browse(self.albums[index]),
                         self.albums[index])
     self.add_child(scene)
Esempio n. 11
0
 def __init__(self):
     self.sonosDevice = Sonos.createSonosDevice()
Esempio n. 12
0
    def processFolderMessage(self, folderName, subCategory=''):
        sonosDevice = Sonos.createSonosDevice()

        # Make sure a Sonos speaker was found
        if sonosDevice is not None:
            # Process the sub-category
            if subCategory is None:
                subCategory = ''

            totalCollected = 0
            totalEntries = 1

            isFirstItem = True

            # Need to get all the tracks in batches
            while (totalCollected < totalEntries) and not self._listLimitReached(totalCollected):
                # make the call to get the tracks in batches of 100

                # Get the items from the sonos system
                list = None
                try:
                    if (subCategory is None) or (subCategory == ''):
                        list = sonosDevice.music_library.get_music_library_information(folderName, totalCollected, Settings.getBatchSize(), True)
                    else:
                        # Make sure the sub category is valid for the message, escape invalid characters
                        # subCategory = urllib.quote(subCategory)
                        # Call the browse version
                        list = sonosDevice.music_library.browse_by_idstring(folderName, subCategory, totalCollected, Settings.getBatchSize(), True)
                except:
                    log("SonosPlugin: %s" % traceback.format_exc(), xbmc.LOGERROR)
                    xbmcgui.Dialog().ok(__addon__.getLocalizedString(32068), __addon__.getLocalizedString(32069) % (folderName, subCategory))
                    return

                # Processes the list returned from Sonos, creating the list display on the screen
                totalEntries = list.total_matches
                log("SonosPlugin: Total %s Matches %d" % (folderName, totalEntries))
                numberReturned = list.number_returned
                log("SonosPlugin: Total %s in this batch %d" % (folderName, numberReturned))

                # Makes sure some items are returned
                if numberReturned < 1:
                    numberReturned = len(list)
                    if numberReturned < 1:
                        log("SonosPlugin: Zero items returned from request")
                        break

                for item in list:
                    # Check if this item is a track of a directory
                    if isinstance(item, soco.data_structures.DidlMusicTrack):
                        self._addTrack(item, totalEntries, folderName)
                    else:
                        # Check for the special case where there is an "All" first in the list
                        # For this the id and parent values are the same.  The All item
                        # is a special case and does not handle like a normal directory
                        if ('sameArtist' in item.item_class) or ('albumlist' in item.item_class):
                            log("SonosPlugin: Skipping \"All\" item for %s" % item.title)
                            isFirstItem = False
                            continue

                        # Check to see if we are dealing with a sonos playlist
                        if isinstance(item, soco.data_structures.DidlPlaylistContainer):
                            # Will need to do the search by ID for playlists as the text method
                            # does not work
                            self._addDirectory(item, folderName, totalEntries, subCategory, item.item_id)
                        else:
                            self._addDirectory(item, folderName, totalEntries, subCategory)
                    # No longer the first item
                    isFirstItem = False  # noqa PEP8

                # Add the number returned this time to the running total
                totalCollected = totalCollected + numberReturned
            del sonosDevice

        xbmcplugin.endOfDirectory(self.addon_handle)
Esempio n. 13
0
    def processFolderMessage(self, folderName, subCategory=""):
        sonosDevice = Sonos.createSonosDevice()

        # Make sure a Sonos speaker was found
        if sonosDevice is not None:
            # Process the sub-category
            if subCategory is None:
                subCategory = ""

            totalCollected = 0
            totalEntries = 1

            isFirstItem = True

            # Need to get all the tracks in batches
            while (totalCollected < totalEntries) and not self._listLimitReached(totalCollected):
                # make the call to get the tracks in batches of 100

                # Get the items from the sonos system
                list = None
                try:
                    if (subCategory is None) or (subCategory == ""):
                        list = sonosDevice.music_library.get_music_library_information(
                            folderName, totalCollected, Settings.getBatchSize(), True
                        )
                    else:
                        # Make sure the sub category is valid for the message, escape invalid characters
                        # subCategory = urllib.quote(subCategory)
                        # Call the browse version
                        list = sonosDevice.music_library.browse_by_idstring(
                            folderName, subCategory, totalCollected, Settings.getBatchSize(), True
                        )
                except:
                    log("SonosPlugin: %s" % traceback.format_exc(), xbmc.LOGERROR)
                    xbmcgui.Dialog().ok(
                        __addon__.getLocalizedString(32068),
                        __addon__.getLocalizedString(32069) % (folderName, subCategory),
                    )
                    return

                # Processes the list returned from Sonos, creating the list display on the screen
                totalEntries = list.total_matches
                log("SonosPlugin: Total %s Matches %d" % (folderName, totalEntries))
                numberReturned = list.number_returned
                log("SonosPlugin: Total %s in this batch %d" % (folderName, numberReturned))

                # Makes sure some items are returned
                if numberReturned < 1:
                    numberReturned = len(list)
                    if numberReturned < 1:
                        log("SonosPlugin: Zero items returned from request")
                        break

                for item in list:
                    # Check if this item is a track of a directory
                    if isinstance(item, soco.data_structures.DidlMusicTrack):
                        self._addTrack(item, totalEntries, folderName)
                    else:
                        # Check for the special case where there is an "All" first in the list
                        # For this the id and parent values are the same.  The All item
                        # is a special case and does not handle like a normal directory
                        if ("sameArtist" in item.item_class) or ("albumlist" in item.item_class):
                            log('SonosPlugin: Skipping "All" item for %s' % item.title)
                            isFirstItem = False
                            continue

                        # Check to see if we are dealing with a sonos playlist
                        if isinstance(item, soco.data_structures.DidlPlaylistContainer):
                            # Will need to do the search by ID for playlists as the text method
                            # does not work
                            self._addDirectory(item, folderName, totalEntries, subCategory, item.item_id)
                        else:
                            self._addDirectory(item, folderName, totalEntries, subCategory)
                    # No longer the first item
                    isFirstItem = False  # noqa PEP8

                # Add the number returned this time to the running total
                totalCollected = totalCollected + numberReturned
            del sonosDevice

        xbmcplugin.endOfDirectory(self.addon_handle)
Esempio n. 14
0
    def populateQueueList(self):
        sonosDevice = Sonos.createSonosDevice()

        # Make sure a Sonos speaker was found
        if sonosDevice is not None:
            totalCollected = 0
            numberReturned = Settings.getBatchSize()

            # Need to get all the tracks in batches
            # Only get the next batch if all the items requested were in the last batch
            while (numberReturned == Settings.getBatchSize()) and not self._listLimitReached(totalCollected):
                # Get the items from the sonos system
                list = None
                try:
                    list = sonosDevice.get_queue(totalCollected, Settings.getBatchSize(), True)
                except:
                    log("SonosPlugin: %s" % traceback.format_exc(), xbmc.LOGERROR)
                    xbmcgui.Dialog().ok(__addon__.getLocalizedString(32068), __addon__.getLocalizedString(32070))
                    return

                # Processes the list returned from Sonos, creating the list display on the screen
                numberReturned = len(list)
                log("SonosPlugin: Total queue entries in this batch %d" % numberReturned)

                itemNum = 0

                for item in list:
                    # Get a suitable display title
                    displayTitle = None
                    if (item.creator is not None) and (item.creator != ""):
                        displayTitle = "%s - %s" % (item.title, item.creator)
                    else:
                        displayTitle = item.title

                    # Create the list item for the track
                    if (
                        hasattr(item, "album_art_uri")
                        and (item.album_art_uri is not None)
                        and (item.album_art_uri != "")
                    ):
                        li = xbmcgui.ListItem(
                            displayTitle, iconImage=item.album_art_uri, thumbnailImage=item.album_art_uri
                        )
                    else:
                        li = xbmcgui.ListItem(displayTitle, iconImage=MediaFiles.TracksIcon)
                    # Set addition information about the track - will be seen in info view
                    li.setInfo("music", {"title": item.title, "artist": item.creator, "album": item.album})

                    # Create the action to be performed when clicking a queue item
                    url = self._build_url(
                        {"mode": "action", "action": ActionManager.ACTION_QUEUE_PLAY_ITEM, "itemId": itemNum}
                    )

                    # Add the context menu for the queue
                    self._addQueueContextMenu(li, itemNum + totalCollected)
                    itemNum = itemNum + 1

                    xbmcplugin.addDirectoryItem(handle=self.addon_handle, url=url, listitem=li, isFolder=False)

                totalCollected = totalCollected + numberReturned
            del sonosDevice

        xbmcplugin.endOfDirectory(self.addon_handle)
Esempio n. 15
0
        if self.keymapCopied is True:
            try:
                xbmcvfs.delete(self.KEYMAPDESTFILE)
                log("KeyMaps: Removed custom keymap")
            except:
                log(
                    "KeyMaps: Failed to remove & load custom keymap: %s" %
                    traceback.format_exc(), xbmc.LOGERROR)

            # Force a re-load
            xbmc.executebuiltin('Action(reloadkeymaps)')


if __name__ == '__main__':

    sonosDevice = Sonos.createSonosDevice()

    # Make sure a Sonos speaker was found
    if sonosDevice is not None:
        # Setup the keymap for the controller
        keyMapCtrl = KeyMaps()
        keyMapCtrl.enable()

        try:
            if Settings.displayArtistInfo():
                sonosCtrl = SonosArtistSlideshow.createSonosArtistSlideshow(
                    sonosDevice)
            else:
                sonosCtrl = SonosControllerWindow.createSonosControllerWindow(
                    sonosDevice)
 def genre_selected(self, list_view, title, index):
      # Browse the artists for this genre
     scene = SelectArtist(self.sonos,title,Sonos.browse(self.genres[index]))
     self.add_child(scene)
Esempio n. 17
0
def run():
    alarm1 = Sonos()
    alarm1.play_audio()
 def artist_selected(self, list_view, title, index):
     # Browse the albums for this artist
     scene = SelectAlbum(self.sonos, title,
                         Sonos.browse(self.artists[index]))
     self.add_child(scene)
Esempio n. 19
0
 def __init__(self):
     self.sonosDevice = Sonos.createSonosDevice()