-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathytsearch.py
59 lines (39 loc) · 1.28 KB
/
ytsearch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import requests
import re
import subprocess
from pyfzf import FzfPrompt
from bs4 import BeautifulSoup
from channel import scrape
fzf = FzfPrompt()
def search(keyword):
try:
url = f"https://invidious.tiekoetter.com/search?q={keyword}"
r = requests.get(url)
soup = BeautifulSoup(r.content, "lxml",
multi_valued_attributes=None)
clear_list = []
for div_card in soup.find_all("div", class_="video-card-row"):
find_a = div_card.find("a").get("href")
find_a_name = div_card.find("a").text
clear_list.append(
f"{find_a_name} || https://www.youtube.com{find_a}")
ui = fzf.prompt(clear_list)
convert_to_str = "".join(ui)
video_link = re.search(
"(?P<url>https?://[^\s]+)", convert_to_str).group("url")
subprocess.run(["mpv", video_link])
except Exception:
print("\nGoodBye\n")
def main():
try:
user_action = input(
"Welcome! Enter action: \n1.Search, 2.Channel\n--->")
if user_action == "1":
word = input("Search:\n")
search(word)
else:
scrape()
except KeyboardInterrupt:
print("\nGoodBye\n")
if __name__ == "__main__":
main()