提交 455457ed 编写于 作者: 小小明-代码实体's avatar 小小明-代码实体

Merge branch 'as604049322-master-patch-04339' into 'master'

更新douyin/抖音短视频合集批量下载器v0.2.exe, douyin/douyin_download_ui.py, douyin/douyin.py, douyin/tools.py

See merge request !1
......@@ -20,11 +20,12 @@ def get_video_url(url, cookies):
r'<script id="RENDER_DATA" type="application/json">([^<>]+)</script>', res.text)
data = json.loads(unquote(RENDER_DATA))
key = '8' if url.find("collection") != -1 else '34'
if key not in data:
print("视频无效...")
try:
detail = data[key]['aweme']['detail']
title = detail['desc']
except Exception as e:
print(f"{url}无效,报错的key:", e)
return
detail = data[key]['aweme']['detail']
title = detail['desc']
if not title:
title, = re.findall("<title[^>]+>\s*([^>]+)\s*</title>", res.text)
video_url = urljoin(url, detail['video']['playApi'])
......@@ -64,7 +65,7 @@ def download_video(video_url, title, folder):
yield done_size, cost_time, total
# print(f"进度:{done_size / total:.2%},{done_size / cost_time / 1024 / 1024:.2f}MB/s")
cost_time = time.time() - start_time
print(f'文件:{basename} 下载完成!耗时:{cost_time:0.2f} 秒')
print(f'文件:{basename} 下载完成!\n耗时:{cost_time:0.2f} 秒')
# def download_douyin_collection(collection_urls, collection_title, save_dir="."):
......@@ -99,7 +100,11 @@ def download_douyin(url, download_collection=False, save_dir="."):
if not cookies:
print("从谷歌游览器提取的douyin cookie为空,请确认本地80以上版本的谷歌游览器有访问过抖音主页")
return
video_url, title, collection_urls, collection_title = get_video_url(url, cookies)
tmp = get_video_url(url, cookies)
if tmp is None:
print("下载结束!!!")
return
video_url, title, collection_urls, collection_title = tmp
if download_collection and collection_urls:
n = len(collection_urls)
print(f"该合集共解析出{n}个视频,合集名称:{collection_title}")
......@@ -107,7 +112,11 @@ def download_douyin(url, download_collection=False, save_dir="."):
os.makedirs(save_dir, exist_ok=True)
for i, collection_url in enumerate(collection_urls, 1):
num = int(collection_url[collection_url.rfind("/") + 1:])
video_url, title, _, _ = get_video_url(collection_url, cookies)
tmp = get_video_url(collection_url, cookies)
if tmp is None:
print("无效视频:", collection_url, "已跳过...")
continue
video_url, title, _, _ = tmp
for done_size, cost_time, total in download_video(video_url, f"{num:>3d}. {title}", save_dir):
yield i, n, done_size, cost_time, total
else:
......
......@@ -64,7 +64,7 @@ while True:
url = values["url"]
if url.startswith("https://v.douyin.com/"):
url = parse_vdouyin_url(url)
if not url.startswith("https://www.douyin.com/video/"):
if not url.startswith("https://www.douyin.com/video/") and not url.startswith("https://www.douyin.com/collection/"):
print("视频地址无效!!!仅支持https://www.douyin.com/video/开头的抖音地址")
continue
window["url"].Update(url)
......@@ -74,8 +74,10 @@ while True:
else:
save_dir = os.path.abspath(".")
window["save_dir"].Update(save_dir)
flag = False
for i, n, done_size, cost_time, total in download_douyin(url, values["download_collection"],
save_dir):
flag = True
window["video_bar"].Update(i * 1000 // n)
if done_size == total:
total_cost_time += cost_time
......@@ -89,7 +91,7 @@ while True:
window["progressbar"].Update(done_size * 1000 // total)
message = f"{done_size / 1024 / 1024:.2f}MB/{total / 1024 / 1024:.2f}MB\n{done_size / cost_time / 1024 / 1024:.2f}MB/s"
window["message"].Update(message)
if values["open_folder"]:
if flag and values["open_folder"]:
sub.Popen(f"explorer {save_dir}", shell=False)
elif event == "清空输出":
window["out"].Update("")
......
......@@ -9,7 +9,6 @@ import base64
import json
import os
import sqlite3
import subprocess
import winreg
import win32crypt
......@@ -64,5 +63,5 @@ def get_chrome_path():
if __name__ == '__main__':
# print(fetch_host_cookie("douyin.com"))
print(fetch_host_cookie("douyin.com"))
print(get_chrome_path())
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册