Skip to content

Commit

Permalink
prepare for release
Browse files Browse the repository at this point in the history
  • Loading branch information
jason136 committed Oct 27, 2021
1 parent 11fb9e5 commit 2afd633
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@

# Usage:
Requirements are Python and FFmpeg, reccomended latest versions but tested on Python 3.9 and FFmpeg 4.4.
FFpmeg must be installed and included in the PATH to avoid codec/encoding errors.

Used modules include youtube_dl, spotipy, os, requests, and mutagen
This repository does not include any executebles, so these modules will have to be installed for the script to work.

The script can be executed to download music from the python console (sparks joy) or by importing and calling its helper methods (does not spark joy, you will have to see the messy code). Helper methods will be documented below the python console how-to.
The main.py can be executed to download music from the python console (sparks joy), while importing and calling its helper methods also works (does not spark joy, you will have to see the messy code). Helper methods will be documented below the console method how-to.

If it does not already exist, the script will create a directory in its location called 'out', where all music will be downloaded to.

A general usage tip: the script will encounter 403 Forbidden errors but will recovery and retry the download automatically. If the script seems stuck, please close the instance and try the download again; the script will pick up from where it left off.

If you notice your wifi speed is slower but your cpu is stronger, consider increasing the number of active threads. This can be done by changing the variable at the top of [mp3_dl.py](mp3_dl.py), the default value is 10. Conversely, if your wifi is fast but cpu is slow, consider decreasing this number for better results.

# Spotify
Music downloaded from Spotify will include title, album, artist, track number, and album art metadata embedded in the mp3 as an ID3 tag.

Expand Down Expand Up @@ -48,7 +53,6 @@ All music is downloaded from YouTube
- Artists sometimes add cutscenes or sound effects

All of these are remedied to an extent, ie matching up the closest song duration and looking for best audio quality, but it will not be perfect for everything.
on das a lie actwaly i was only thinking abt the duration thing but im thinking long abt it an itll be soon

# Reference
```python
Expand Down
4 changes: 2 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import os, spotipy, subprocess
import os, spotipy
from requests.exceptions import ConnectionError

import mp3_dl
Expand All @@ -18,7 +18,7 @@ def process_input(link):
return
track = mp3_dl.sp.track(link)
mp3_dl.dl_sp_track(track, silent=False)

elif 'open.spotify.com/playlist/' in link:
try:
playlist = mp3_dl.sp.playlist(playlist_id=link)
Expand Down
11 changes: 6 additions & 5 deletions mp3_dl.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
from youtube_dl.utils import DownloadError
from requests.exceptions import HTTPError

root = os.getcwd()
number_of_threads = 10

root = os.getcwd()
q = queue.Queue()
sp = None

count = 0
total = 0

Expand All @@ -23,6 +23,7 @@
}],
'extractaudio': True,
'audioformat': 'mp3',
'ffmpeg-location': os.getcwd() + '/ffmpeg/ffmpeg.exe',
'hls-prefer-ffmpeg': True,
'outtmpl': '%(id)s.%(ext)s',
'restrictfilenames': True,
Expand Down Expand Up @@ -58,7 +59,7 @@ def dl_yt_playlist(link, silent=False):
global count, total
total = len(result['entries'])
count = 0
for i in range(10):
for i in range(number_of_threads):
t = threading.Thread(target=yt_playlist_worker)
t.daemon = True
t.start()
Expand Down Expand Up @@ -173,7 +174,7 @@ def dl_spotify(input_link, silent=False):
tracks = playlist['items']
total = total + len(tracks)

for i in range(10):
for i in range(number_of_threads):
t = threading.Thread(target=sp_playlist_worker)
t.daemon = True
t.start()
Expand Down Expand Up @@ -268,7 +269,7 @@ def dl_sp_track(track, silent=True, album=None):
except Exception as e:
if isinstance(e, KeyboardInterrupt):
raise e
print('ERROR: ID3 tags unable to be written.')
if not ('Errno 13' in str(e)): print('ERROR: ID3 tags unable to be written.')

os.remove(thumbnail_name)
if not silent:
Expand Down

0 comments on commit 2afd633

Please sign in to comment.