Skip to content

Commit 5409bbf

Browse files
Continue to download the playlist if missing files (#172)
* update reqs * Continue to download the playlist if missing files Just a patch for the missing file's recurrent issue. It seems that for some reason, youtube_dl does not find some videos but does not throw an exception. * More precise reporting * add test creds, add clean up to makefile * run make tests * install ffmpeg on tests Co-authored-by: Sathyajith <[email protected]>
1 parent 572d1a8 commit 5409bbf

File tree

5 files changed

+22
-8
lines changed

5 files changed

+22
-8
lines changed

.github/workflows/run_tests.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ jobs:
3131
SPOTIPY_CLIENT_ID: ${{ secrets.SPOTIPY_CLIENT_ID }}
3232
SPOTIPY_CLIENT_SECRET: ${{ secrets.SPOTIPY_CLIENT_SECRET }}
3333
run: |
34-
pip install pytest pytest-cov
35-
pytest --cov=spotify_dl tests/
34+
sudo apt-get install ffmpeg
35+
make tests

Makefile

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
.PHONY: tests
1+
.PHONY: tests clean
2+
default: tests
23

3-
tests:
4+
clean:
5+
find . | grep -E "\(__pycache__|\.pyc|\.pyo$\)" | xargs rm -rf
6+
rm -f tests/*mp3
7+
rm -f tests/downloaded_songs.txt
8+
9+
tests: clean
410
pip install -e .
511
pip install pytest pytest-cov
612
pytest --cov=spotify_dl tests/

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
peewee==3.13.3
22
sentry_sdk==0.19.4
3-
youtube-dl>=2021.1.24.1
3+
youtube-dl>=2021.04.01
44
spotipy==2.16.1
55
mutagen==1.45.1
66
spotipy== 2.16.1

spotify_dl/youtube.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import urllib.request
22
from os import path
33

4+
import mutagen
45
import youtube_dl
56
from mutagen.easyid3 import EasyID3
67
from mutagen.id3 import APIC, ID3
@@ -65,7 +66,12 @@ def download_songs(songs, download_directory, format_string, skip_mp3,
6566
continue
6667

6768
if not skip_mp3:
68-
song_file = MP3(path.join(f"{file_path}.mp3"), ID3=EasyID3)
69+
try:
70+
song_file = MP3(path.join(f"{file_path}.mp3"), ID3=EasyID3)
71+
except mutagen.MutagenError as e:
72+
log.debug(e)
73+
print('Failed to download: {}, please ensure YouTubeDL is up-to-date. '.format(query))
74+
continue
6975
song_file['date'] = song.get('year')
7076
if keep_playlist_order:
7177
song_file['tracknumber'] = str(song.get('playlist_num'))

tests/test_spotify_fetch_tracks.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
from spotipy.oauth2 import SpotifyClientCredentials
22
from spotify_dl.spotify import fetch_tracks
33
import spotipy
4-
4+
import base64
55

66
def spotify_auth():
7-
client = spotipy.Spotify(auth_manager=SpotifyClientCredentials())
7+
# test client ids, b64 for just to deter.
8+
client = spotipy.Spotify(auth_manager=SpotifyClientCredentials(client_id=base64.b64decode('NjliZDE4ZjNiNDY3NGMyNTkwNTllMzE5YTQ1ZGQwMzY=').decode('ascii'),
9+
client_secret=base64.b64decode('NTczY2UwYmM2OWUzNDdkNzg3NjgwZDBlMzJmOTQ3MGM=').decode('ascii')))
810
return client
911

1012

0 commit comments

Comments
 (0)