mirror of
https://github.com/cooperhammond/irs.git
synced 2025-01-17 21:17:07 +00:00
Merge pull request #24 from kepoorhampond/custom-text
Added custom hook text support
This commit is contained in:
commit
630800fded
|
@ -13,6 +13,9 @@ from .utils import YdlUtils, ObjManip, Config
|
||||||
from .metadata import Metadata
|
from .metadata import Metadata
|
||||||
from .metadata import find_album_and_track, parse_genre
|
from .metadata import find_album_and_track, parse_genre
|
||||||
|
|
||||||
|
# Config File and Flags
|
||||||
|
from .config import CONFIG
|
||||||
|
|
||||||
# Parsing
|
# Parsing
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
if sys.version_info[0] >= 3:
|
if sys.version_info[0] >= 3:
|
||||||
|
@ -29,6 +32,16 @@ else:
|
||||||
class Ripper:
|
class Ripper:
|
||||||
def __init__(self, args={}):
|
def __init__(self, args={}):
|
||||||
self.args = args
|
self.args = args
|
||||||
|
if self.args.get("hook-text") is None:
|
||||||
|
self.args["hook-text"] = {
|
||||||
|
"youtube": "Finding Youtube link ...",
|
||||||
|
"list": '{0}: "{1}" by "{2}"',
|
||||||
|
"song": 'Downloading "{0}" by "{1}"',
|
||||||
|
"converting": "Converting to mp3 ...",
|
||||||
|
}
|
||||||
|
if self.args["hook-text"].get("converting") is not None:
|
||||||
|
CONFIG["converting"] = self.args["hook-text"]["converting"]
|
||||||
|
|
||||||
self.locations = []
|
self.locations = []
|
||||||
self.type = None
|
self.type = None
|
||||||
try:
|
try:
|
||||||
|
@ -42,7 +55,7 @@ class Ripper:
|
||||||
client_credentials_manager=client_credentials_manager)
|
client_credentials_manager=client_credentials_manager)
|
||||||
|
|
||||||
self.authorized = True
|
self.authorized = True
|
||||||
except Exception as e:
|
except Exception:
|
||||||
self.spotify = spotipy.Spotify()
|
self.spotify = spotipy.Spotify()
|
||||||
self.authorized = False
|
self.authorized = False
|
||||||
|
|
||||||
|
@ -111,8 +124,7 @@ class Ripper:
|
||||||
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 is None:
|
if additional_search is None:
|
||||||
additional_search = Config.parse_search_terms(self)
|
additional_search = Config.parse_search_terms(self)
|
||||||
else:
|
print(self.args["hook-text"].get("youtube"))
|
||||||
print("Finding Youtube link ...")
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if not song:
|
if not song:
|
||||||
|
@ -123,8 +135,6 @@ class Ripper:
|
||||||
raise ValueError("Must specify song_title/artist in `args` with \
|
raise ValueError("Must specify song_title/artist in `args` with \
|
||||||
init, or in method arguments.")
|
init, or in method arguments.")
|
||||||
|
|
||||||
print("Finding Youtube Link ...")
|
|
||||||
|
|
||||||
search_terms = song + " " + artist + " " + additional_search
|
search_terms = song + " " + artist + " " + additional_search
|
||||||
query_string = urlencode({"search_query": (
|
query_string = urlencode({"search_query": (
|
||||||
search_terms.encode('utf-8'))})
|
search_terms.encode('utf-8'))})
|
||||||
|
@ -238,8 +248,9 @@ with init, or in method arguments.")
|
||||||
if the_list is not None:
|
if the_list is not None:
|
||||||
YdlUtils.clear_line()
|
YdlUtils.clear_line()
|
||||||
|
|
||||||
print(type.title() + ': "%s" by \
|
print(self.args["hook-text"].get("list")
|
||||||
"%s"' % (the_list["name"], the_list["artists"][0]["name"]))
|
.format(type.title(), the_list["name"],
|
||||||
|
the_list["artists"][0]["name"]))
|
||||||
|
|
||||||
compilation = ""
|
compilation = ""
|
||||||
if type == "album":
|
if type == "album":
|
||||||
|
@ -358,7 +369,7 @@ init, or in method arguments.")
|
||||||
|
|
||||||
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(self.args["hook-text"].get("song").format(song, artist))
|
||||||
|
|
||||||
file_name = str(data["file_prefix"] + ObjManip.blank(song, False) +
|
file_name = str(data["file_prefix"] + ObjManip.blank(song, False) +
|
||||||
".mp3")
|
".mp3")
|
||||||
|
|
|
@ -49,7 +49,7 @@ class YdlUtils:
|
||||||
|
|
||||||
def my_hook(d):
|
def my_hook(d):
|
||||||
if d['status'] == 'finished':
|
if d['status'] == 'finished':
|
||||||
print("Converting to mp3 ...")
|
print(CONFIG["converting"])
|
||||||
|
|
||||||
|
|
||||||
# ================================
|
# ================================
|
||||||
|
@ -271,8 +271,7 @@ def banner():
|
||||||
.format(BYELLOW, BRED, BYELLOW), COLS))
|
.format(BYELLOW, BRED, BYELLOW), COLS))
|
||||||
|
|
||||||
flush_puts(center_colors("{0}Made with 😈 by: {1}Kepoor Hampond \
|
flush_puts(center_colors("{0}Made with 😈 by: {1}Kepoor Hampond \
|
||||||
({2}kepoorhampond{3})".format(BBLUE, BYELLOW,
|
({2}kepoorhampond{3})".format(BBLUE, BYELLOW, BRED, BYELLOW) + END, COLS))
|
||||||
BRED, BYELLOW) + END, COLS))
|
|
||||||
|
|
||||||
flush_puts(center_colors("{0}Version: {1}".format(BBLUE, BYELLOW) +
|
flush_puts(center_colors("{0}Version: {1}".format(BBLUE, BYELLOW) +
|
||||||
pkg_resources.get_distribution("irs").version, COLS))
|
pkg_resources.get_distribution("irs").version, COLS))
|
||||||
|
|
Loading…
Reference in a new issue