Пример #1
0
    def change_song_metadata(self, songs):
        """Changes the metadata of tracks.
        Returns a list of the song ids changed.

        :param songs: a list of song dictionaries
          or a single song dictionary.

        Currently, only the ``rating`` key can be changed.
        Set it to ``'0'`` (no thumb), ``'1'`` (down thumb), or ``'5'`` (up thumb)
        unless you're using the 5-star ratings lab.

        You can also use this to rate All Access tracks
        that aren't in your library, eg::

            song = mc.get_track_info('<some store track id>')
            song['rating'] = '5'
            mc.change_song_metadata(song)

        """

        mutate_call = mobileclient.BatchMutateTracks
        mutations = [{'update': s} for s in songs]
        self._make_call(mutate_call, mutations)

        # TODO
        # store tracks don't send back their id, so we're
        # forced to spoof this
        return [utils.id_or_nid(d) for d in songs]
Пример #2
0
    def change_song_metadata(self, songs):
        """Changes the metadata of tracks.
        Returns a list of the song ids changed.

        :param songs: a list of song dictionaries
          or a single song dictionary.

        Currently, only the ``rating`` key can be changed.
        Set it to ``'0'`` (no thumb), ``'1'`` (down thumb), or ``'5'`` (up thumb)
        unless you're using the 5-star ratings lab.

        You can also use this to rate All Access tracks
        that aren't in your library, eg::

            song = mc.get_track_info('<some store track id>')
            song['rating'] = '5'
            mc.change_song_metadata(song)

        """

        mutate_call = mobileclient.BatchMutateTracks
        mutations = [{'update': s} for s in songs]
        self._make_call(mutate_call, mutations)

        # TODO
        # store tracks don't send back their id, so we're
        # forced to spoof this
        return [utils.id_or_nid(d) for d in songs]
    def _assert_song_rating(method, sid, rating):
        """
        :param method: eg self.mc.get_all_songs
        :param sid: song id
        :param rating: a string
        """
        songs = method()

        if not isinstance(songs, list):
            # kind of a hack to support get_track_info as well
            songs = [songs]

        found = [s for s in songs if id_or_nid(s) == sid]

        assert_equal(len(found), 1)

        assert_equal(found[0]['rating'], rating)
        return found[0]
Пример #4
0
    def _assert_song_rating(method, sid, rating):
        """
        :param method: eg self.mc.get_all_songs
        :param sid: song id
        :param rating: a string
        """
        songs = method()

        if not isinstance(songs, list):
            # kind of a hack to support get_track_info as well
            songs = [songs]

        found = [s for s in songs if id_or_nid(s) == sid]

        assert_equal(len(found), 1)

        assert_equal(found[0]['rating'], rating)
        return found[0]
Пример #5
0
 def getStationTracks(self,station_id):
     import gmusicapi.utils.utils as utils
     listItems = []
     tracks = self.api.getStationTracks(station_id)
     for track in tracks:
         li = self.xbmcgui.ListItem(track['title'])
         li.setProperty('IsPlayable', 'true')
         li.setProperty('Music', 'true')
         url = '%s?action=play_song&song_id=%s' % (sys.argv[0],utils.id_or_nid(track).encode('utf8'))
         infos = {}
         for k,v in track.iteritems():
             if k in ('title','album','artist'):
                 url = url+'&'+repr(k)+'='+repr(v)
                 infos[k] = v
         li.setInfo(type='music', infoLabels=infos)
         li.setPath(url)
         listItems.append([url,li])
     return listItems
    def change_song_metadata(self, songs):
        """Changes the metadata of tracks.
        Returns a list of the song ids changed.

        :param songs: a list of song dictionaries
          or a single song dictionary.

        Not all keys can be changed.
        These keys are known to work:

        * ``rating``: this is a string!
                      set to '0' (no thumb), '1' (down thumb), or '5' (up thumb)
                      unless you're using the 5-star ratings lab
        * ``album``
        * ``albumArtist``
        * ``artist``
        * ``comment``
        * ``composer``
        * ``discNumber``
        * ``genre``
        * ``playCount``
        * ``title``
        * ``totalDiscCount``
        * ``totalTrackCount``
        * ``trackNumber``
        * ``year``

        You can also use this to rate All Access tracks
        that aren't in your library, eg::

            song = mc.get_track_info('<some store track id>')
            song['rating'] = '5'
            mc.change_song_metadata(song)

        """

        mutate_call = mobileclient.BatchMutateTracks
        mutations = [{'update': s} for s in songs]
        self._make_call(mutate_call, mutations)

        #TODO
        # store tracks don't send back their id, so we're
        # forced to spoof this
        return [utils.id_or_nid(d) for d in songs]
Пример #7
0
    def change_song_metadata(self, songs):
        """Changes the metadata of tracks.
        Returns a list of the song ids changed.

        :param songs: a list of song dictionaries
          or a single song dictionary.

        Not all keys can be changed.
        These keys are known to work:

        * ``rating``: this is a string!
                      set to '0' (no thumb), '1' (down thumb), or '5' (up thumb)
                      unless you're using the 5-star ratings lab
        * ``album``
        * ``albumArtist``
        * ``artist``
        * ``comment``
        * ``composer``
        * ``discNumber``
        * ``genre``
        * ``playCount``
        * ``title``
        * ``totalDiscCount``
        * ``totalTrackCount``
        * ``trackNumber``
        * ``year``

        You can also use this to rate All Access tracks
        that aren't in your library, eg::

            song = mc.get_track_info('<some store track id>')
            song['rating'] = '5'
            mc.change_song_metadata(song)

        """

        mutate_call = mobileclient.BatchMutateTracks
        mutations = [{'update': s} for s in songs]
        self._make_call(mutate_call, mutations)

        #TODO
        # store tracks don't send back their id, so we're
        # forced to spoof this
        return [utils.id_or_nid(d) for d in songs]
Пример #8
0
    def _assert_song_key_equal_to(method, sid, key, value):
        """
        :param method: eg self.mc.get_all_songs
        :param sid: song id
        :param key: eg 'rating'
        :param value: eg '1'
        """
        songs = method()

        if not isinstance(songs, list):
            # kind of a hack to support get_track_info as well
            songs = [songs]

        found = [s for s in songs if id_or_nid(s) == sid]

        assert_equal(len(found), 1)

        assert_equal(found[0][key], value)
        return found[0]
Пример #9
0
    def _assert_song_key_equal_to(method, sid, key, value):
        """
        :param method: eg self.mc.get_all_songs
        :param sid: song id
        :param key: eg 'rating'
        :param value: eg '1'
        """
        songs = method()

        if not isinstance(songs, list):
            # kind of a hack to support get_track_info as well
            songs = [songs]

        found = [s for s in songs if id_or_nid(s) == sid]

        assert_equal(len(found), 1)

        assert_equal(found[0][key], value)
        return found[0]
Пример #10
0
 def getStationTracks(self, station_id):
     import gmusicapi.utils.utils as utils
     listItems = []
     tracks = self.api.getStationTracks(station_id)
     for track in tracks:
         li = self.xbmcgui.ListItem(track['title'])
         li.setProperty('IsPlayable', 'true')
         li.setProperty('Music', 'true')
         url = '%s?action=play_song&song_id=%s' % (
             sys.argv[0], utils.id_or_nid(track).encode('utf8'))
         infos = {}
         for k, v in track.iteritems():
             if k in ('title', 'album', 'artist'):
                 url = url + '&' + repr(k) + '=' + repr(v)
                 infos[k] = v
         li.setInfo(type='music', infoLabels=infos)
         li.setPath(url)
         listItems.append([url, li])
     return listItems