|
@@ -1,20 +1,40 @@
|
|
|
import html
|
|
|
import os
|
|
|
+from urllib.parse import urlparse
|
|
|
+
|
|
|
import requests
|
|
|
|
|
|
|
|
|
class DownLoad:
|
|
|
@classmethod
|
|
|
- def download_video(cls, video_url, video_path_url):
|
|
|
+ def download_video(cls, video_url, video_path_url, tag_transport_channel):
|
|
|
video = video_path_url + 'video.mp4'
|
|
|
- url_type = html.unescape(video_url).split('?')[0]
|
|
|
- if ".m3u8" in url_type:
|
|
|
- ts_video = video_path_url + 'video.ts'
|
|
|
- status_code = cls.download_m3u8_video(video_url, ts_video)
|
|
|
- if status_code == False:
|
|
|
- return video
|
|
|
- cls.convert_ts_to_mp4(ts_video, video)
|
|
|
- return video
|
|
|
+ if tag_transport_channel == "抖音":
|
|
|
+ headers = {
|
|
|
+ 'accept': '*/*',
|
|
|
+ 'accept-encoding': 'identity;q=1, *;q=0',
|
|
|
+ 'accept-language': 'zh-CN,zh;q=0.9',
|
|
|
+ 'cache-control': 'no-cache',
|
|
|
+ 'connection': 'keep-alive',
|
|
|
+ 'host': urlparse(video_url).netloc,
|
|
|
+ 'pragma': 'no-cache',
|
|
|
+ 'range': 'bytes=0-',
|
|
|
+ 'referer': video_url,
|
|
|
+ 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36',
|
|
|
+ }
|
|
|
+ payload = {}
|
|
|
+ for i in range(3):
|
|
|
+ try:
|
|
|
+ response = requests.request("GET", video_url, headers=headers, data=payload, timeout=240)
|
|
|
+ if response.status_code == 200:
|
|
|
+ # 以二进制写入模式打开文件
|
|
|
+
|
|
|
+ with open(f"{video}", "wb") as file:
|
|
|
+ # 将响应内容写入文件
|
|
|
+ file.write(response.content)
|
|
|
+ return video
|
|
|
+ except Exception:
|
|
|
+ return video
|
|
|
else:
|
|
|
try:
|
|
|
for i in range(3):
|