Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -10,13 +10,14 @@ import json
|
|
10 |
|
11 |
|
12 |
def dlvid(vid):
|
|
|
13 |
url = f"https://www.nicovideo.jp/watch/{vid}"
|
14 |
headers = {
|
15 |
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36 Edg/124.0.0.0',
|
16 |
}
|
17 |
|
18 |
# 发送请求
|
19 |
-
response =
|
20 |
if response.status_code == 200:
|
21 |
# 解析 HTML
|
22 |
soup = BeautifulSoup(response.text, 'html.parser')
|
@@ -50,7 +51,7 @@ def dlvid(vid):
|
|
50 |
'x-request-with': 'https://www.nicovideo.jp'
|
51 |
}
|
52 |
|
53 |
-
response =
|
54 |
|
55 |
hlsjson=response.json()
|
56 |
hlsuri=hlsjson['data']['contentUrl']
|
@@ -60,7 +61,7 @@ def dlvid(vid):
|
|
60 |
|
61 |
# 使用 ffmpeg 将 m3u8 转换为 mp4
|
62 |
mp3link = hlsuri # 假设你的 m3u8 地址存储在 mp3link 中
|
63 |
-
ffmpeg_command = f'ffmpeg -protocol_whitelist "concat,file,http,https,tcp,tls,crypto" -i "{mp3link}" -c copy "test.mp4"'
|
64 |
os.system(ffmpeg_command)
|
65 |
return 'test.mp4'
|
66 |
else:
|
|
|
10 |
|
11 |
|
12 |
def dlvid(vid):
|
13 |
+
s = requests.Session()
|
14 |
url = f"https://www.nicovideo.jp/watch/{vid}"
|
15 |
headers = {
|
16 |
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36 Edg/124.0.0.0',
|
17 |
}
|
18 |
|
19 |
# 发送请求
|
20 |
+
response = s.get(url, headers=headers)
|
21 |
if response.status_code == 200:
|
22 |
# 解析 HTML
|
23 |
soup = BeautifulSoup(response.text, 'html.parser')
|
|
|
51 |
'x-request-with': 'https://www.nicovideo.jp'
|
52 |
}
|
53 |
|
54 |
+
response = s.request("POST", url, headers=headers, data=payload)
|
55 |
|
56 |
hlsjson=response.json()
|
57 |
hlsuri=hlsjson['data']['contentUrl']
|
|
|
61 |
|
62 |
# 使用 ffmpeg 将 m3u8 转换为 mp4
|
63 |
mp3link = hlsuri # 假设你的 m3u8 地址存储在 mp3link 中
|
64 |
+
ffmpeg_command = f'ffmpeg -protocol_whitelist "concat,file,http,https,tcp,tls,crypto" -i "{mp3link}" -c copy -cookies "{s.cookies.get_dict()}" "test.mp4"'
|
65 |
os.system(ffmpeg_command)
|
66 |
return 'test.mp4'
|
67 |
else:
|