mirror of
https://github.com/cooperhammond/irs.git
synced 2025-02-27 23:16:46 +00:00
Fixed another bug with the album downloading and updated README.
This commit is contained in:
parent
570651980b
commit
70b3c8447b
|
@ -19,6 +19,9 @@ optional arguments:
|
|||
-s SONG, --song SONG Specify song name of the artist
|
||||
```
|
||||
[](https://asciinema.org/a/bcs7i0sjmka052wsdyxg5xrug?speed=3&autoplay=true)
|
||||
|
||||
[](https://asciinema.org/a/8kb9882j4cbtd4hwbsbb7h0ia?speed=3&autoplay=true)
|
||||
|
||||
___
|
||||
### Installation
|
||||
```
|
||||
|
@ -36,4 +39,4 @@ For Ubuntu:
|
|||
```
|
||||
$ sudo apt-get install ffmpeg
|
||||
```
|
||||
<sub><sup>Most other linux distros have `ffmpeg` or `libav-tools` in their package manager repos, so you can install one or the other for other distros.<sup><sub>
|
||||
Most other linux distros have `ffmpeg` or `libav-tools` in their package manager repos, so you can install one or the other for other distros.
|
||||
|
|
|
@ -44,8 +44,12 @@ def find_mp3(song, artist):
|
|||
|
||||
return search_results[i]
|
||||
|
||||
def rip_album(album, artist, tried=False, search="album", album_url=None):
|
||||
def rip_album(album, artist,
|
||||
tried=False, # for if it can't find the album the first time
|
||||
search="album", # ditto
|
||||
):
|
||||
visible_texts = search_google(album, artist, search)
|
||||
errors = []
|
||||
try:
|
||||
songs = []
|
||||
num = True
|
||||
|
@ -70,11 +74,19 @@ def rip_album(album, artist, tried=False, search="album", album_url=None):
|
|||
else:
|
||||
pass
|
||||
|
||||
if album_url != None:
|
||||
album_url = get_albumart_url(album, artist)
|
||||
print ("")
|
||||
print (bc.HEADER + "Album Contents:" + bc.ENDC)
|
||||
for i, j in enumerate(songs):
|
||||
print (bc.OKBLUE + " - " + j + bc.ENDC)
|
||||
|
||||
album_art_url = get_albumart_url(album, artist)
|
||||
|
||||
for i, j in enumerate(songs):
|
||||
rip_mp3(j, artist, part_of_album=True, album=album, tracknum=i + 1, album_url=album_url)
|
||||
song = j
|
||||
rip_mp3(j, artist, part_of_album=True, album=album, tracknum=i + 1, album_art_url=album_art_url)
|
||||
|
||||
if errors.size > 0:
|
||||
for error in errors: print (error)
|
||||
|
||||
except Exception as e:
|
||||
if str(e) == "local variable 'indexed' referenced before assignment" or str(e) == 'list index out of range':
|
||||
|
@ -84,13 +96,22 @@ def rip_album(album, artist, tried=False, search="album", album_url=None):
|
|||
else:
|
||||
print (bc.FAIL + 'Could not find album "%s"' % album + bc.ENDC)
|
||||
else:
|
||||
print (bc.FAIL + 'There was an error getting the contents of "%s":' % album + bc.ENDC)
|
||||
print (e)
|
||||
errors.append(bc.FAIL + "There was a problem with downloading: " + bc.ENDC + song)
|
||||
print (bc.FAIL + "Something major went wrong: " + str(e) + bc.ENDC)
|
||||
pass
|
||||
|
||||
|
||||
def rip_mp3(song, artist, part_of_album=False, album="", tracknum="", album_url=None):
|
||||
def rip_mp3(song, artist,
|
||||
part_of_album=False, # neccessary for creating folders
|
||||
album=None, # if you want to specify an album and save a bit of time
|
||||
tracknum=None, # to specify the tracknumber in the album
|
||||
album_art_url=None # if you want to save a lot of time trying to find album cover.
|
||||
):
|
||||
|
||||
audio_code = find_mp3(song, artist)
|
||||
|
||||
filename = strip_special_chars(song) + ".mp3"
|
||||
|
||||
ydl_opts = {
|
||||
'format': 'bestaudio/best',
|
||||
#'quiet': True,
|
||||
|
@ -99,26 +120,32 @@ def rip_mp3(song, artist, part_of_album=False, album="", tracknum="", album_url=
|
|||
'preferredcodec': 'mp3',
|
||||
}],
|
||||
}
|
||||
|
||||
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
||||
ydl.download(["http://www.youtube.com/watch?v=" + audio_code])
|
||||
|
||||
|
||||
artist_folder = artist
|
||||
if not os.path.isdir(artist_folder):
|
||||
os.makedirs(artist_folder)
|
||||
if not part_of_album:
|
||||
location = artist_folder
|
||||
|
||||
if album != "" and part_of_album:
|
||||
|
||||
if album and part_of_album:
|
||||
album_folder = artist + "/" + album
|
||||
if not os.path.isdir(album_folder):
|
||||
os.makedirs(album_folder)
|
||||
location = album_folder
|
||||
|
||||
|
||||
for file in os.listdir("."):
|
||||
if audio_code in file:
|
||||
os.rename(file, location + "/" + filename)
|
||||
|
||||
parse_metadata(song, artist, location, filename, tracknum=tracknum, album=album, album_url=album_url)
|
||||
|
||||
print (color(song, ["BOLD", "UNDERLINE"]) + bc.OKGREEN + '" downloaded successfully!'+ bc.ENDC)
|
||||
parse_metadata(song, artist, location, filename, tracknum=tracknum, album=album, album_art_url=album_art_url)
|
||||
|
||||
|
||||
print (color(song, ["BOLD", "UNDERLINE"]) + bc.OKGREEN + ' downloaded successfully!'+ bc.ENDC)
|
||||
print ("")
|
||||
|
|
|
@ -36,9 +36,8 @@ def search_google(song, artist, search_terms=""):
|
|||
|
||||
return list(filter(visible, texts))
|
||||
|
||||
def parse_metadata(song, artist, location, filename, tracknum="", album="", album_url=None):
|
||||
def parse_metadata(song, artist, location, filename, tracknum="", album="", album_art_url=""):
|
||||
googled = search_google(song, artist)
|
||||
|
||||
mp3file = MP3("%s/%s" % (location, filename), ID3=EasyID3)
|
||||
|
||||
# Song title
|
||||
|
@ -54,8 +53,9 @@ def parse_metadata(song, artist, location, filename, tracknum="", album="", albu
|
|||
|
||||
print (bc.OKGREEN + "Artist parsed: " + bc.ENDC + mp3file['artist'][0])
|
||||
|
||||
|
||||
# Album
|
||||
if album == "":
|
||||
if not album:
|
||||
for i, j in enumerate(googled):
|
||||
if "Album:" in j:
|
||||
album = (googled[i + 1])
|
||||
|
@ -67,6 +67,7 @@ def parse_metadata(song, artist, location, filename, tracknum="", album="", albu
|
|||
|
||||
mp3file.save()
|
||||
|
||||
|
||||
# Release date
|
||||
for i, j in enumerate(googled):
|
||||
if "Released:" in j:
|
||||
|
@ -81,24 +82,25 @@ def parse_metadata(song, artist, location, filename, tracknum="", album="", albu
|
|||
|
||||
mp3file.save()
|
||||
|
||||
|
||||
# Track number
|
||||
if tracknum != "":
|
||||
if tracknum:
|
||||
mp3file['tracknumber'] = str(tracknum)
|
||||
mp3file.save()
|
||||
|
||||
|
||||
# Album art
|
||||
try:
|
||||
if album_url == None:
|
||||
album_url = get_albumart_url(album, artist)
|
||||
embed_mp3(album_url, location + "/" + filename)
|
||||
else:
|
||||
embed_mp3(album_url, location + "/" + filename)
|
||||
if not album_art_url:
|
||||
album_art_url = get_albumart_url(album, artist)
|
||||
embed_mp3(album_art_url, location + "/" + filename)
|
||||
else: # If part of an album, it should do this.
|
||||
embed_mp3(album_art_url, location + "/" + filename)
|
||||
|
||||
print (bc.OKGREEN + "Album art parsed: " + bc.ENDC + album_url)
|
||||
print (bc.OKGREEN + "Album art parsed: " + bc.ENDC + album_art_url)
|
||||
|
||||
except Exception as e:
|
||||
print (e)
|
||||
print (bc.FAIL + "Album art not parsed." + bc.ENDC)
|
||||
print (bc.FAIL + "Album art not parsed: " + bc.ENDC + e)
|
||||
|
||||
def embed_mp3(albumart_url, song_location):
|
||||
image = urlopen(albumart_url)
|
||||
|
|
Loading…
Reference in a new issue