mirror of
https://github.com/cooperhammond/irs.git
synced 2025-01-08 20:05:27 +00:00
Single song downloading is working.
This commit is contained in:
parent
be13b60ba6
commit
3ccc7d50e9
|
@ -2,6 +2,7 @@
|
||||||
from mutagen.mp3 import MP3, EasyMP3
|
from mutagen.mp3 import MP3, EasyMP3
|
||||||
from mutagen.easyid3 import EasyID3
|
from mutagen.easyid3 import EasyID3
|
||||||
from mutagen.id3 import * # There's A LOT of stuff to import, forgive me.
|
from mutagen.id3 import * # There's A LOT of stuff to import, forgive me.
|
||||||
|
from mutagen.id3 import APIC
|
||||||
|
|
||||||
# System
|
# System
|
||||||
import sys
|
import sys
|
||||||
|
@ -35,8 +36,8 @@ class Metadata:
|
||||||
|
|
||||||
def add_tag(self, tag, data):
|
def add_tag(self, tag, data):
|
||||||
# For valid tags: `EasyID3.valid_keys.keys()`
|
# For valid tags: `EasyID3.valid_keys.keys()`
|
||||||
audio[tag] = data
|
self.mp3[tag] = data
|
||||||
audio.save()
|
self.mp3.save()
|
||||||
|
|
||||||
def add_album_art(self, image_url):
|
def add_album_art(self, image_url):
|
||||||
mp3 = EasyMP3(self.location, ID3=ID3)
|
mp3 = EasyMP3(self.location, ID3=ID3)
|
||||||
|
@ -51,8 +52,8 @@ class Metadata:
|
||||||
)
|
)
|
||||||
mp3.save()
|
mp3.save()
|
||||||
|
|
||||||
def find_album(song, artist):
|
def find_album_and_track(song, artist):
|
||||||
tracks = self.spotify.search(q=song, type="track")
|
tracks = spotipy.Spotify().search(q=song, type="track")["tracks"]["items"]
|
||||||
for track in tracks:
|
for track in tracks:
|
||||||
if utils.blank_include(track["name"], song):
|
if utils.blank_include(track["name"], song):
|
||||||
if utils.blank_include(track["artists"][0]["name"], artist):
|
if utils.blank_include(track["artists"][0]["name"], artist):
|
||||||
|
@ -63,7 +64,6 @@ def parse_genre(genres):
|
||||||
genres.reverse()
|
genres.reverse()
|
||||||
genres = list(map(lambda x: x.replace("-", " "), genres))
|
genres = list(map(lambda x: x.replace("-", " "), genres))
|
||||||
genres.sort(key=lambda x: len(x.split()))
|
genres.sort(key=lambda x: len(x.split()))
|
||||||
print (genres)
|
|
||||||
return genres[0]
|
return genres[0]
|
||||||
else:
|
else:
|
||||||
return ""
|
return ""
|
|
@ -96,7 +96,7 @@ class Ripper:
|
||||||
search = title
|
search = title
|
||||||
if "artist" in self.args:
|
if "artist" in self.args:
|
||||||
search += " " + self.args["artist"]
|
search += " " + self.args["artist"]
|
||||||
list_of_lists = self.spotify.search(q=search, type="album")
|
list_of_lists = self.spotify.search(q=search, type="album")["albums"]["items"]
|
||||||
elif type == "playlist":
|
elif type == "playlist":
|
||||||
list_of_lists = self.spotify.user_playlists(username)
|
list_of_lists = self.spotify.user_playlists(username)
|
||||||
|
|
||||||
|
@ -113,7 +113,7 @@ class Ripper:
|
||||||
break
|
break
|
||||||
if the_list != None:
|
if the_list != None:
|
||||||
print ('"%s" by "%s"' % (the_list["name"], the_list["artists"][0]["name"]))
|
print ('"%s" by "%s"' % (the_list["name"], the_list["artists"][0]["name"]))
|
||||||
compilation = False
|
compilation = ""
|
||||||
if type == "album":
|
if type == "album":
|
||||||
tmp_albums = []
|
tmp_albums = []
|
||||||
tmp_artists = []
|
tmp_artists = []
|
||||||
|
@ -123,7 +123,7 @@ class Ripper:
|
||||||
tmp_albums = list(set(tmp_albums))
|
tmp_albums = list(set(tmp_albums))
|
||||||
tmp_artists = list(set(tmp_artists))
|
tmp_artists = list(set(tmp_artists))
|
||||||
if len(tmp_albums) == 1 and len(tmp_artists) > 1:
|
if len(tmp_albums) == 1 and len(tmp_artists) > 1:
|
||||||
compilation = True
|
compilation = "true"
|
||||||
|
|
||||||
tracks = []
|
tracks = []
|
||||||
file_prefix = ""
|
file_prefix = ""
|
||||||
|
@ -137,7 +137,7 @@ class Ripper:
|
||||||
"name": track["name"],
|
"name": track["name"],
|
||||||
"artist": track["artists"][0]["name"],
|
"artist": track["artists"][0]["name"],
|
||||||
"album": track["album"],
|
"album": track["album"],
|
||||||
"genre": track["artists"][0]["genres"],
|
"genre": self.spotify.artist(track["artists"][0]["uri"])["genres"],
|
||||||
"track_number": track["track_number"],
|
"track_number": track["track_number"],
|
||||||
"disc_number": track["disc_number"],
|
"disc_number": track["disc_number"],
|
||||||
"compilation": compilation,
|
"compilation": compilation,
|
||||||
|
@ -152,7 +152,7 @@ class Ripper:
|
||||||
print ('Could not find any lists.')
|
print ('Could not find any lists.')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def list(list_data):
|
def list(self, list_data):
|
||||||
locations = []
|
locations = []
|
||||||
with open(".irs-download-log", "w+") as file:
|
with open(".irs-download-log", "w+") as file:
|
||||||
file.write(utils.format_download_log_data(list_data))
|
file.write(utils.format_download_log_data(list_data))
|
||||||
|
@ -167,7 +167,7 @@ class Ripper:
|
||||||
os.remove(".irs-download-log")
|
os.remove(".irs-download-log")
|
||||||
return locations
|
return locations
|
||||||
|
|
||||||
def song(song=None, artist=None, data={}):
|
def song(self, song=None, artist=None, data={}):
|
||||||
try:
|
try:
|
||||||
if not song: song = self.args["song_title"]
|
if not song: song = self.args["song_title"]
|
||||||
if not artist: artist = self.args["artist"]
|
if not artist: artist = self.args["artist"]
|
||||||
|
@ -207,14 +207,16 @@ class Ripper:
|
||||||
if data == False:
|
if data == False:
|
||||||
if "album" not in self.args:
|
if "album" not in self.args:
|
||||||
album, track = find_album_and_track(song, artist)
|
album, track = find_album_and_track(song, artist)
|
||||||
|
album = self.spotify.album(album["uri"])
|
||||||
|
track = self.spotify.track(track["uri"])
|
||||||
else:
|
else:
|
||||||
album = self.args["album"]
|
album = self.args["album"]
|
||||||
if album != None:
|
if album != None:
|
||||||
genre = album["artists"][0]["genres"]
|
genre = self.spotify.artist(album["artists"][0]["uri"])["genres"]
|
||||||
|
|
||||||
album_name = ""
|
album_name = ""
|
||||||
if album:
|
if album:
|
||||||
if utils.check_garbage_phrases(["remastered", "explicit"], album.name, "")
|
if utils.check_garbage_phrases(["remastered", "explicit"], album["name"], ""):
|
||||||
album_name = album["name"].split(" (")[0]
|
album_name = album["name"].split(" (")[0]
|
||||||
else:
|
else:
|
||||||
album_name = album["name"]
|
album_name = album["name"]
|
||||||
|
@ -224,18 +226,23 @@ class Ripper:
|
||||||
# Ease of Variables (copyright) (patent pending) (git yer filthy hands off)
|
# Ease of Variables (copyright) (patent pending) (git yer filthy hands off)
|
||||||
#
|
#
|
||||||
# *5 Minutes Later*
|
# *5 Minutes Later*
|
||||||
# Depecrated. It won't be the next big thing. :(
|
# Deprecated. It won't be the next big thing. :(
|
||||||
|
|
||||||
|
|
||||||
m = Metadata(file_name)
|
m = Metadata(file_name)
|
||||||
|
|
||||||
m.add_tag( "title", song)
|
m.add_tag( "title", song)
|
||||||
m.add_tag( "artist", artist)
|
m.add_tag( "artist", artist)
|
||||||
m.add_tag( "comment", "Downloaded from: %s\n Video Title: %s" % (video_url, video_title))
|
#m.add_tag( "comment", "Downloaded from: %s\n Video Title: %s" % (video_url, video_title))
|
||||||
if album:
|
if album:
|
||||||
m.add_tag("album", album_name)
|
m.add_tag("album", album_name)
|
||||||
m.add_tag("genre", genre)
|
m.add_tag("genre", genre)
|
||||||
m.add_tag("compilation", compilation)
|
m.add_tag("tracknumber", str(track["track_number"]))
|
||||||
m.add_tag("tracknumber", track["track_number"])
|
m.add_tag("discnumber", str(track["disc_number"]))
|
||||||
m.add_tag("discnumber", track["disc_number"])
|
|
||||||
m.add_album_art( album["images"][0]["url"])
|
m.add_album_art( album["images"][0]["url"])
|
||||||
|
# TODO: GET THIS WORKING:
|
||||||
|
#if "compilation" in data:
|
||||||
|
# m.add_tag("compilation", data["compilation"])
|
||||||
|
|
||||||
|
|
||||||
|
Ripper().song("Stomp", "The Stone Foxes")
|
Loading…
Reference in a new issue