Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bug when playing local files #27

Merged
merged 2 commits into from
Aug 24, 2024

Conversation

holy-jesus
Copy link
Contributor

@holy-jesus holy-jesus commented Aug 24, 2024

Local files doesn't have track["item"]["id"], so when it tries to get audio_features it passes None as track_id, and it causes this exception.

An exception occurred: 'NoneType' object is not iterable
Traceback (most recent call last):
  File "/home/user/.local/opt/activitywatch/aw-watcher-spotify/aw_watcher_spotify/main.py", line 155, in main
    and last_track_data["uri"] != data_from_track(track, sp)["uri"]
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.local/opt/activitywatch/aw-watcher-spotify/aw_watcher_spotify/main.py", line 38, in data_from_track
    data = sp.audio_features(track["item"]["id"])[0] or {}
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.local/opt/activitywatch/aw-watcher-spotify/venv/lib64/python3.12/site-packages/spotipy/client.py", line 1752, in audio_features
    tlist = [self._get_id("track", t) for t in tracks]
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'NoneType' object is not iterable

Added check if track["item"]["id"] isn't empty, then get audio_features.


🚀 This description was created by Ellipsis for commit 7678bb4

Summary:

Fixes bug in aw_watcher_spotify/main.py by adding a check for track["item"]["id"] before retrieving audio features, preventing errors with local files.

Key points:

  • Fixes bug in aw_watcher_spotify/main.py where local files lack track["item"]["id"].
  • Adds conditional check in data_from_track function to ensure track["item"]["id"] is not None before calling sp.audio_features.
  • Prevents TypeError when processing local files without track_id.

Generated with ❤️ by ellipsis.dev

Copy link

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looks good to me! Reviewed everything up to 7678bb4 in 11 seconds

More details
  • Looked at 16 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 1 drafted comments based on config settings.
1. aw_watcher_spotify/main.py:39
  • Draft comment:
    Consider checking if track["item"] is not None before accessing track["item"]["id"] to avoid potential KeyError.
  • Reason this comment was not posted:
    Decided after close inspection that this draft comment was likely wrong and/or not actionable:
    The comment is relevant to the changes made in the diff because it addresses a potential issue with accessing track["item"]["id"]. The diff added a check for track["item"]["id"], but not for track["item"], which could still lead to a KeyError. Therefore, the comment is valid and suggests a necessary code change.
    I might be overestimating the likelihood of track["item"] being None. If the context of the code ensures track["item"] is always present, the comment might not be necessary.
    Without additional context ensuring track["item"] is always present, it's safer to assume the comment is valid and keep it.
    Keep the comment as it addresses a potential issue related to the changes made in the diff.

Workflow ID: wflow_5LWHNPLaFwYKUgJg


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Copy link
Member

@ErikBjare ErikBjare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks!

aw_watcher_spotify/main.py Show resolved Hide resolved
@ErikBjare ErikBjare merged commit fe53cf6 into ActivityWatch:master Aug 24, 2024
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants