-- Fixed Issue #32\n-- Fixed Issue #33
This commit is contained in:
parent
c2f8333c7c
commit
7a2fad0110
58
pylast.py
58
pylast.py
|
@ -932,6 +932,7 @@ TopItem = _namedtuple("TopItem", ["item", "weight"])
|
||||||
SimilarItem = _namedtuple("SimilarItem", ["item", "match"])
|
SimilarItem = _namedtuple("SimilarItem", ["item", "match"])
|
||||||
LibraryItem = _namedtuple("LibraryItem", ["item", "playcount", "tagcount"])
|
LibraryItem = _namedtuple("LibraryItem", ["item", "playcount", "tagcount"])
|
||||||
PlayedTrack = _namedtuple("PlayedTrack", ["track", "playback_date", "timestamp"])
|
PlayedTrack = _namedtuple("PlayedTrack", ["track", "playback_date", "timestamp"])
|
||||||
|
LovedTrack = _namedtuple("LovedTrack", ["track", "date", "timestamp"])
|
||||||
ImageSizes = _namedtuple("ImageSizes", ["original", "large", "largesquare", "medium", "small", "extralarge"])
|
ImageSizes = _namedtuple("ImageSizes", ["original", "large", "largesquare", "medium", "small", "extralarge"])
|
||||||
Image = _namedtuple("Image", ["title", "url", "dateadded", "format", "owner", "sizes", "votes"])
|
Image = _namedtuple("Image", ["title", "url", "dateadded", "format", "owner", "sizes", "votes"])
|
||||||
Shout = _namedtuple("Shout", ["body", "author", "date"])
|
Shout = _namedtuple("Shout", ["body", "author", "date"])
|
||||||
|
@ -2708,18 +2709,32 @@ class User(_BaseObject):
|
||||||
return seq
|
return seq
|
||||||
|
|
||||||
def get_loved_tracks(self, limit=50):
|
def get_loved_tracks(self, limit=50):
|
||||||
"""Returns the loved tracks by this user
|
"""Returns this user's loved track as a sequence of LovedTrack objects
|
||||||
if limit is None, it will return all of them
|
in reverse order of their timestamp, all the way back to the first track.
|
||||||
"""
|
|
||||||
|
|
||||||
tracks = []
|
If limit==None, it will try to pull all the available data.
|
||||||
for track in _collect_nodes(limit, self, "user.getLovedTracks", False):
|
|
||||||
title = _extract(track, 'name', 0)
|
|
||||||
artist = _extract(track, 'name', 1)
|
|
||||||
|
|
||||||
tracks.append(Track(artist, title, self.network))
|
This method uses caching. Enable caching only if you're pulling a
|
||||||
|
large amount of data.
|
||||||
|
|
||||||
return tracks
|
Use extract_items() with the return of this function to
|
||||||
|
get only a sequence of Track objects with no playback dates. """
|
||||||
|
|
||||||
|
params = self._get_params()
|
||||||
|
if limit:
|
||||||
|
params['limit'] = _unicode(limit)
|
||||||
|
|
||||||
|
seq = []
|
||||||
|
for track in _collect_nodes(limit, self, "user.getLovedTracks", True, params):
|
||||||
|
|
||||||
|
title = _extract(track, "name")
|
||||||
|
artist = _extract(track, "name", 1)
|
||||||
|
date = _extract(track, "date")
|
||||||
|
timestamp = track.getElementsByTagName("date")[0].getAttribute("uts")
|
||||||
|
|
||||||
|
seq.append(LovedTrack(Track(artist, title, self.network), date, timestamp))
|
||||||
|
|
||||||
|
return seq
|
||||||
|
|
||||||
def get_neighbours(self, limit = 50):
|
def get_neighbours(self, limit = 50):
|
||||||
"""Returns a list of the user's friends."""
|
"""Returns a list of the user's friends."""
|
||||||
|
@ -2780,9 +2795,15 @@ class User(_BaseObject):
|
||||||
return Track(artist, title, self.network)
|
return Track(artist, title, self.network)
|
||||||
|
|
||||||
|
|
||||||
def get_recent_tracks(self, limit = None):
|
def get_recent_tracks(self, limit = 10):
|
||||||
"""Returns this user's recent listened-to tracks as
|
"""Returns this user's played track as a sequence of PlayedTrack objects
|
||||||
a sequence of PlayedTrack objects.
|
in reverse order of their playtime, all the way back to the first track.
|
||||||
|
|
||||||
|
If limit==None, it will try to pull all the available data.
|
||||||
|
|
||||||
|
This method uses caching. Enable caching only if you're pulling a
|
||||||
|
large amount of data.
|
||||||
|
|
||||||
Use extract_items() with the return of this function to
|
Use extract_items() with the return of this function to
|
||||||
get only a sequence of Track objects with no playback dates. """
|
get only a sequence of Track objects with no playback dates. """
|
||||||
|
|
||||||
|
@ -2790,18 +2811,17 @@ class User(_BaseObject):
|
||||||
if limit:
|
if limit:
|
||||||
params['limit'] = _unicode(limit)
|
params['limit'] = _unicode(limit)
|
||||||
|
|
||||||
doc = self._request('user.getRecentTracks', False, params)
|
|
||||||
|
|
||||||
seq = []
|
seq = []
|
||||||
for track in doc.getElementsByTagName('track'):
|
for track in _collect_nodes(limit, self, "user.getRecentTracks", True, params):
|
||||||
|
|
||||||
|
if track.hasAttribute('nowplaying'):
|
||||||
|
continue #to prevent the now playing track from sneaking in here
|
||||||
|
|
||||||
title = _extract(track, "name")
|
title = _extract(track, "name")
|
||||||
artist = _extract(track, "artist")
|
artist = _extract(track, "artist")
|
||||||
date = _extract(track, "date")
|
date = _extract(track, "date")
|
||||||
timestamp = track.getElementsByTagName("date")[0].getAttribute("uts")
|
timestamp = track.getElementsByTagName("date")[0].getAttribute("uts")
|
||||||
|
|
||||||
if track.hasAttribute('nowplaying'):
|
|
||||||
continue #to prevent the now playing track from sneaking in here
|
|
||||||
|
|
||||||
seq.append(PlayedTrack(Track(artist, title, self.network), date, timestamp))
|
seq.append(PlayedTrack(Track(artist, title, self.network), date, timestamp))
|
||||||
|
|
||||||
return seq
|
return seq
|
||||||
|
@ -3456,7 +3476,7 @@ def extract_items(topitems_or_libraryitems):
|
||||||
|
|
||||||
seq = []
|
seq = []
|
||||||
for i in topitems_or_libraryitems:
|
for i in topitems_or_libraryitems:
|
||||||
seq.append(i.get_item())
|
seq.append(i.item)
|
||||||
|
|
||||||
return seq
|
return seq
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue