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

youtube: skip songs that lack duration metadata #18

Closed
wants to merge 1 commit into from

Conversation

lucasrangit
Copy link

In my playlist Spotify did not return the duration for the following track.

{'resultType': 'video', 'title': 'Auditory Canvas - Spring Rain', 'views': None, 'videoId': None, 'year': None, 'artists': [], 'thumbnails': [{...}]}

Resulting in the following exception.


Traceback (most recent call last):
...
  File "/usr/lib/python3.8/runpy.py", line 95, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/usr/lib/python3.8/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "YouTube.py", line 191, in <module>
    main()
  File "YouTube.py", line 182, in main
    videoIds = ytmusic.search_songs(playlist['tracks'])
  File "YouTube.py", line 75, in search_songs
    targetSong = self.get_best_fit_song_id(result, song)
  File "YouTube.py", line 30, in get_best_fit_song_id
    if res['duration']:
KeyError: 'duration'
  • Instead of checking if the duration is not-None, check that is exists as a key in the res dictionary.

In my playlist Spotify did not return the duration for the following track.

```
{'resultType': 'video', 'title': 'Auditory Canvas - Spring Rain', 'views': None, 'videoId': None, 'year': None, 'artists': [], 'thumbnails': [{...}]}
```

Resulting in the following exception.
```

Traceback (most recent call last):
...
  File "/usr/lib/python3.8/runpy.py", line 95, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/usr/lib/python3.8/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "YouTube.py", line 191, in <module>
    main()
  File "YouTube.py", line 182, in main
    videoIds = ytmusic.search_songs(playlist['tracks'])
  File "YouTube.py", line 75, in search_songs
    targetSong = self.get_best_fit_song_id(result, song)
  File "YouTube.py", line 30, in get_best_fit_song_id
    if res['duration']:
KeyError: 'duration'
```

* Instead of checking if the duration is non-zero, check that is exists.
@lucasrangit lucasrangit changed the title youtube: skip songs that lack a duration from metadata youtube: skip songs that lack a duration metadata May 28, 2021
@lucasrangit lucasrangit changed the title youtube: skip songs that lack a duration metadata youtube: skip songs that lack duration metadata May 28, 2021
@sigma67
Copy link
Owner

sigma67 commented May 28, 2021

We should check both if the key exists and if it is None. In your PR it would now crash in cases it previously didn't.

@sigma67 sigma67 closed this in 7308332 May 28, 2021
@lucasrangit
Copy link
Author

Yeah, you're right. Do you have a sample playlist from Spotify that crashes because the duration value is None?

@lucasrangit lucasrangit deleted the missing-duration branch May 29, 2021 12:55
@sigma67
Copy link
Owner

sigma67 commented May 29, 2021

I don't have it anymore but it has definitely happened before or I wouldn't have added that part :)

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.

None yet

3 participants