-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvideo_finder.py
38 lines (35 loc) · 1.38 KB
/
video_finder.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
# this module will find one video with given quality
from bs4 import BeautifulSoup as bs
import requests
import sys
import re
import json
headers = {}
with open(f"{sys.path[0]}/headers", "r") as fli:
fli = json.load(fli)
if type(fli) != dict:
print("err: the header file should be a json file", file=sys.stderr)
elif type(fli) == dict:
headers = fli
def main(link, quality):
found_or_not = str()
quality = ".*"+str(quality)+".*" # This regex find the specify quality in the list of all quality
req = requests.get(link, headers=headers)
if(req.status_code == 200):
result = req.content
soup = bs(result, "html.parser")
# Finding name of video
name = soup.h1.string+".mp4"
# Finding video download url
fquality = soup.find("div",attrs={"class":"dropdown-content"}).find_all("a")
videolinks = re.findall("href=\"(.*)\".*target", str(fquality)) # This Regex return a list of all quality of video
for i in videolinks:
if(re.findall(quality, i)):
found_or_not = i
return i, name
if(len(found_or_not) <= 0):
print(f"Video with given quality {quality} not found. link: {link}")
else:
print(link)
print("err in video finder: http status code is: "+str(req.status_code))
sys.exit(req.status_code)