Skip to content

IndexError in get_recent_tracks when now_playing=True #422

Open
@ndm13

Description

What did you do?

Called get_recent_tracks on the current pylast user, with now_playing set to True and a track currently playing.

What did you expect to happen?

The returned history should include the requested number of tracks, including the currently playing one at the top.

What actually happened?

Received IndexError: list index out of range in _extract_played_track line 2211.

What versions are you using?

  • OS: Windows 10 x64
  • Python: 3.10
  • pylast: 5.1.0

Please include code that reproduces the issue.

import pylast

last = pylast.LastFMNetwork(API_KEY, API_SECRET, USER_TOKEN, USER_NAME)
for track in last.get_authenticated_user().get_recent_tracks(now_playing=True):
    print(track)
Traceback (most recent call last):
  File "X:\project-root\scratch.py", line 9, in <module>
    for track in last.get_authenticated_user().get_recent_tracks(now_playing=True):
  File "X:\project-root\venv\lib\site-packages\pylast\__init__.py", line 2359, in get_recent_tracks
    return _get_recent_tracks() if stream else list(_get_recent_tracks())
  File "X:\project-root\venv\lib\site-packages\pylast\__init__.py", line 2356, in _get_recent_tracks
    yield self._extract_played_track(track_node=track_node)
  File "X:\project-root\venv\lib\site-packages\pylast\__init__.py", line 2211, in _extract_played_track
    timestamp = track_node.getElementsByTagName("date")[0].getAttribute("uts")
IndexError: list index out of range

Note that the code behaves as expected when now_playing=False or when the user is not currently playing something. I searched the issues and found #33 which seems to match this, but it's a very old issue.

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions