mirror of
https://github.com/cooperhammond/irs.git
synced 2025-02-28 23:26:48 +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
|
-s SONG, --song SONG Specify song name of the artist
|
||||||
```
|
```
|
||||||
[](https://asciinema.org/a/bcs7i0sjmka052wsdyxg5xrug?speed=3&autoplay=true)
|
[](https://asciinema.org/a/bcs7i0sjmka052wsdyxg5xrug?speed=3&autoplay=true)
|
||||||
|
|
||||||
|
[](https://asciinema.org/a/8kb9882j4cbtd4hwbsbb7h0ia?speed=3&autoplay=true)
|
||||||
|
|
||||||
___
|
___
|
||||||
### Installation
|
### Installation
|
||||||
```
|
```
|
||||||
|
@ -36,4 +39,4 @@ For Ubuntu:
|
||||||
```
|
```
|
||||||
$ sudo apt-get install ffmpeg
|
$ 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]
|
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)
|
visible_texts = search_google(album, artist, search)
|
||||||
|
errors = []
|
||||||
try:
|
try:
|
||||||
songs = []
|
songs = []
|
||||||
num = True
|
num = True
|
||||||
|
@ -70,11 +74,19 @@ def rip_album(album, artist, tried=False, search="album", album_url=None):
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if album_url != None:
|
print ("")
|
||||||
album_url = get_albumart_url(album, artist)
|
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):
|
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:
|
except Exception as e:
|
||||||
if str(e) == "local variable 'indexed' referenced before assignment" or str(e) == 'list index out of range':
|
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:
|
else:
|
||||||
print (bc.FAIL + 'Could not find album "%s"' % album + bc.ENDC)
|
print (bc.FAIL + 'Could not find album "%s"' % album + bc.ENDC)
|
||||||
else:
|
else:
|
||||||
print (bc.FAIL + 'There was an error getting the contents of "%s":' % album + bc.ENDC)
|
errors.append(bc.FAIL + "There was a problem with downloading: " + bc.ENDC + song)
|
||||||
print (e)
|
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)
|
audio_code = find_mp3(song, artist)
|
||||||
|
|
||||||
filename = strip_special_chars(song) + ".mp3"
|
filename = strip_special_chars(song) + ".mp3"
|
||||||
|
|
||||||
ydl_opts = {
|
ydl_opts = {
|
||||||
'format': 'bestaudio/best',
|
'format': 'bestaudio/best',
|
||||||
#'quiet': True,
|
#'quiet': True,
|
||||||
|
@ -99,26 +120,32 @@ def rip_mp3(song, artist, part_of_album=False, album="", tracknum="", album_url=
|
||||||
'preferredcodec': 'mp3',
|
'preferredcodec': 'mp3',
|
||||||
}],
|
}],
|
||||||
}
|
}
|
||||||
|
|
||||||
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
||||||
ydl.download(["http://www.youtube.com/watch?v=" + audio_code])
|
ydl.download(["http://www.youtube.com/watch?v=" + audio_code])
|
||||||
|
|
||||||
|
|
||||||
artist_folder = artist
|
artist_folder = artist
|
||||||
if not os.path.isdir(artist_folder):
|
if not os.path.isdir(artist_folder):
|
||||||
os.makedirs(artist_folder)
|
os.makedirs(artist_folder)
|
||||||
if not part_of_album:
|
if not part_of_album:
|
||||||
location = artist_folder
|
location = artist_folder
|
||||||
|
|
||||||
if album != "" and part_of_album:
|
|
||||||
|
if album and part_of_album:
|
||||||
album_folder = artist + "/" + album
|
album_folder = artist + "/" + album
|
||||||
if not os.path.isdir(album_folder):
|
if not os.path.isdir(album_folder):
|
||||||
os.makedirs(album_folder)
|
os.makedirs(album_folder)
|
||||||
location = album_folder
|
location = album_folder
|
||||||
|
|
||||||
|
|
||||||
for file in os.listdir("."):
|
for file in os.listdir("."):
|
||||||
if audio_code in file:
|
if audio_code in file:
|
||||||
os.rename(file, location + "/" + filename)
|
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 ("")
|
print ("")
|
||||||
|
|
|
@ -36,9 +36,8 @@ def search_google(song, artist, search_terms=""):
|
||||||
|
|
||||||
return list(filter(visible, texts))
|
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)
|
googled = search_google(song, artist)
|
||||||
|
|
||||||
mp3file = MP3("%s/%s" % (location, filename), ID3=EasyID3)
|
mp3file = MP3("%s/%s" % (location, filename), ID3=EasyID3)
|
||||||
|
|
||||||
# Song title
|
# 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])
|
print (bc.OKGREEN + "Artist parsed: " + bc.ENDC + mp3file['artist'][0])
|
||||||
|
|
||||||
|
|
||||||
# Album
|
# Album
|
||||||
if album == "":
|
if not album:
|
||||||
for i, j in enumerate(googled):
|
for i, j in enumerate(googled):
|
||||||
if "Album:" in j:
|
if "Album:" in j:
|
||||||
album = (googled[i + 1])
|
album = (googled[i + 1])
|
||||||
|
@ -67,6 +67,7 @@ def parse_metadata(song, artist, location, filename, tracknum="", album="", albu
|
||||||
|
|
||||||
mp3file.save()
|
mp3file.save()
|
||||||
|
|
||||||
|
|
||||||
# Release date
|
# Release date
|
||||||
for i, j in enumerate(googled):
|
for i, j in enumerate(googled):
|
||||||
if "Released:" in j:
|
if "Released:" in j:
|
||||||
|
@ -81,24 +82,25 @@ def parse_metadata(song, artist, location, filename, tracknum="", album="", albu
|
||||||
|
|
||||||
mp3file.save()
|
mp3file.save()
|
||||||
|
|
||||||
|
|
||||||
# Track number
|
# Track number
|
||||||
if tracknum != "":
|
if tracknum:
|
||||||
mp3file['tracknumber'] = str(tracknum)
|
mp3file['tracknumber'] = str(tracknum)
|
||||||
mp3file.save()
|
mp3file.save()
|
||||||
|
|
||||||
|
|
||||||
# Album art
|
# Album art
|
||||||
try:
|
try:
|
||||||
if album_url == None:
|
if not album_art_url:
|
||||||
album_url = get_albumart_url(album, artist)
|
album_art_url = get_albumart_url(album, artist)
|
||||||
embed_mp3(album_url, location + "/" + filename)
|
embed_mp3(album_art_url, location + "/" + filename)
|
||||||
else:
|
else: # If part of an album, it should do this.
|
||||||
embed_mp3(album_url, location + "/" + filename)
|
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:
|
except Exception as e:
|
||||||
print (e)
|
print (bc.FAIL + "Album art not parsed: " + bc.ENDC + e)
|
||||||
print (bc.FAIL + "Album art not parsed." + bc.ENDC)
|
|
||||||
|
|
||||||
def embed_mp3(albumart_url, song_location):
|
def embed_mp3(albumart_url, song_location):
|
||||||
image = urlopen(albumart_url)
|
image = urlopen(albumart_url)
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -2,7 +2,7 @@ from setuptools import setup
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='irs',
|
name='irs',
|
||||||
version='1.1.3',
|
version='1.1.4',
|
||||||
description='A music downloader that just gets metadata.',
|
description='A music downloader that just gets metadata.',
|
||||||
url='https://github.com/kepoorhampond/irs',
|
url='https://github.com/kepoorhampond/irs',
|
||||||
author='Kepoor Hampond',
|
author='Kepoor Hampond',
|
||||||
|
|
Loading…
Reference in a new issue