mirror of
https://github.com/cooperhammond/irs.git
synced 2025-06-30 14:48:14 +00:00
Follows pep8 guides with more organization
This commit is contained in:
parent
04909589cf
commit
09a839aeab
30
irs/cli.py
30
irs/cli.py
|
@ -8,35 +8,42 @@ import os
|
||||||
# Powered by:
|
# Powered by:
|
||||||
from .ripper import Ripper
|
from .ripper import Ripper
|
||||||
from .utils import console, parse_default_flags
|
from .utils import console, parse_default_flags
|
||||||
from .config import CONFIG
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
|
|
||||||
# Single Song
|
# Single Song
|
||||||
parser.add_argument("-a", "--artist", dest="artist", help="Specify artist name. Must be used with -s/--song or -A/--album")
|
parser.add_argument("-a", "--artist", dest="artist", help="Specify artist \
|
||||||
parser.add_argument("-s", "--song", dest="song", help="Specify song name. Must be used with -a/--artist")
|
name. Must be used with -s/--song or -A/--album")
|
||||||
|
parser.add_argument("-s", "--song", dest="song", help="Specify song name.\
|
||||||
|
Must be used with -a/--artist")
|
||||||
|
|
||||||
# Album
|
# Album
|
||||||
parser.add_argument("-A", "--album", dest="album", help="Specify album name")
|
parser.add_argument("-A", "--album", dest="album", help="Specify album \
|
||||||
|
name")
|
||||||
|
|
||||||
# Playlist
|
# Playlist
|
||||||
parser.add_argument("-u", "--username", dest="username", help="Specify username. Must be used with -p/--playlist")
|
parser.add_argument("-u", "--username", dest="username", help="Specify \
|
||||||
parser.add_argument("-p", "--playlist", dest="playlist", help="Specify playlist name. Must be used with -u/--username")
|
username. Must be used with -p/--playlist")
|
||||||
|
parser.add_argument("-p", "--playlist", dest="playlist", help="Specify \
|
||||||
|
playlist name. Must be used with -u/--username")
|
||||||
|
|
||||||
# Post-Processors
|
# Post-Processors
|
||||||
parser.add_argument("-l", "--location", dest="location", help="Specify a directory to place files in.")
|
parser.add_argument("-l", "--location", dest="location", help="Specify a \
|
||||||
parser.add_argument("-o", "--organize", dest="organize", action="store_true", help="Organize downloaded files.")
|
directory to place files in.")
|
||||||
|
parser.add_argument("-o", "--organize", dest="organize",
|
||||||
|
action="store_true", help="Organize downloaded files.")
|
||||||
|
|
||||||
# Config
|
# Config
|
||||||
parser.add_argument("-c", "--config", dest="config", action="store_true", help="Display path to config file.")
|
parser.add_argument("-c", "--config", dest="config", action="store_true",
|
||||||
|
help="Display path to config file.")
|
||||||
|
|
||||||
args = parser.parse_args(parse_default_flags())
|
args = parser.parse_args(parse_default_flags())
|
||||||
|
|
||||||
if args.config:
|
if args.config:
|
||||||
import irs
|
import irs
|
||||||
print (os.path.dirname(irs.__file__) + "/config.py")
|
print(os.path.dirname(irs.__file__) + "/config.py")
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
ripper_args = {
|
ripper_args = {
|
||||||
|
@ -62,5 +69,6 @@ def main():
|
||||||
else:
|
else:
|
||||||
console(ripper)
|
console(ripper)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
|
@ -16,7 +16,8 @@ CONFIG = dict(
|
||||||
organize = True,
|
organize = True,
|
||||||
# True always forces organization.
|
# True always forces organization.
|
||||||
# False always forces non-organization.
|
# False always forces non-organization.
|
||||||
# None allows options and flags to determine if the files will be organized.
|
# None allows options and flags to determine if the files
|
||||||
|
# will be organized.
|
||||||
|
|
||||||
custom_directory = "",
|
custom_directory = "",
|
||||||
# Defaults to '~/Music'
|
# Defaults to '~/Music'
|
||||||
|
|
|
@ -1,12 +1,19 @@
|
||||||
# MP3 Metadata editing
|
# MP3 Metadata editing
|
||||||
from mutagen.mp3 import MP3, EasyMP3
|
from mutagen.mp3 import EasyMP3
|
||||||
from mutagen.easyid3 import EasyID3, EasyID3KeyError
|
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, ID3, COMM
|
from mutagen.id3 import APIC, ID3
|
||||||
|
|
||||||
# System
|
# System
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
# Powered by...
|
||||||
|
import spotipy
|
||||||
|
|
||||||
|
# Local utils
|
||||||
|
from .utils import ObjManip
|
||||||
|
om = ObjManip
|
||||||
|
|
||||||
# Info finding
|
# Info finding
|
||||||
if sys.version_info[0] >= 3:
|
if sys.version_info[0] >= 3:
|
||||||
from urllib.parse import quote_plus, quote
|
from urllib.parse import quote_plus, quote
|
||||||
|
@ -16,16 +23,6 @@ elif sys.version_info[0] < 3:
|
||||||
from urllib import urlopen
|
from urllib import urlopen
|
||||||
from urllib2 import Request
|
from urllib2 import Request
|
||||||
|
|
||||||
# Info parsing
|
|
||||||
import json
|
|
||||||
from re import match
|
|
||||||
from bs4 import BeautifulSoup
|
|
||||||
|
|
||||||
# Local utils
|
|
||||||
from .utils import *
|
|
||||||
|
|
||||||
# Powered by...
|
|
||||||
import spotipy
|
|
||||||
|
|
||||||
class Metadata:
|
class Metadata:
|
||||||
def __init__(self, location):
|
def __init__(self, location):
|
||||||
|
@ -58,14 +55,17 @@ class Metadata:
|
||||||
)
|
)
|
||||||
mp3.save()
|
mp3.save()
|
||||||
|
|
||||||
|
|
||||||
def find_album_and_track(song, artist):
|
def find_album_and_track(song, artist):
|
||||||
tracks = spotipy.Spotify().search(q=song, type="track")["tracks"]["items"]
|
tracks = spotipy.Spotify().search(q=song, type="track"
|
||||||
|
)["tracks"]["items"]
|
||||||
for track in tracks:
|
for track in tracks:
|
||||||
if blank_include(track["name"], song):
|
if om.blank_include(track["name"], song):
|
||||||
if blank_include(track["artists"][0]["name"], artist):
|
if om.blank_include(track["artists"][0]["name"], artist):
|
||||||
return track["album"], track
|
return track["album"], track
|
||||||
return False, False
|
return False, False
|
||||||
|
|
||||||
|
|
||||||
def parse_genre(genres):
|
def parse_genre(genres):
|
||||||
if genres != []:
|
if genres != []:
|
||||||
genres.reverse()
|
genres.reverse()
|
||||||
|
|
198
irs/ripper.py
198
irs/ripper.py
|
@ -8,6 +8,11 @@ import sys
|
||||||
import os
|
import os
|
||||||
import glob
|
import glob
|
||||||
|
|
||||||
|
# Local utilities
|
||||||
|
from .utils import YdlUtils, ObjManip, Config
|
||||||
|
from .metadata import Metadata
|
||||||
|
from .metadata import find_album_and_track, parse_genre
|
||||||
|
|
||||||
# Parsing
|
# Parsing
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
if sys.version_info[0] >= 3:
|
if sys.version_info[0] >= 3:
|
||||||
|
@ -17,12 +22,9 @@ elif sys.version_info[0] < 3:
|
||||||
from urllib import urlencode
|
from urllib import urlencode
|
||||||
from urllib import urlopen
|
from urllib import urlopen
|
||||||
else:
|
else:
|
||||||
print ("Must be using Python 2 or 3")
|
print("Must be using Python 2 or 3")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Local utilities
|
|
||||||
from .utils import *
|
|
||||||
from .metadata import *
|
|
||||||
|
|
||||||
class Ripper:
|
class Ripper:
|
||||||
def __init__(self, args={}):
|
def __init__(self, args={}):
|
||||||
|
@ -30,9 +32,15 @@ class Ripper:
|
||||||
self.locations = []
|
self.locations = []
|
||||||
self.type = None
|
self.type = None
|
||||||
try:
|
try:
|
||||||
CLIENT_ID, CLIENT_SECRET = parse_spotify_creds(self)
|
CLIENT_ID, CLIENT_SECRET = Config.parse_spotify_creds(self)
|
||||||
client_credentials_manager = SpotifyClientCredentials(CLIENT_ID, CLIENT_SECRET)
|
client_credentials_manager = SpotifyClientCredentials(CLIENT_ID,
|
||||||
self.spotify = spotipy.Spotify(client_credentials_manager=client_credentials_manager)
|
CLIENT_SECRET
|
||||||
|
# Stupid lint
|
||||||
|
)
|
||||||
|
|
||||||
|
self.spotify = spotipy.Spotify(
|
||||||
|
client_credentials_manager=client_credentials_manager)
|
||||||
|
|
||||||
self.authorized = True
|
self.authorized = True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.spotify = spotipy.Spotify()
|
self.spotify = spotipy.Spotify()
|
||||||
|
@ -40,12 +48,13 @@ class Ripper:
|
||||||
|
|
||||||
def post_processing(self, locations):
|
def post_processing(self, locations):
|
||||||
post_processors = self.args.get("post_processors")
|
post_processors = self.args.get("post_processors")
|
||||||
|
directory_option = Config.parse_directory(self)
|
||||||
if post_processors:
|
if post_processors:
|
||||||
if parse_directory(self) != None:
|
if directory_option is not None:
|
||||||
for index, loc in enumerate(locations):
|
for index, loc in enumerate(locations):
|
||||||
new_file_name = parse_directory(self) + "/" + loc
|
new_file_name = directory_option + "/" + loc
|
||||||
if not os.path.exists(parse_directory(self)):
|
if not os.path.exists(directory_option):
|
||||||
os.makedirs(parse_directory(self))
|
os.makedirs(directory_option)
|
||||||
os.rename(loc, new_file_name)
|
os.rename(loc, new_file_name)
|
||||||
locations[index] = new_file_name
|
locations[index] = new_file_name
|
||||||
# I'd just go on believing that code this terrible doesn't exist.
|
# I'd just go on believing that code this terrible doesn't exist.
|
||||||
|
@ -55,10 +64,11 @@ class Ripper:
|
||||||
# It's like loving someone,
|
# It's like loving someone,
|
||||||
# Everyone has some flaws, but you still appreciate and embrace
|
# Everyone has some flaws, but you still appreciate and embrace
|
||||||
# those flaws for being exclusive to them.
|
# those flaws for being exclusive to them.
|
||||||
# And if those flaws are really enough to turn you off of them, then
|
# And if those flaws are really enough to turn you off of them,
|
||||||
# you *probably* don't really want to be with them anyways.
|
# then you *probably* don't really want to be with them anyways.
|
||||||
# Either way, it's up to you.
|
# Either way, it's up to you.
|
||||||
if parse_organize(self):
|
|
||||||
|
if Config.parse_organize(self):
|
||||||
if self.type in ("album", "song"):
|
if self.type in ("album", "song"):
|
||||||
for index, loc in enumerate(locations):
|
for index, loc in enumerate(locations):
|
||||||
mp3 = Metadata(loc)
|
mp3 = Metadata(loc)
|
||||||
|
@ -68,10 +78,11 @@ class Ripper:
|
||||||
file_name = loc.split("/")[-1]
|
file_name = loc.split("/")[-1]
|
||||||
else:
|
else:
|
||||||
file_name = loc
|
file_name = loc
|
||||||
artist, album = mp3.read_tag("artist")[0], mp3.read_tag("album")
|
artist, album = mp3.read_tag("artist")[0]
|
||||||
new_loc += blank(artist, False)
|
album = mp3.read_tag("album")
|
||||||
|
new_loc += ObjManip.blank(artist, False)
|
||||||
if album != []:
|
if album != []:
|
||||||
new_loc += "/" + blank(album[0], False)
|
new_loc += "/" + ObjManip.blank(album[0], False)
|
||||||
if not os.path.exists(new_loc):
|
if not os.path.exists(new_loc):
|
||||||
os.makedirs(new_loc)
|
os.makedirs(new_loc)
|
||||||
new_loc += "/" + file_name
|
new_loc += "/" + file_name
|
||||||
|
@ -87,68 +98,80 @@ class Ripper:
|
||||||
file_name = loc.split("/")[-1]
|
file_name = loc.split("/")[-1]
|
||||||
else:
|
else:
|
||||||
file_name = loc
|
file_name = loc
|
||||||
new_loc += blank(self.playlist_title, False)
|
new_loc += ObjManip.blank(self.playlist_title, False)
|
||||||
if not os.path.exists(new_loc):
|
if not os.path.exists(new_loc):
|
||||||
os.makedirs(new_loc)
|
os.makedirs(new_loc)
|
||||||
loc = loc.replace("//", "/")
|
loc = loc.replace("//", "/")
|
||||||
new_loc = (new_loc + "/" + file_name).replace("//", "/")
|
new_loc = (new_loc + "/" + file_name)\
|
||||||
|
.replace("//", "/")
|
||||||
os.rename(loc, new_loc)
|
os.rename(loc, new_loc)
|
||||||
|
|
||||||
return locations
|
return locations
|
||||||
|
|
||||||
def find_yt_url(self, song=None, artist=None, additional_search=None):
|
def find_yt_url(self, song=None, artist=None, additional_search=None):
|
||||||
if additional_search == None:
|
if additional_search is None:
|
||||||
additional_search = parse_search_terms(self)
|
additional_search = Config.parse_search_terms(self)
|
||||||
try:
|
try:
|
||||||
if not song: song = self.args["song_title"]
|
if not song:
|
||||||
if not artist: artist = self.args["artist"]
|
song = self.args["song_title"]
|
||||||
|
if not artist:
|
||||||
|
artist = self.args["artist"]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise ValueError("Must specify song_title/artist in `args` with init, or in method arguments.")
|
raise ValueError("Must specify song_title/artist in `args` with \
|
||||||
|
init, or in method arguments.")
|
||||||
|
|
||||||
print ("Finding Youtube Link ...")
|
print("Finding Youtube Link ...")
|
||||||
|
|
||||||
search_terms = song + " " + artist + " " + additional_search
|
search_terms = song + " " + artist + " " + additional_search
|
||||||
query_string = urlencode({"search_query" : (search_terms)})
|
query_string = urlencode({"search_query": (search_terms)})
|
||||||
link = "http://www.youtube.com/results?" + query_string
|
link = "http://www.youtube.com/results?" + query_string
|
||||||
|
|
||||||
html_content = urlopen(link).read()
|
html_content = urlopen(link).read()
|
||||||
soup = BeautifulSoup(html_content, 'html.parser')#.prettify()
|
soup = BeautifulSoup(html_content, 'html.parser') # .prettify()
|
||||||
|
|
||||||
def find_link(link):
|
def find_link(link):
|
||||||
try:
|
try:
|
||||||
if "yt-uix-tile-link yt-ui-ellipsis yt-ui-ellipsis-2 yt-uix-sessionlink spf-link" in str(" ".join(link["class"])):
|
if "yt-uix-tile-link yt-ui-ellipsis yt-ui-ellipsis-2 yt-uix-\
|
||||||
if not "&list=" in link["href"]:
|
sessionlink spf-link" in str(" ".join(link["class"])):
|
||||||
|
if "&list=" not in link["href"]:
|
||||||
return link
|
return link
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
results = list(filter(None, (map(find_link, soup.find_all("a")))))
|
results = list(filter(None, (map(find_link, soup.find_all("a")))))
|
||||||
|
|
||||||
garbage_phrases = "cover album live clean rare version full full album".split(" ")
|
garbage_phrases = "cover album live clean rare version full full \
|
||||||
|
album".split(" ")
|
||||||
|
|
||||||
self.code = None
|
self.code = None
|
||||||
counter = 0
|
counter = 0
|
||||||
|
|
||||||
|
while self.code is None and counter <= 10:
|
||||||
while self.code == None and counter <= 10:
|
|
||||||
counter += 1
|
counter += 1
|
||||||
for link in results:
|
for link in results:
|
||||||
if blank_include(link["title"], song) and blank_include(link["title"], artist):
|
if ObjManip.blank_include(link["title"], song) and \
|
||||||
if check_garbage_phrases(garbage_phrases, link["title"], song): continue
|
ObjManip.blank_include(link["title"], artist):
|
||||||
|
if ObjManip.check_garbage_phrases(garbage_phrases,
|
||||||
|
link["title"], song):
|
||||||
|
continue
|
||||||
self.code = link
|
self.code = link
|
||||||
break
|
break
|
||||||
|
|
||||||
if self.code == None:
|
if self.code is None:
|
||||||
for link in results:
|
for link in results:
|
||||||
if check_garbage_phrases(garbage_phrases, link["title"], song): continue
|
if ObjManip.check_garbage_phrases(garbage_phrases,
|
||||||
if individual_word_match(song, link["title"]) >= 0.8 and blank_include(link["title"], artist):
|
link["title"], song):
|
||||||
|
continue
|
||||||
|
if ObjManip.individual_word_match(song, link["title"]) \
|
||||||
|
>= 0.8 and ObjManip.blank_include(link["title"],
|
||||||
|
artist):
|
||||||
self.code = link
|
self.code = link
|
||||||
break
|
break
|
||||||
|
|
||||||
if self.code == None:
|
if self.code is None:
|
||||||
song = limit_song_name(song)
|
song = ObjManip.limit_song_name(song)
|
||||||
|
|
||||||
if self.code == None:
|
if self.code is None:
|
||||||
if additional_search == "lyrics":
|
if additional_search == "lyrics":
|
||||||
return self.find_yt_url(song, artist, "")
|
return self.find_yt_url(song, artist, "")
|
||||||
else:
|
else:
|
||||||
|
@ -159,17 +182,21 @@ class Ripper:
|
||||||
def album(self, title): # Alias for `spotify_list("album", ...)`
|
def album(self, title): # Alias for `spotify_list("album", ...)`
|
||||||
return self.spotify_list("album", title)
|
return self.spotify_list("album", title)
|
||||||
|
|
||||||
def playlist(self, title, username): # Alias for `spotify_list("playlist", ...)`
|
def playlist(self, title, username):
|
||||||
|
# Alias for `spotify_list("playlist", ...)`
|
||||||
return self.spotify_list("playlist", title, username)
|
return self.spotify_list("playlist", title, username)
|
||||||
|
|
||||||
def spotify_list(self, type=None, title=None, username=None, artist=None):
|
def spotify_list(self, type=None, title=None, username=None, artist=None):
|
||||||
try:
|
try:
|
||||||
if not type: type = self.args["type"]
|
if not type:
|
||||||
if not title: title = self.args["list_title"]
|
type = self.args["type"]
|
||||||
|
if not title:
|
||||||
|
title = self.args["list_title"]
|
||||||
if not username and type == "playlist":
|
if not username and type == "playlist":
|
||||||
username = self.args["username"]
|
username = self.args["username"]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise ValueError("Must specify type/title/username in `args` with init, or in method arguments.")
|
raise ValueError("Must specify type/title/username in `args` \
|
||||||
|
with init, or in method arguments.")
|
||||||
|
|
||||||
if not self.type:
|
if not self.type:
|
||||||
self.type = type
|
self.type = type
|
||||||
|
@ -178,28 +205,34 @@ 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")["albums"]["items"]
|
list_of_lists = self.spotify.search(q=search, type="album")
|
||||||
|
list_of_lists = list_of_lists["albums"]["items"]
|
||||||
elif type == "playlist":
|
elif type == "playlist":
|
||||||
list_of_lists = self.spotify.user_playlists(username)["items"]
|
list_of_lists = self.spotify.user_playlists(username)["items"]
|
||||||
|
|
||||||
if len(list_of_lists) > 0:
|
if len(list_of_lists) > 0:
|
||||||
the_list = None
|
the_list = None
|
||||||
for list_ in list_of_lists:
|
for list_ in list_of_lists:
|
||||||
if blank_include(list_["name"], title):
|
if ObjManip.blank_include(list_["name"], title):
|
||||||
if parse_artist(self):
|
if Config.parse_artist(self):
|
||||||
if blank_include(list_["artists"][0]["name"], parse_artist(self)):
|
if ObjManip.blank_include(list_["artists"][0]["name"],
|
||||||
|
ObjManip.arse_artist(self)):
|
||||||
the_list = self.spotify.album(list_["uri"])
|
the_list = self.spotify.album(list_["uri"])
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
if type == "album":
|
if type == "album":
|
||||||
the_list = self.spotify.album(list_["uri"])
|
the_list = self.spotify.album(list_["uri"])
|
||||||
else:
|
else:
|
||||||
the_list = self.spotify.user_playlist(list_["owner"]["id"], list_["uri"])
|
the_list = self.spotify.user_playlist(
|
||||||
|
list_["owner"]["id"], list_["uri"])
|
||||||
the_list["artists"] = [{"name": username}]
|
the_list["artists"] = [{"name": username}]
|
||||||
break
|
break
|
||||||
if the_list != None:
|
if the_list is not None:
|
||||||
clear_line()
|
YdlUtils.clear_line()
|
||||||
print (type.title() + ': "%s" by "%s"' % (the_list["name"], the_list["artists"][0]["name"]))
|
|
||||||
|
print(type.title() + ': "%s" by \
|
||||||
|
"%s"' % (the_list["name"], the_list["artists"][0]["name"]))
|
||||||
|
|
||||||
compilation = ""
|
compilation = ""
|
||||||
if type == "album":
|
if type == "album":
|
||||||
tmp_artists = []
|
tmp_artists = []
|
||||||
|
@ -215,7 +248,8 @@ class Ripper:
|
||||||
|
|
||||||
for track in the_list["tracks"]["items"]:
|
for track in the_list["tracks"]["items"]:
|
||||||
if type == "playlist":
|
if type == "playlist":
|
||||||
self.playlist_title = the_list["name"] # For post-processors
|
# For post-processors
|
||||||
|
self.playlist_title = the_list["name"]
|
||||||
|
|
||||||
file_prefix = str(len(tracks) + 1) + " - "
|
file_prefix = str(len(tracks) + 1) + " - "
|
||||||
track = track["track"]
|
track = track["track"]
|
||||||
|
@ -229,7 +263,9 @@ class Ripper:
|
||||||
"name": track["name"],
|
"name": track["name"],
|
||||||
"artist": track["artists"][0]["name"],
|
"artist": track["artists"][0]["name"],
|
||||||
"album": album["name"],
|
"album": album["name"],
|
||||||
"genre": parse_genre(self.spotify.artist(track["artists"][0]["uri"])["genres"]),
|
"genre": m.MetadataUtils.parse_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"],
|
||||||
"album_art": album["images"][0]["url"],
|
"album_art": album["images"][0]["url"],
|
||||||
|
@ -241,32 +277,32 @@ class Ripper:
|
||||||
|
|
||||||
locations = self.list(tracks)
|
locations = self.list(tracks)
|
||||||
return locations
|
return locations
|
||||||
#return self.post_processing(locations)
|
# return self.post_processing(locations)
|
||||||
|
|
||||||
print ('Could not find any lists.')
|
print("Could not find any lists.")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def list(self, 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(format_download_log_data(list_data))
|
# file.write(format_download_log_data(list_data))
|
||||||
|
|
||||||
for track in list_data:
|
for track in list_data:
|
||||||
loc = self.song(track["name"], track["artist"], track)
|
loc = self.song(track["name"], track["artist"], track)
|
||||||
|
|
||||||
if loc != False:
|
if loc is not False:
|
||||||
#update_download_log_line_status(track, "downloaded")
|
# update_download_log_line_status(track, "downloaded")
|
||||||
locations.append(loc)
|
locations.append(loc)
|
||||||
|
|
||||||
if self.type in ("album", "playlist"):
|
if self.type in ("album", "playlist"):
|
||||||
return self.post_processing(locations)
|
return self.post_processing(locations)
|
||||||
|
|
||||||
#os.remove(".irs-download-log")
|
# os.remove(".irs-download-log")
|
||||||
return locations
|
return locations
|
||||||
|
|
||||||
def parse_song_data(self, song, artist):
|
def parse_song_data(self, song, artist):
|
||||||
album, track = find_album_and_track(song, artist)
|
album, track = find_album_and_track(song, artist)
|
||||||
if album == False:
|
if album is False:
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
album = self.spotify.album(album["uri"])
|
album = self.spotify.album(album["uri"])
|
||||||
|
@ -282,19 +318,26 @@ class Ripper:
|
||||||
"track_number": track["track_number"],
|
"track_number": track["track_number"],
|
||||||
"disc_number": track["disc_number"],
|
"disc_number": track["disc_number"],
|
||||||
|
|
||||||
"compilation": "", # If this method is being called, it's not a compilation
|
# If this method is being called, it's not a compilation
|
||||||
"file_prefix": "" # And therefore, won't have a prefix
|
"compilation": "",
|
||||||
|
# And therefore, won't have a prefix
|
||||||
|
"file_prefix": ""
|
||||||
}
|
}
|
||||||
|
|
||||||
def song(self, song, artist, data={}): # Takes data from `parse_song_data`
|
def song(self, song, artist, data={}):
|
||||||
|
# "data" comes from "self.parse_song_data"'s layout
|
||||||
|
|
||||||
if not self.type:
|
if not self.type:
|
||||||
self.type = "song"
|
self.type = "song"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if not song: song = self.args["song_title"]
|
if not song:
|
||||||
if not artist: artist = self.args["artist"]
|
song = self.args["song_title"]
|
||||||
|
if not artist:
|
||||||
|
artist = self.args["artist"]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise ValueError("Must specify song_title/artist in `args` with init, or in method arguments.")
|
raise ValueError("Must specify song_title/artist in `args` with \
|
||||||
|
init, or in method arguments.")
|
||||||
|
|
||||||
if data == {}:
|
if data == {}:
|
||||||
data = self.parse_song_data(song, artist)
|
data = self.parse_song_data(song, artist)
|
||||||
|
@ -307,20 +350,20 @@ class Ripper:
|
||||||
|
|
||||||
video_url, video_title = self.find_yt_url(song, artist)
|
video_url, video_title = self.find_yt_url(song, artist)
|
||||||
|
|
||||||
print ('Downloading "%s" by "%s" ...' % (song, artist))
|
print('Downloading "%s" by "%s" ...' % (song, artist))
|
||||||
|
|
||||||
file_name = str(data["file_prefix"] + blank(song, False) + ".mp3")
|
file_name = str(data["file_prefix"] + ObjManip.blank(song, False) +
|
||||||
|
".mp3")
|
||||||
|
|
||||||
ydl_opts = {
|
ydl_opts = {
|
||||||
'format': 'bestaudio/best',
|
'format': 'bestaudio/best',
|
||||||
#'quiet': True,
|
|
||||||
'postprocessors': [{
|
'postprocessors': [{
|
||||||
'key': 'FFmpegExtractAudio',
|
'key': 'FFmpegExtractAudio',
|
||||||
'preferredcodec': 'mp3',
|
'preferredcodec': 'mp3',
|
||||||
'preferredquality': '192',
|
'preferredquality': '192',
|
||||||
}],
|
}],
|
||||||
'logger': MyLogger(),
|
'logger': YdlUtils.MyLogger(),
|
||||||
'progress_hooks': [my_hook],
|
'progress_hooks': [YdlUtils.my_hook],
|
||||||
'output': "tmp_file",
|
'output': "tmp_file",
|
||||||
'prefer-ffmpeg': True,
|
'prefer-ffmpeg': True,
|
||||||
}
|
}
|
||||||
|
@ -328,19 +371,18 @@ class Ripper:
|
||||||
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
||||||
ydl.download([video_url])
|
ydl.download([video_url])
|
||||||
|
|
||||||
|
|
||||||
for file in glob.glob("./*%s*" % video_url.split("/watch?v=")[-1]):
|
for file in glob.glob("./*%s*" % video_url.split("/watch?v=")[-1]):
|
||||||
os.rename(file, file_name)
|
os.rename(file, file_name)
|
||||||
|
|
||||||
# Ease of Variables (copyright) (patent pending) (git yer filthy hands off)
|
# Ease of Variables (C) (patent pending) (git yer filthy hands off)
|
||||||
# [CENSORED BY THE BAD CODE ACT]
|
# [CENSORED BY THE BAD CODE ACT]
|
||||||
# *5 Minutes Later*
|
# *5 Minutes Later*
|
||||||
# Deprecated. 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("comment", 'URL: "%s"\nVideo Title: "%s"' % (video_url, video_title))
|
m.add_tag("comment", 'URL: "%s"\nVideo Title: "%s"' %
|
||||||
|
(video_url, video_title))
|
||||||
if len(data.keys()) > 1:
|
if len(data.keys()) > 1:
|
||||||
m.add_tag("title", data["name"])
|
m.add_tag("title", data["name"])
|
||||||
m.add_tag("artist", data["artist"])
|
m.add_tag("artist", data["artist"])
|
||||||
|
@ -349,9 +391,9 @@ class Ripper:
|
||||||
m.add_tag("tracknumber", str(data["track_number"]))
|
m.add_tag("tracknumber", str(data["track_number"]))
|
||||||
m.add_tag("discnumber", str(data["disc_number"]))
|
m.add_tag("discnumber", str(data["disc_number"]))
|
||||||
m.add_tag("compilation", data["compilation"])
|
m.add_tag("compilation", data["compilation"])
|
||||||
m.add_album_art( str(data["album_art"]))
|
m.add_album_art(str(data["album_art"]))
|
||||||
else:
|
else:
|
||||||
print ("Could not find metadata.")
|
print("Could not find metadata.")
|
||||||
m.add_tag("title", song)
|
m.add_tag("title", song)
|
||||||
m.add_tag("artist", artist)
|
m.add_tag("artist", artist)
|
||||||
|
|
||||||
|
|
240
irs/utils.py
240
irs/utils.py
|
@ -1,14 +1,29 @@
|
||||||
# -*- coding: UTF-8 -*-
|
# -*- coding: UTF-8 -*-
|
||||||
|
|
||||||
|
# =======
|
||||||
|
# Imports
|
||||||
|
# =======
|
||||||
|
|
||||||
#==========================
|
# And Now For Something Completely Different
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import re
|
||||||
|
from time import sleep
|
||||||
|
import pkg_resources
|
||||||
|
|
||||||
|
# Config File and Flags
|
||||||
|
from .config import CONFIG
|
||||||
|
|
||||||
|
|
||||||
|
# =========================
|
||||||
# Youtube-DL Logs and Hooks
|
# Youtube-DL Logs and Hooks
|
||||||
#==========================
|
# =========================
|
||||||
|
|
||||||
def clear_line():
|
class YdlUtils:
|
||||||
|
def clear_line():
|
||||||
sys.stdout.write("\x1b[2K\r")
|
sys.stdout.write("\x1b[2K\r")
|
||||||
|
|
||||||
class MyLogger(object):
|
class MyLogger(object):
|
||||||
def debug(self, msg):
|
def debug(self, msg):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -18,49 +33,54 @@ class MyLogger(object):
|
||||||
def error(self, msg):
|
def error(self, msg):
|
||||||
print(msg)
|
print(msg)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
def my_hook(d):
|
def my_hook(d):
|
||||||
if d['status'] == 'finished':
|
if d['status'] == 'finished':
|
||||||
print ("Converting to mp3 ...")
|
print("Converting to mp3 ...")
|
||||||
|
|
||||||
|
|
||||||
#=================================
|
# ================================
|
||||||
# Object Manipulation and Checking
|
# Object Manipulation and Checking
|
||||||
#=================================
|
# ================================
|
||||||
|
|
||||||
def limit_song_name(song):
|
class ObjManip: # Object Manipulation
|
||||||
|
def limit_song_name(song):
|
||||||
bad_phrases = "remaster remastered master".split(" ")
|
bad_phrases = "remaster remastered master".split(" ")
|
||||||
# I have "master" here because Spotify actually sometimes mispells stuff
|
# I have "master" here because Spotify actually sometimes mispells
|
||||||
# and it is hella annoying, so this was my solution
|
# stuff and it is hella annoying, so this was my solution
|
||||||
for phrase in bad_phrases:
|
for phrase in bad_phrases:
|
||||||
if blank_include(song.split(" - ")[-1], phrase):
|
if ObjManip.blank_include(song.split(" - ")[-1], phrase):
|
||||||
return song.split(" - ")[0]
|
return song.split(" - ")[0]
|
||||||
return song
|
return song
|
||||||
|
|
||||||
def check_garbage_phrases(phrases, string, title):
|
@staticmethod
|
||||||
|
def check_garbage_phrases(phrases, string, title):
|
||||||
for phrase in phrases:
|
for phrase in phrases:
|
||||||
if phrase in blank(string):
|
if phrase in ObjManip.blank(string):
|
||||||
if not phrase in blank(title):
|
if phrase not in ObjManip.blank(title):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def blank(string, downcase=True):
|
@staticmethod
|
||||||
|
def blank(string, downcase=True):
|
||||||
import re
|
import re
|
||||||
regex = re.compile('[^a-zA-Z0-9\ ]')
|
regex = re.compile('[^a-zA-Z0-9\ ]')
|
||||||
string = regex.sub('', string)
|
string = regex.sub('', string)
|
||||||
if downcase: string = string.lower()
|
if downcase:
|
||||||
|
string = string.lower()
|
||||||
return ' '.join(string.split())
|
return ' '.join(string.split())
|
||||||
|
|
||||||
def blank_include(this, includes_this):
|
@staticmethod
|
||||||
this = blank(this)
|
def blank_include(this, includes_this):
|
||||||
includes_this = blank(includes_this)
|
this = ObjManip.blank(this)
|
||||||
|
includes_this = ObjManip.blank(includes_this)
|
||||||
if includes_this in this:
|
if includes_this in this:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def individual_word_match(match_against, match):
|
def individual_word_match(match_against, match):
|
||||||
match_against = blank(match_against).split(" ")
|
match_against = ObjManip.blank(match_against).split(" ")
|
||||||
match = blank(match).split(" ")
|
match = ObjManip.blank(match).split(" ")
|
||||||
matched = []
|
matched = []
|
||||||
for match_ag in match_against:
|
for match_ag in match_against:
|
||||||
for word in match:
|
for word in match:
|
||||||
|
@ -68,7 +88,7 @@ def individual_word_match(match_against, match):
|
||||||
matched.append(word)
|
matched.append(word)
|
||||||
return (float(len(set(matched))) / float(len(match_against)))
|
return (float(len(set(matched))) / float(len(match_against)))
|
||||||
|
|
||||||
def flatten(l):
|
def flatten(l):
|
||||||
flattened_list = []
|
flattened_list = []
|
||||||
for x in l:
|
for x in l:
|
||||||
if type(x) != str:
|
if type(x) != str:
|
||||||
|
@ -78,31 +98,33 @@ def flatten(l):
|
||||||
flattened_list.append(x)
|
flattened_list.append(x)
|
||||||
return flattened_list
|
return flattened_list
|
||||||
|
|
||||||
def remove_none_values(d):
|
def remove_none_values(d):
|
||||||
new_d = d
|
new_d = d
|
||||||
for x in list(d.keys()):
|
for x in list(d.keys()):
|
||||||
if type(new_d[x]) is list:
|
if type(new_d[x]) is list:
|
||||||
new_d[x] = remove_none_values(d[x])
|
new_d[x] = ObjManip.remove_none_values(d[x])
|
||||||
elif new_d[x] == None:
|
elif new_d[x] is None:
|
||||||
del new_d[x]
|
del new_d[x]
|
||||||
return new_d
|
return new_d
|
||||||
|
|
||||||
#=========================================
|
|
||||||
|
# ========================================
|
||||||
# Download Log Reading/Updating/Formatting
|
# Download Log Reading/Updating/Formatting
|
||||||
#=========================================
|
# ========================================
|
||||||
|
|
||||||
def format_download_log_line(t, download_status="not downloaded"):
|
class DLog:
|
||||||
return (" @@ ".join([t["name"], t["artist"], t["album"]["id"], \
|
def format_download_log_line(t, download_status="not downloaded"):
|
||||||
str(t["genre"]), t["track_number"], t["disc_number"], t["compilation"], \
|
return (" @@ ".join([t["name"], t["artist"], t["album"]["id"],
|
||||||
t["file_prefix"], download_status]))
|
str(t["genre"]), t["track_number"], t["disc_number"],
|
||||||
|
t["compilation"], t["file_prefix"], download_status]))
|
||||||
|
|
||||||
def format_download_log_data(data):
|
def format_download_log_data(data):
|
||||||
lines = []
|
lines = []
|
||||||
for track in data:
|
for track in data:
|
||||||
lines.append(format_download_log_line(track))
|
lines.append(DLog.format_download_log_line(track))
|
||||||
return "\n".join(lines)
|
return "\n".join(lines)
|
||||||
|
|
||||||
def read_download_log(spotify):
|
def read_download_log(spotify):
|
||||||
data = []
|
data = []
|
||||||
with open(".irs-download-log", "r") as file:
|
with open(".irs-download-log", "r") as file:
|
||||||
for line in file:
|
for line in file:
|
||||||
|
@ -119,26 +141,23 @@ def read_download_log(spotify):
|
||||||
})
|
})
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def update_download_log_line_status(track, status="downloaded"):
|
def update_download_log_line_status(track, status="downloaded"):
|
||||||
line_to_find = format_download_log_line(track)
|
line_to_find = DLog.format_download_log_line(track)
|
||||||
with open(".irs-download-log", "r") as input_file, \
|
with open(".irs-download-log", "r") as input_file:
|
||||||
open(".irs-download-log", "w") as output_file:
|
with open(".irs-download-log", "w") as output_file:
|
||||||
for line in input_file:
|
for line in input_file:
|
||||||
if line == line_to_find:
|
if line == line_to_find:
|
||||||
output_file.write(format_download_log_line(track, status))
|
output_file.write(
|
||||||
|
DLog.format_download_log_line(track, status))
|
||||||
else:
|
else:
|
||||||
output_file.write(line)
|
output_file.write(line)
|
||||||
|
|
||||||
|
|
||||||
#============================================
|
# ===========================================
|
||||||
# And Now, For Something Completely Different
|
# And Now, For Something Completely Different
|
||||||
#============================================
|
# ===========================================
|
||||||
# (It's for the CLI)
|
# (It's for the CLI)
|
||||||
|
|
||||||
import os, sys, re
|
|
||||||
from time import sleep
|
|
||||||
import pkg_resources
|
|
||||||
|
|
||||||
COLS = int(os.popen('tput cols').read().strip("\n"))
|
COLS = int(os.popen('tput cols').read().strip("\n"))
|
||||||
|
|
||||||
if sys.version_info[0] == 2:
|
if sys.version_info[0] == 2:
|
||||||
|
@ -149,36 +168,41 @@ if sys.version_info[0] == 2:
|
||||||
def code(code1):
|
def code(code1):
|
||||||
return "\x1b[%sm" % str(code1)
|
return "\x1b[%sm" % str(code1)
|
||||||
|
|
||||||
|
|
||||||
def no_colors(string):
|
def no_colors(string):
|
||||||
return re.sub("\x1b\[\d+m", "", string)
|
return re.sub("\x1b\[\d+m", "", string)
|
||||||
|
|
||||||
|
|
||||||
def center_colors(string, cols):
|
def center_colors(string, cols):
|
||||||
return no_colors(string).center(cols).replace(no_colors(string), string)
|
return no_colors(string).center(cols).replace(no_colors(string), string)
|
||||||
|
|
||||||
|
|
||||||
def decode_utf8(string):
|
def decode_utf8(string):
|
||||||
if sys.version_info[0] == 3:
|
if sys.version_info[0] == 3:
|
||||||
return string.encode("utf8", "strict").decode()
|
return string.encode("utf8", "strict").decode()
|
||||||
elif sys.version_info[0] == 2:
|
elif sys.version_info[0] == 2:
|
||||||
return string.decode("utf8")
|
return string.decode("utf8")
|
||||||
|
|
||||||
|
|
||||||
def center_unicode(string, cols):
|
def center_unicode(string, cols):
|
||||||
tmp_chars = "X" * len(decode_utf8(string))
|
tmp_chars = "X" * len(decode_utf8(string))
|
||||||
chars = center_colors(tmp_chars, cols)
|
chars = center_colors(tmp_chars, cols)
|
||||||
return chars.replace(tmp_chars, string)
|
return chars.replace(tmp_chars, string)
|
||||||
|
|
||||||
|
|
||||||
def center_lines(string, cols, end="\n"):
|
def center_lines(string, cols, end="\n"):
|
||||||
lines = []
|
lines = []
|
||||||
for line in string.split("\n"):
|
for line in string.split("\n"):
|
||||||
lines.append(center_unicode(line, cols))
|
lines.append(center_unicode(line, cols))
|
||||||
return end.join(lines)
|
return end.join(lines)
|
||||||
|
|
||||||
|
|
||||||
def flush_puts(msg, time=0.01):
|
def flush_puts(msg, time=0.01):
|
||||||
# For slow *burrrp* scroll text, Morty. They-They just love it, Morty.
|
# For slow *burrrp* scroll text, Morty. They-They just love it, Morty.
|
||||||
# When they see this text. Just slowwwly extending across the page. Mmm, mmm.
|
# When they see this text. Just slowwwly extending across the page. Mmm,
|
||||||
# You just give the time for how *buurp* slow you wa-want it, Morty.
|
# mmm. You just give the time for how *buurp* slow you wa-want it, Morty.
|
||||||
# It works with colors and escape characters too, Morty.
|
# It works with colors and escape characters too, Morty.
|
||||||
# Your grandpa's a genius *burrrp* Morty
|
# Your grandpa's a genius *burrrp* Morty
|
||||||
pattern = re.compile("(\x1b\[\d+m)")
|
|
||||||
def check_color(s):
|
def check_color(s):
|
||||||
if "\x1b" not in s:
|
if "\x1b" not in s:
|
||||||
new = list(s)
|
new = list(s)
|
||||||
|
@ -187,13 +211,13 @@ def flush_puts(msg, time=0.01):
|
||||||
return new
|
return new
|
||||||
msg = re.split("(\x1b\[\d+m)", msg)
|
msg = re.split("(\x1b\[\d+m)", msg)
|
||||||
msg = list(filter(None, map(check_color, msg)))
|
msg = list(filter(None, map(check_color, msg)))
|
||||||
msg = flatten(msg)
|
msg = ObjManip.flatten(msg)
|
||||||
for char in msg:
|
for char in msg:
|
||||||
if char not in (" ", "", "\n") and "\x1b" not in char:
|
if char not in (" ", "", "\n") and "\x1b" not in char:
|
||||||
sleep(time)
|
sleep(time)
|
||||||
sys.stdout.write(char)
|
sys.stdout.write(char)
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
print ("")
|
print("")
|
||||||
|
|
||||||
|
|
||||||
BOLD = code(1)
|
BOLD = code(1)
|
||||||
|
@ -213,6 +237,7 @@ BPURPLE = PURPLE + BOLD
|
||||||
BCYAN = CYAN + BOLD
|
BCYAN = CYAN + BOLD
|
||||||
BGRAY = GRAY + BOLD
|
BGRAY = GRAY + BOLD
|
||||||
|
|
||||||
|
|
||||||
def banner():
|
def banner():
|
||||||
title = (BCYAN + center_lines("""\
|
title = (BCYAN + center_lines("""\
|
||||||
██╗██████╗ ███████╗
|
██╗██████╗ ███████╗
|
||||||
|
@ -225,37 +250,42 @@ def banner():
|
||||||
for num in range(0, 6):
|
for num in range(0, 6):
|
||||||
os.system("clear || cls")
|
os.system("clear || cls")
|
||||||
if num % 2 == 1:
|
if num % 2 == 1:
|
||||||
print (BRED + center_unicode("🚨 🚨 🚨 🚨 🚨 \r", COLS))
|
print(BRED + center_unicode("🚨 🚨 🚨 🚨 🚨 \r", COLS))
|
||||||
else:
|
else:
|
||||||
print ("")
|
print("")
|
||||||
print (title)
|
print(title)
|
||||||
sleep(0.3)
|
sleep(0.3)
|
||||||
flush_puts(center_colors("{0}Ironic Redistribution System ({1}IRS{2})"\
|
flush_puts(center_colors("{0}Ironic Redistribution System ({1}IRS{2})"
|
||||||
.format(BYELLOW, BRED, BYELLOW), COLS))
|
.format(BYELLOW, BRED, BYELLOW), COLS))
|
||||||
|
|
||||||
flush_puts(center_colors("{0}Made with 😈 by: {1}Kepoor Hampond ({2}kepoorhampond{3})"\
|
flush_puts(center_colors("{0}Made with 😈 by: {1}Kepoor Hampond \
|
||||||
.format(BBLUE, BYELLOW, BRED, BYELLOW) + END, COLS))
|
({2}kepoorhampond{3})".format(BBLUE, BYELLOW,
|
||||||
|
BRED, BYELLOW) + END, COLS))
|
||||||
|
|
||||||
|
flush_puts(center_colors("{0}Version: {1}".format(BBLUE, BYELLOW) +
|
||||||
|
pkg_resources.get_distribution("irs").version, COLS))
|
||||||
|
|
||||||
flush_puts(center_colors("{0}Version: {1}".format(BBLUE, BYELLOW) + pkg_resources.get_distribution("irs").version, COLS))
|
|
||||||
|
|
||||||
def menu(unicode, time=0.01):
|
def menu(unicode, time=0.01):
|
||||||
flush_puts("Choose option from menu:", time)
|
flush_puts("Choose option from menu:", time)
|
||||||
flush_puts("\t[{0}song{1}] Download Song".format(BGREEN, END), time)
|
flush_puts("\t[{0}song{1}] Download Song".format(BGREEN, END), time)
|
||||||
flush_puts("\t[{0}album{1}] Download Album".format(BGREEN, END), time)
|
flush_puts("\t[{0}album{1}] Download Album".format(BGREEN, END), time)
|
||||||
flush_puts("\t[{0}{1}{2}] Download Playlist".format(BGREEN, unicode[-1], END), time)
|
flush_puts("\t[{0}{1}{2}] Download Playlist"
|
||||||
|
.format(BGREEN, unicode[-1], END), time)
|
||||||
flush_puts("\t[{0}help{1}] Print This Menu".format(BGREEN, END), time)
|
flush_puts("\t[{0}help{1}] Print This Menu".format(BGREEN, END), time)
|
||||||
flush_puts("\t[{0}exit{1}] Exit IRS".format(BGREEN, END), time)
|
flush_puts("\t[{0}exit{1}] Exit IRS".format(BGREEN, END), time)
|
||||||
print ("")
|
print("")
|
||||||
|
|
||||||
|
|
||||||
def console(ripper):
|
def console(ripper):
|
||||||
banner()
|
banner()
|
||||||
print (END)
|
print(END)
|
||||||
if ripper.authorized == True:
|
if ripper.authorized is True:
|
||||||
unicode = [BGREEN + "✔" + END, "list"]
|
unicode = [BGREEN + "✔" + END, "list"]
|
||||||
elif ripper.authorized == False:
|
elif ripper.authorized is False:
|
||||||
unicode = [BRED + "✘" + END]
|
unicode = [BRED + "✘" + END]
|
||||||
flush_puts("[{0}] Authenticated with Spotify".format(unicode[0]))
|
flush_puts("[{0}] Authenticated with Spotify".format(unicode[0]))
|
||||||
print ("")
|
print("")
|
||||||
menu(unicode)
|
menu(unicode)
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
|
@ -267,92 +297,104 @@ def console(ripper):
|
||||||
try:
|
try:
|
||||||
if choice in ("song", "s"):
|
if choice in ("song", "s"):
|
||||||
song_name = input("Song name{0}:{1} ".format(BBLUE, END))
|
song_name = input("Song name{0}:{1} ".format(BBLUE, END))
|
||||||
artist_name = input("Artist name{0}:{1} ".format(BBLUE, END))
|
artist_name = input("Artist name{0}:{1} "
|
||||||
|
.format(BBLUE, END))
|
||||||
ripper.song(song_name, artist_name)
|
ripper.song(song_name, artist_name)
|
||||||
|
|
||||||
elif choice in ("album", "a"):
|
elif choice in ("album", "a"):
|
||||||
album_name = input("Album name{0}:{1} ".format(BBLUE, END))
|
album_name = input("Album name{0}:{1} ".format(BBLUE, END))
|
||||||
ripper.spotify_list("album", album_name)
|
ripper.spotify_list("album", album_name)
|
||||||
|
|
||||||
elif choice in ("list", "l") and ripper.authorized == True:
|
elif choice in ("list", "l") and ripper.authorized is True:
|
||||||
username = input("Spotify Username{0}:{1} ".format(BBLUE, END))
|
username = input("Spotify Username{0}:{1} "
|
||||||
list_name = input("Playlist Name{0}:{1} ".format(BBLUE, END))
|
.format(BBLUE, END))
|
||||||
|
list_name = input("Playlist Name{0}:{1} "
|
||||||
|
.format(BBLUE, END))
|
||||||
ripper.spotify_list("playlist", list_name, username)
|
ripper.spotify_list("playlist", list_name, username)
|
||||||
|
|
||||||
elif choice in ("help", "h", "?"):
|
elif choice in ("help", "h", "?"):
|
||||||
menu(unicode, 0)
|
menu(unicode, 0)
|
||||||
except (KeyboardInterrupt, EOFError):
|
except (KeyboardInterrupt, EOFError):
|
||||||
print ("")
|
print("")
|
||||||
pass
|
pass
|
||||||
|
|
||||||
except (KeyboardInterrupt, EOFError):
|
except (KeyboardInterrupt, EOFError):
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
#======================
|
|
||||||
|
"""
|
||||||
|
# =====================
|
||||||
# Config File and Flags
|
# Config File and Flags
|
||||||
#======================
|
# =====================
|
||||||
from .config import CONFIG
|
|
||||||
|
|
||||||
def check_sources(ripper, key, default=None, environment=False, where=None):
|
def check_sources(ripper, key, default=None, environment=False, where=None):
|
||||||
if where != None:
|
if where is not None:
|
||||||
tmp_args = ripper.args.get(where)
|
tmp_args = ripper.args.get(where)
|
||||||
else:
|
else:
|
||||||
tmp_args = ripper.args
|
tmp_args = ripper.args
|
||||||
|
|
||||||
if tmp_args.get(key):
|
if tmp_args.get(key):
|
||||||
return tmp_args.get(key)
|
return tmp_args.get(key)
|
||||||
#============
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
# ===========
|
||||||
# CONFIG FILE
|
# CONFIG FILE
|
||||||
#============
|
# ===========
|
||||||
from .config import CONFIG
|
|
||||||
|
|
||||||
def check_sources(ripper, key, default=None, environment=False, where=None):
|
def check_sources(ripper, key, default=None, environment=False, where=None):
|
||||||
tmp_args = ripper.args
|
# tmp_args = ripper.args
|
||||||
if where != None and ripper.args.get(where):
|
# if where is not None and ripper.args.get(where):
|
||||||
tmp_args = ripper.args.get("where")
|
# tmp_args = ripper.args.get("where")
|
||||||
|
|
||||||
if ripper.args.get(key):
|
if ripper.args.get(key):
|
||||||
return ripper.args.get(key)
|
return ripper.args.get(key)
|
||||||
elif CONFIG.get(key):
|
elif CONFIG.get(key):
|
||||||
return CONFIG.get(key)
|
return CONFIG.get(key)
|
||||||
elif os.environ.get(key) and environment == True:
|
elif os.environ.get(key) and environment is True:
|
||||||
return os.environ.get(key)
|
return os.environ.get(key)
|
||||||
else:
|
else:
|
||||||
return default
|
return default
|
||||||
|
|
||||||
def parse_spotify_creds(ripper):
|
|
||||||
CLIENT_ID = check_sources(ripper, "SPOTIFY_CLIENT_ID", environment=True)
|
class Config:
|
||||||
CLIENT_SECRET = check_sources(ripper, "SPOTIFY_CLIENT_SECRET", environment=True)
|
|
||||||
|
def parse_spotify_creds(ripper):
|
||||||
|
CLIENT_ID = check_sources(ripper, "SPOTIFY_CLIENT_ID",
|
||||||
|
environment=True)
|
||||||
|
CLIENT_SECRET = check_sources(ripper, "SPOTIFY_CLIENT_SECRET",
|
||||||
|
environment=True)
|
||||||
return CLIENT_ID, CLIENT_SECRET
|
return CLIENT_ID, CLIENT_SECRET
|
||||||
|
|
||||||
def parse_search_terms(ripper):
|
@staticmethod
|
||||||
search_terms = check_sources(ripper, "additional_search_terms", "lyrics")
|
def parse_search_terms(ripper):
|
||||||
|
search_terms = check_sources(ripper, "additional_search_terms",
|
||||||
|
"lyrics")
|
||||||
return search_terms
|
return search_terms
|
||||||
|
|
||||||
def parse_artist(ripper):
|
def parse_artist(ripper):
|
||||||
artist = check_sources(ripper, "artist")
|
artist = check_sources(ripper, "artist")
|
||||||
return artist
|
return artist
|
||||||
|
|
||||||
def parse_directory(ripper):
|
@staticmethod
|
||||||
directory = check_sources(ripper, "custom_directory", where="post_processors")
|
def parse_directory(ripper):
|
||||||
if directory == None:
|
directory = check_sources(ripper, "custom_directory",
|
||||||
|
where="post_processors")
|
||||||
|
if directory is None:
|
||||||
directory = check_sources(ripper, "custom_directory", "~/Music")
|
directory = check_sources(ripper, "custom_directory", "~/Music")
|
||||||
return directory.replace("~", os.path.expanduser("~"))
|
return directory.replace("~", os.path.expanduser("~"))
|
||||||
|
|
||||||
def parse_default_flags(default=""):
|
def parse_default_flags(default=""):
|
||||||
if CONFIG.get("default_flags"):
|
if CONFIG.get("default_flags"):
|
||||||
args = sys.argv[1:] + CONFIG.get("default_flags")
|
args = sys.argv[1:] + CONFIG.get("default_flags")
|
||||||
else:
|
else:
|
||||||
args = default
|
args = default
|
||||||
return args
|
return args
|
||||||
|
|
||||||
def parse_organize(ripper):
|
def parse_organize(ripper):
|
||||||
organize = check_sources(ripper, "organize")
|
organize = check_sources(ripper, "organize")
|
||||||
if organize == None:
|
if organize is None:
|
||||||
return check_sources(ripper, "organize", False, where="post_processors")
|
return check_sources(ripper, "organize", False,
|
||||||
|
where="post_processors")
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def parse_search_terms(ripper):
|
|
||||||
search_terms = check_sources(ripper, "additional_search_terms", "lyrics")
|
|
||||||
return search_terms
|
|
Loading…
Reference in a new issue