mirror of
https://github.com/cooperhammond/irs.git
synced 2025-07-06 15:40:32 +00:00
ffmpeg checker init
This commit is contained in:
parent
6a186b80df
commit
37fd4d7ab7
|
@ -133,7 +133,7 @@ class Ripper:
|
||||||
|
|
||||||
return locations
|
return locations
|
||||||
|
|
||||||
def find_yt_url(self, song=None, artist=None, additional_search=None, caught_by_google=False):
|
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")))
|
||||||
|
@ -182,6 +182,9 @@ album row at @ session".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,
|
if ObjManip.check_garbage_phrases(garbage_phrases,
|
||||||
link["title"], song):
|
link["title"], song):
|
||||||
continue
|
continue
|
||||||
|
@ -213,16 +216,19 @@ album row at @ session".split(" ")
|
||||||
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)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return ("https://youtube.com" + self.code["href"], self.code["title"])
|
return ("https://youtube.com" + self.code["href"], self.code["title"])
|
||||||
except TypeError:
|
except TypeError:
|
||||||
# Assuming Google catches you trying to search youtube for music ;)
|
if first is not True:
|
||||||
print("Trying to bypass google captcha.")
|
return self.find_yt_url(song, artist, additional_search, caught_by_google, first=True)
|
||||||
return self.find_yt_url(song=song, artist=artist, additional_search=additional_search, caught_by_google=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)
|
||||||
|
|
||||||
|
|
||||||
def album(self, title, artist=None): # Alias for spotify_list("album", ..)
|
def album(self, title, artist=None): # Alias for spotify_list("album", ..)
|
||||||
|
@ -425,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': [{
|
||||||
|
@ -437,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 True:
|
||||||
|
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])
|
||||||
|
|
||||||
|
|
32
irs/utils.py
32
irs/utils.py
|
@ -367,26 +367,13 @@ def console(ripper):
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
||||||
"""
|
|
||||||
# =====================
|
|
||||||
# Config File and Flags
|
|
||||||
# =====================
|
|
||||||
|
|
||||||
def check_sources(ripper, key, default=None, environment=False, where=None):
|
|
||||||
if where is not None:
|
|
||||||
tmp_args = ripper.args.get(where)
|
|
||||||
else:
|
|
||||||
tmp_args = ripper.args
|
|
||||||
|
|
||||||
if tmp_args.get(key):
|
|
||||||
return tmp_args.get(key)
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
# ===========
|
# ===========
|
||||||
# CONFIG FILE
|
# CONFIG FILE
|
||||||
# ===========
|
# ===========
|
||||||
|
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
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 is not None and ripper.args.get(where):
|
# if where is not None and ripper.args.get(where):
|
||||||
|
@ -448,6 +435,19 @@ class Config:
|
||||||
if exact in (True, False):
|
if exact in (True, False):
|
||||||
return exact
|
return exact
|
||||||
|
|
||||||
|
def check_ffmpeg():
|
||||||
|
for c in ["ffmpeg", "ffprobe"]:
|
||||||
|
try:
|
||||||
|
with open(os.devnull, 'w') as shutup:
|
||||||
|
subprocess.call([c], stdout=shutup, stderr=shutup)
|
||||||
|
except OSError as e:
|
||||||
|
if e.errno == os.errno.ENOENT:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
# Something else went wrong while trying to run `wget`
|
||||||
|
raise
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#==============
|
#==============
|
||||||
|
|
Loading…
Reference in a new issue