-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutil.py
64 lines (53 loc) · 1.57 KB
/
util.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
import re
from m3u8 import M3U8
from urllib.request import getproxies
import httpx
headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/99.0.4844.74 Safari/537.36'}
def getporoxy():
proxy = getproxies()
if proxy:
proxy['https'] = proxy['https'].replace('https','http')
del proxy['ftp']
return proxy
return None
def gethttpxporoxy():
proxy = getproxies()
if proxy:
proxy['https'] = proxy['https'].replace('https','http')
del proxy['ftp']
d = {}
d['http://'] = proxy['http']
d['https://'] = proxy['https']
return d
return None
def loadm3u8(url,b=False):
r = httpx.get(url, verify=False, headers=headers,proxies=gethttpxporoxy())
if b:
# baseurl =r.url
l = url.split("/")
baseurl = l[0] + "//" + l[2]
else:
baseurl = "/".join(url.split("/")[:-1])+"/"
# l = r.url.split("/")
# baseurl = l[0] + "//" + l[2]
# baseurl = urljoin(url, '.')
return M3U8(r.text, base_uri=baseurl, custom_tags_parser=None)
def checkhentai(url):
if "uncensoredhentai" in url:
return True
# elif "hentai.tv" in url:
# return True
elif "animeidhentai" in url:
return True
def checkNameValid(name=None):
"""
检测Windows文件名称!
"""
reg = re.compile(r'[\\/:*?"<>|\r\n]+')
valid_name = reg.findall(name)
if valid_name:
for nv in valid_name:
name = name.replace(nv, "_")
return name