mirror of
https://github.com/cooperhammond/irs.git
synced 2024-11-09 18:48:33 +00:00
-e/--exact flag feature
This commit is contained in:
parent
0edad1c255
commit
6a186b80df
|
@ -26,6 +26,9 @@ name. Must be used with -s/--song or -A/--album")
|
||||||
# Album
|
# Album
|
||||||
parser.add_argument("-A", "--album", dest="album", help="Specify album \
|
parser.add_argument("-A", "--album", dest="album", help="Specify album \
|
||||||
name")
|
name")
|
||||||
|
parser.add_argument("-e", "--exact", dest="exact", action="store_true",
|
||||||
|
help="The list will only be chosen if it equals the \
|
||||||
|
user input.")
|
||||||
|
|
||||||
# Playlist
|
# Playlist
|
||||||
parser.add_argument("-u", "--username", dest="username", help="Specify \
|
parser.add_argument("-u", "--username", dest="username", help="Specify \
|
||||||
|
|
|
@ -159,12 +159,13 @@ init, or in method arguments.")
|
||||||
else:
|
else:
|
||||||
soup = BeautifulSoup(CaptchaCheat.cheat_it(link), 'html.parser')
|
soup = BeautifulSoup(CaptchaCheat.cheat_it(link), 'html.parser')
|
||||||
|
|
||||||
# print(soup.prettify())
|
# 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-simple-endpoint style-scope ytd-video-renderer" in str(" ".join(link["class"])) or \
|
if "yt-simple-endpoint style-scope ytd-video-renderer" in str(" ".join(link["class"])) or \
|
||||||
"yt-uix-tile-link yt-ui-ellipsis yt-ui-ellipsis-2 yt-uix-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:
|
||||||
|
@ -173,7 +174,7 @@ init, or in method arguments.")
|
||||||
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
|
||||||
|
@ -181,11 +182,11 @@ 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 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
|
||||||
|
|
||||||
|
@ -200,6 +201,15 @@ 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)
|
||||||
|
|
||||||
|
@ -211,6 +221,7 @@ album".split(" ")
|
||||||
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 ;)
|
# 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 self.find_yt_url(song=song, artist=artist, additional_search=additional_search, caught_by_google=True)
|
||||||
|
|
||||||
|
|
||||||
|
@ -252,20 +263,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()
|
||||||
|
|
||||||
|
|
10
irs/utils.py
10
irs/utils.py
|
@ -90,8 +90,8 @@ class ObjManip: # Object Manipulation
|
||||||
|
|
||||||
def check_garbage_phrases(phrases, string, title):
|
def check_garbage_phrases(phrases, string, title):
|
||||||
for phrase in phrases:
|
for phrase in phrases:
|
||||||
if phrase in ObjManip.blank(string):
|
if phrase in string.lower():
|
||||||
if phrase not in ObjManip.blank(title):
|
if phrase not in title.lower():
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -443,6 +443,12 @@ class Config:
|
||||||
else:
|
else:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def parse_exact(ripper):
|
||||||
|
exact = check_sources(ripper, "exact")
|
||||||
|
if exact in (True, False):
|
||||||
|
return exact
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#==============
|
#==============
|
||||||
# Captcha Cheat
|
# Captcha Cheat
|
||||||
|
|
Loading…
Reference in a new issue