|
@@ 3414-3467 (lines=54) @@
|
| 3411 |
|
|
| 3412 |
|
return Track(artist, title, self.network, self.name) |
| 3413 |
|
|
| 3414 |
|
def get_recent_tracks(self, limit=10, cacheable=True, |
| 3415 |
|
time_from=None, time_to=None): |
| 3416 |
|
""" |
| 3417 |
|
Returns this user's played track as a sequence of PlayedTrack objects |
| 3418 |
|
in reverse order of playtime, all the way back to the first track. |
| 3419 |
|
|
| 3420 |
|
Parameters: |
| 3421 |
|
limit : If None, it will try to pull all the available data. |
| 3422 |
|
from (Optional) : Beginning timestamp of a range - only display |
| 3423 |
|
scrobbles after this time, in UNIX timestamp format (integer |
| 3424 |
|
number of seconds since 00:00:00, January 1st 1970 UTC). This |
| 3425 |
|
must be in the UTC time zone. |
| 3426 |
|
to (Optional) : End timestamp of a range - only display scrobbles |
| 3427 |
|
before this time, in UNIX timestamp format (integer number of |
| 3428 |
|
seconds since 00:00:00, January 1st 1970 UTC). This must be in |
| 3429 |
|
the UTC time zone. |
| 3430 |
|
|
| 3431 |
|
This method uses caching. Enable caching only if you're pulling a |
| 3432 |
|
large amount of data. |
| 3433 |
|
|
| 3434 |
|
Use extract_items() with the return of this function to |
| 3435 |
|
get only a sequence of Track objects with no playback dates. |
| 3436 |
|
""" |
| 3437 |
|
|
| 3438 |
|
params = self._get_params() |
| 3439 |
|
if limit: |
| 3440 |
|
params['limit'] = limit |
| 3441 |
|
if time_from: |
| 3442 |
|
params['from'] = time_from |
| 3443 |
|
if time_to: |
| 3444 |
|
params['to'] = time_to |
| 3445 |
|
|
| 3446 |
|
seq = [] |
| 3447 |
|
for track in _collect_nodes( |
| 3448 |
|
limit, |
| 3449 |
|
self, |
| 3450 |
|
self.ws_prefix + ".getRecentTracks", |
| 3451 |
|
cacheable, |
| 3452 |
|
params): |
| 3453 |
|
|
| 3454 |
|
if track.hasAttribute('nowplaying'): |
| 3455 |
|
continue # to prevent the now playing track from sneaking in |
| 3456 |
|
|
| 3457 |
|
title = _extract(track, "name") |
| 3458 |
|
artist = _extract(track, "artist") |
| 3459 |
|
date = _extract(track, "date") |
| 3460 |
|
album = _extract(track, "album") |
| 3461 |
|
timestamp = track.getElementsByTagName( |
| 3462 |
|
"date")[0].getAttribute("uts") |
| 3463 |
|
|
| 3464 |
|
seq.append(PlayedTrack( |
| 3465 |
|
Track(artist, title, self.network), album, date, timestamp)) |
| 3466 |
|
|
| 3467 |
|
return seq |
| 3468 |
|
|
| 3469 |
|
def get_id(self): |
| 3470 |
|
"""Returns the user ID.""" |
|
@@ 2429-2455 (lines=27) @@
|
| 2426 |
|
|
| 2427 |
|
return self.country |
| 2428 |
|
|
| 2429 |
|
def _get_chart( |
| 2430 |
|
self, method, tag="artist", limit=None, from_date=None, |
| 2431 |
|
to_date=None, cacheable=True): |
| 2432 |
|
"""Internal helper for getting geo charts.""" |
| 2433 |
|
params = self._get_params() |
| 2434 |
|
if limit: |
| 2435 |
|
params["limit"] = limit |
| 2436 |
|
if from_date and to_date: |
| 2437 |
|
params["from"] = from_date |
| 2438 |
|
params["to"] = to_date |
| 2439 |
|
|
| 2440 |
|
doc = self._request(method, cacheable, params) |
| 2441 |
|
|
| 2442 |
|
seq = [] |
| 2443 |
|
for node in doc.getElementsByTagName(tag): |
| 2444 |
|
if tag == "artist": |
| 2445 |
|
item = Artist(_extract(node, "name"), self.network) |
| 2446 |
|
elif tag == "track": |
| 2447 |
|
title = _extract(node, "name") |
| 2448 |
|
artist = _extract_element_tree(node).get('artist')['name'] |
| 2449 |
|
item = Track(artist, title, self.network) |
| 2450 |
|
else: |
| 2451 |
|
return None |
| 2452 |
|
weight = _number(_extract(node, "listeners")) |
| 2453 |
|
seq.append(TopItem(item, weight)) |
| 2454 |
|
|
| 2455 |
|
return seq |
| 2456 |
|
|
| 2457 |
|
def get_artist_chart( |
| 2458 |
|
self, tag="artist", limit=None, from_date=None, to_date=None, |