-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathargs.py
More file actions
62 lines (55 loc) · 2.33 KB
/
Copy pathargs.py
File metadata and controls
62 lines (55 loc) · 2.33 KB
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
60
61
62
import argparse
from bs4 import BeautifulSoup
import random
import requests
import config
from ssl_util import SharedSSLAdapter
import re
def get_parser():
parser = argparse.ArgumentParser(description="FetchJAV")
# store_true, not type=bool: argparse's bool("False") is truthy, so `--nogui False`
# would wrongly enable it. store_true makes the mere presence of the flag mean True.
parser.add_argument("--random", action='store_true',
help="Download a random recommended video")
parser.add_argument("--url", type=str, default="",
help="Jable TV URL to download")
parser.add_argument("--nogui", action='store_true',
help="Disable GUI mode")
parser.add_argument(
"-o", "--output", type=str, default="download", metavar="DIR",
help="Output directory for downloads (default: ./download)")
parser.add_argument(
"--max-workers-per-video", type=int,
choices=range(
config.MIN_WORKERS_PER_VIDEO,
config.MAX_WORKERS_PER_VIDEO + 1),
default=None, metavar="N",
help="Maximum segment download workers per video (1-16)")
parser.add_argument(
"--hot-reload", "-hr", "--watch", action='store_true',
help="Enable hot reloading mode (watches source files and restarts app on change)")
parser.add_argument(
"--watch-interval", type=float, default=1.0, metavar="SEC",
help="File watcher poll interval in seconds (default: 1.0)")
return parser
def av_recommand():
headers = {'User-Agent': 'Mozilla/5.0'}
url = 'https://jable.tv/'
try:
with requests.Session() as session:
session.mount('https://', SharedSSLAdapter())
response = session.get(
url, headers=headers, timeout=15,
**config.proxy_request_kwargs())
response.raise_for_status()
web_content = response.content
except Exception:
return None
# 得到繞過轉址後的 html
soup = BeautifulSoup(web_content, 'html.parser')
h6_tags = soup.find_all('h6', class_='title')
av_list = re.findall(r'https[^"]+', str(h6_tags))
if not av_list: # site changed/blocked -> avoid random.choice([]) IndexError
return None
return random.choice(av_list)
# print(av_recommand())