示例#1
0
文件: plugin.py 项目: noba3/KoTos
    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)
示例#2
0
文件: plugin.py 项目: noba3/KoTos
    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)
示例#3
0
文件: plugin.py 项目: noba3/KoTos
    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)
示例#4
0
文件: default.py 项目: noba3/KoTos
    # 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")
示例#5
0
文件: plugin.py 项目: noba3/KoTos
 def __init__(self):
     self.sonosDevice = Sonos.createSonosDevice()
示例#6
0
文件: plugin.py 项目: noba3/KoTos
    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)
示例#7
0
文件: plugin.py 项目: noba3/KoTos
    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)
示例#8
0
文件: default.py 项目: noba3/KoTos
        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)
示例#9
0
文件: plugin.py 项目: noba3/KoTos
 def __init__(self):
     self.sonosDevice = Sonos.createSonosDevice()
示例#10
0
文件: plugin.py 项目: noba3/KoTos
    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)