|
@@ -24,49 +24,52 @@ from data_channel.piaoquan import PQ
|
|
|
class CarryViode:
|
|
|
|
|
|
def get_text_dy_video(self,url):
|
|
|
- try:
|
|
|
- if "&vid=" in url:
|
|
|
- parsed_url = urlparse(url)
|
|
|
- params = parse_qs(parsed_url.query)
|
|
|
- video_id = params.get('vid', [None])[0]
|
|
|
- elif "?modal_id=" in url:
|
|
|
- parsed_url = urlparse(url)
|
|
|
- params = parse_qs(parsed_url.query)
|
|
|
- video_id = params.get('modal_id', [None])[0]
|
|
|
- else:
|
|
|
+ max_retries = 3
|
|
|
+ retry_count = 0
|
|
|
+ while retry_count < max_retries:
|
|
|
+ try:
|
|
|
+ if "&vid=" in url:
|
|
|
+ parsed_url = urlparse(url)
|
|
|
+ params = parse_qs(parsed_url.query)
|
|
|
+ video_id = params.get('vid', [None])[0]
|
|
|
+ elif "?modal_id=" in url:
|
|
|
+ parsed_url = urlparse(url)
|
|
|
+ params = parse_qs(parsed_url.query)
|
|
|
+ video_id = params.get('modal_id', [None])[0]
|
|
|
+ else:
|
|
|
+ headers = {
|
|
|
+ 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;'
|
|
|
+ 'q=0.8,application/signed-exchange;v=b3;q=0.7',
|
|
|
+ 'Accept-Language': 'zh-CN,zh;q=0.9',
|
|
|
+ 'Cache-Control': 'no-cache',
|
|
|
+ 'Pragma': 'no-cache',
|
|
|
+ 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) '
|
|
|
+ 'Chrome/127.0.0.0 Safari/537.36',
|
|
|
+ }
|
|
|
+ response = requests.request(url=url, method='GET', headers=headers, allow_redirects=False, timeout=30)
|
|
|
+ location = response.headers.get('Location', None)
|
|
|
+ video_id = re.search(r'/video/(\d+)/?', location.split('?')[0] if location else url).group(1)
|
|
|
+ url = "http://8.217.192.46:8889/crawler/dou_yin/detail"
|
|
|
+ payload = json.dumps({
|
|
|
+ "content_id": str(video_id)
|
|
|
+ })
|
|
|
headers = {
|
|
|
- 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;'
|
|
|
- 'q=0.8,application/signed-exchange;v=b3;q=0.7',
|
|
|
- 'Accept-Language': 'zh-CN,zh;q=0.9',
|
|
|
- 'Cache-Control': 'no-cache',
|
|
|
- 'Pragma': 'no-cache',
|
|
|
- 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) '
|
|
|
- 'Chrome/127.0.0.0 Safari/537.36',
|
|
|
+ 'Content-Type': 'application/json'
|
|
|
}
|
|
|
- response = requests.request(url=url, method='GET', headers=headers, allow_redirects=False, timeout=30)
|
|
|
- location = response.headers.get('Location', None)
|
|
|
- video_id = re.search(r'/video/(\d+)/?', location.split('?')[0] if location else url).group(1)
|
|
|
- url = "http://8.217.192.46:8889/crawler/dou_yin/detail"
|
|
|
- payload = json.dumps({
|
|
|
- "content_id": str(video_id)
|
|
|
- })
|
|
|
- headers = {
|
|
|
- 'Content-Type': 'application/json'
|
|
|
- }
|
|
|
|
|
|
- response = requests.request("POST", url, headers=headers, data=payload, timeout= 30)
|
|
|
- response = response.json()
|
|
|
- code = response["code"]
|
|
|
- if code == 0:
|
|
|
- data = response["data"]["data"]
|
|
|
- video_url = data["video_url_list"][0]["video_url"]
|
|
|
- original_title = data["title"]
|
|
|
- return video_url, original_title
|
|
|
- else:
|
|
|
- return None, None
|
|
|
- except Exception as e:
|
|
|
- logger.error(f"[+] 抖音{url}获取视频链接失败,失败信息{e}")
|
|
|
- return None, None
|
|
|
+ response = requests.request("POST", url, headers=headers, data=payload, timeout= 30)
|
|
|
+ response = response.json()
|
|
|
+ code = response["code"]
|
|
|
+ if code == 0:
|
|
|
+ data = response["data"]["data"]
|
|
|
+ video_url = data["video_url_list"][0]["video_url"]
|
|
|
+ original_title = data["title"]
|
|
|
+ return video_url, original_title
|
|
|
+ except Exception as e:
|
|
|
+ retry_count += 1
|
|
|
+ logger.error(f"[+] 抖音{url}获取视频链接失败,失败信息{e}")
|
|
|
+ time.sleep(1)
|
|
|
+ return None, None
|
|
|
|
|
|
def get_text_ks_video(self,url):
|
|
|
try:
|