Skip to content
This repository has been archived by the owner on Jan 22, 2022. It is now read-only.

Commit

Permalink
add list tracks for music manager; fix bug in protocol merge
Browse files Browse the repository at this point in the history
  • Loading branch information
simon-weber committed Apr 21, 2013
1 parent e465aad commit 71a8351
Show file tree
Hide file tree
Showing 6 changed files with 429 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -4,6 +4,7 @@ Thumbs.db
\#*\# \#*\#
.\#* .\#*
.*.swp .*.swp
*.un~
.*.swo .*.swo
*.tmproj *.tmproj


Expand Down
51 changes: 51 additions & 0 deletions gmusicapi/clients.py
Expand Up @@ -288,6 +288,57 @@ def logout(self, revoke_oauth=False):


return success and super(Musicmanager, self).logout() return success and super(Musicmanager, self).logout()


# mostly copy-paste from Webclient.get_all_songs.
# not worried about overlap in this case; the logic of either could change.
def get_all_songs(self, incremental=False):
"""Returns a list of dictionaries, each with the following keys:
``('id', 'title', 'album', 'album_artist', 'artist', 'track_number',
'track_size')``.
:param incremental: if True, return a generator that yields lists
of at most 1000 dictionaries
as they are retrieved from the server. This can be useful for
presenting a loading bar to a user.
"""

to_return = self._get_all_songs()

if not incremental:
to_return = [song for chunk in to_return for song in chunk]

return to_return

@staticmethod
def _track_info_to_dict(track_info):
"""Given a download_pb2.DownloadTrackInfo, return a dictionary."""
# figure it's better to hardcode keys here than use introspection
# and risk returning a new field all of a sudden.

return dict((field, getattr(track_info, field)) for field in
('id', 'title', 'album', 'album_artist', 'artist',
'track_number', 'track_size'))

def _get_all_songs(self):
"""Return a generator of song chunks."""

get_next_chunk = True

# need to spoof .continuation_token access, and
# can't add attrs to object(). Can with functions.

lib_chunk = lambda: 0
lib_chunk.continuation_token = None

while get_next_chunk:
lib_chunk = self._make_call(musicmanager.ListTracks,
self.uploader_id,
lib_chunk.continuation_token)

yield [self._track_info_to_dict(info)
for info in lib_chunk.download_track_info]

get_next_chunk = lib_chunk.HasField('continuation_token')

# def get_quota(self): # def get_quota(self):
# """Returns a tuple of (allowed number of tracks, total tracks, available tracks).""" # """Returns a tuple of (allowed number of tracks, total tracks, available tracks)."""
# quota = self._mm_pb_call("client_state").quota # quota = self._mm_pb_call("client_state").quota
Expand Down
269 changes: 269 additions & 0 deletions gmusicapi/protocol/download_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 71a8351

Please sign in to comment.