mirror of
https://github.com/cooperhammond/irs.git
synced 2024-12-22 17:35:28 +00:00
reset ffmpeg-checker
This commit is contained in:
parent
13c71da9c4
commit
d21ac18059
108
irs/ripper.py
108
irs/ripper.py
|
@ -18,7 +18,7 @@ from spotipy.oauth2 import SpotifyClientCredentials
|
||||||
|
|
||||||
|
|
||||||
# Local utilities
|
# Local utilities
|
||||||
from .utils import YdlUtils, ObjManip, Config
|
from .utils import YdlUtils, ObjManip, Config, CaptchaCheat
|
||||||
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
|
||||||
|
|
||||||
|
@ -58,6 +58,9 @@ class Ripper:
|
||||||
client_credentials_manager = SpotifyClientCredentials(CLIENT_ID,
|
client_credentials_manager = SpotifyClientCredentials(CLIENT_ID,
|
||||||
CLIENT_SECRET
|
CLIENT_SECRET
|
||||||
# Stupid lint
|
# Stupid lint
|
||||||
|
# and stupid
|
||||||
|
# long var
|
||||||
|
# names
|
||||||
)
|
)
|
||||||
|
|
||||||
self.spotify = spotipy.Spotify(
|
self.spotify = spotipy.Spotify(
|
||||||
|
@ -130,7 +133,7 @@ class Ripper:
|
||||||
|
|
||||||
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, caught_by_google=False, first=False):
|
||||||
if additional_search is None:
|
if additional_search is None:
|
||||||
additional_search = Config.parse_search_terms(self)
|
additional_search = Config.parse_search_terms(self)
|
||||||
print(str(self.args["hook-text"].get("youtube")))
|
print(str(self.args["hook-text"].get("youtube")))
|
||||||
|
@ -150,22 +153,28 @@ init, or in method arguments.")
|
||||||
search_terms.encode('utf-8'))})
|
search_terms.encode('utf-8'))})
|
||||||
link = "http://www.youtube.com/results?" + query_string
|
link = "http://www.youtube.com/results?" + query_string
|
||||||
|
|
||||||
html_content = urlopen(link).read()
|
if not caught_by_google:
|
||||||
soup = BeautifulSoup(html_content, 'html.parser') # .prettify()
|
html_content = urlopen(link).read()
|
||||||
|
soup = BeautifulSoup(html_content, 'html.parser')
|
||||||
|
else:
|
||||||
|
soup = BeautifulSoup(CaptchaCheat.cheat_it(link), 'html.parser')
|
||||||
|
|
||||||
|
# with open("index.html", "w") as f:
|
||||||
|
# f.write(soup.prettify().encode('utf-8'))
|
||||||
|
|
||||||
def find_link(link):
|
def find_link(link):
|
||||||
try:
|
try:
|
||||||
if "yt-uix-tile-link yt-ui-ellipsis yt-ui-ellipsis-2 yt-uix-\
|
if "yt-simple-endpoint style-scope ytd-video-renderer" in str(" ".join(link["class"])) or \
|
||||||
sessionlink spf-link" in str(" ".join(link["class"])):
|
"yt-uix-tile-link yt-ui-ellipsis yt-ui-ellipsis-2 yt-uix-sessionlink spf-link " in str(" ".join(link["class"])):
|
||||||
if "&list=" not in link["href"]:
|
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 \
|
garbage_phrases = "cover album live clean rare version full full \
|
||||||
album".split(" ")
|
album row at @ session".split(" ")
|
||||||
|
|
||||||
self.code = None
|
self.code = None
|
||||||
counter = 0
|
counter = 0
|
||||||
|
@ -173,11 +182,14 @@ album".split(" ")
|
||||||
while self.code is None and counter <= 10:
|
while self.code is None and counter <= 10:
|
||||||
counter += 1
|
counter += 1
|
||||||
for link in results:
|
for link in results:
|
||||||
|
if first == True:
|
||||||
|
self.code = link
|
||||||
|
break
|
||||||
|
if ObjManip.check_garbage_phrases(garbage_phrases,
|
||||||
|
link["title"], song):
|
||||||
|
continue
|
||||||
if ObjManip.blank_include(link["title"], song) and \
|
if ObjManip.blank_include(link["title"], song) and \
|
||||||
ObjManip.blank_include(link["title"], artist):
|
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
|
||||||
|
|
||||||
|
@ -192,16 +204,32 @@ album".split(" ")
|
||||||
self.code = link
|
self.code = link
|
||||||
break
|
break
|
||||||
|
|
||||||
|
if self.code is None:
|
||||||
|
for link in results:
|
||||||
|
if ObjManip.check_garbage_phrases(garbage_phrases,
|
||||||
|
link["title"], song):
|
||||||
|
continue
|
||||||
|
if ObjManip.blank_include(link["title"], song):
|
||||||
|
self.code = link
|
||||||
|
break
|
||||||
|
|
||||||
if self.code is None:
|
if self.code is None:
|
||||||
song = ObjManip.limit_song_name(song)
|
song = ObjManip.limit_song_name(song)
|
||||||
|
|
||||||
if self.code is None:
|
if self.code is None and first is not True:
|
||||||
if additional_search == "lyrics":
|
if additional_search == "lyrics":
|
||||||
return self.find_yt_url(song, artist, "")
|
return self.find_yt_url(song, artist, additional_search, caught_by_google, first)
|
||||||
else:
|
|
||||||
self.code = results[0]
|
try:
|
||||||
|
return ("https://youtube.com" + self.code["href"], self.code["title"])
|
||||||
|
except TypeError:
|
||||||
|
if first is not True:
|
||||||
|
return self.find_yt_url(song, artist, additional_search, caught_by_google, first=True)
|
||||||
|
|
||||||
|
# # Assuming Google catches you trying to search youtube for music ;)
|
||||||
|
# print("Trying to bypass google captcha.")
|
||||||
|
# return self.find_yt_url(song=song, artist=artist, additional_search=additional_search, caught_by_google=True)
|
||||||
|
|
||||||
return ("https://youtube.com" + self.code["href"], self.code["title"])
|
|
||||||
|
|
||||||
def album(self, title, artist=None): # Alias for spotify_list("album", ..)
|
def album(self, title, artist=None): # Alias for spotify_list("album", ..)
|
||||||
return self.spotify_list("album", title=title, artist=artist)
|
return self.spotify_list("album", title=title, artist=artist)
|
||||||
|
@ -241,20 +269,37 @@ with init, or in method arguments.")
|
||||||
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 ObjManip.blank_include(list_["name"], title):
|
if Config.parse_exact(self) == True:
|
||||||
if Config.parse_artist(self):
|
if list_["name"].encode("utf-8") == title.encode("utf-8"):
|
||||||
if ObjManip.blank_include(list_["artists"][0]["name"],
|
if Config.parse_artist(self):
|
||||||
Config.parse_artist(self)):
|
if list_["artists"][0]["name"].encode("utf-8") == \
|
||||||
the_list = self.spotify.album(list_["uri"])
|
Config.parse_artist(self).encode('utf-8'):
|
||||||
break
|
the_list = self.spotify.album(list_["uri"])
|
||||||
else:
|
break
|
||||||
if type == "album":
|
|
||||||
the_list = self.spotify.album(list_["uri"])
|
|
||||||
else:
|
else:
|
||||||
the_list = self.spotify.user_playlist(
|
if type == "album":
|
||||||
list_["owner"]["id"], list_["uri"])
|
the_list = self.spotify.album(list_["uri"])
|
||||||
the_list["artists"] = [{"name": username}]
|
else:
|
||||||
break
|
the_list = self.spotify.user_playlist(
|
||||||
|
list_["owner"]["id"], list_["uri"])
|
||||||
|
the_list["artists"] = [{"name": username}]
|
||||||
|
break
|
||||||
|
|
||||||
|
else:
|
||||||
|
if ObjManip.blank_include(list_["name"], title):
|
||||||
|
if Config.parse_artist(self):
|
||||||
|
if ObjManip.blank_include(list_["artists"][0]["name"],
|
||||||
|
Config.parse_artist(self)):
|
||||||
|
the_list = self.spotify.album(list_["uri"])
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
if type == "album":
|
||||||
|
the_list = self.spotify.album(list_["uri"])
|
||||||
|
else:
|
||||||
|
the_list = self.spotify.user_playlist(
|
||||||
|
list_["owner"]["id"], list_["uri"])
|
||||||
|
the_list["artists"] = [{"name": username}]
|
||||||
|
break
|
||||||
if the_list is not None:
|
if the_list is not None:
|
||||||
YdlUtils.clear_line()
|
YdlUtils.clear_line()
|
||||||
|
|
||||||
|
@ -386,7 +431,6 @@ init, or in method arguments.")
|
||||||
print(self.args["hook-text"].get("song").format(song, artist))
|
print(self.args["hook-text"].get("song").format(song, artist))
|
||||||
|
|
||||||
file_name = data["file_prefix"] + ObjManip.blank(song, False) + ".mp3"
|
file_name = data["file_prefix"] + ObjManip.blank(song, False) + ".mp3"
|
||||||
|
|
||||||
ydl_opts = {
|
ydl_opts = {
|
||||||
'format': 'bestaudio/best',
|
'format': 'bestaudio/best',
|
||||||
'postprocessors': [{
|
'postprocessors': [{
|
||||||
|
@ -398,9 +442,11 @@ init, or in method arguments.")
|
||||||
'progress_hooks': [YdlUtils.my_hook],
|
'progress_hooks': [YdlUtils.my_hook],
|
||||||
'output': "tmp_file",
|
'output': "tmp_file",
|
||||||
'prefer-ffmpeg': True,
|
'prefer-ffmpeg': True,
|
||||||
'ffmpeg_location': os.path.expanduser("~/.irs/bin/")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if Config.check_ffmpeg() is False:
|
||||||
|
ydl_opts.update({'ffmpeg_location': os.path.expanduser("~/.irs/bin/")})
|
||||||
|
|
||||||
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
||||||
ydl.download([video_url])
|
ydl.download([video_url])
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue