|
@@ -0,0 +1,722 @@
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+import base64
|
|
|
|
+import json
|
|
|
|
+import os
|
|
|
|
+import random
|
|
|
|
+import string
|
|
|
|
+import sys
|
|
|
|
+import time
|
|
|
|
+import requests
|
|
|
|
+import urllib3
|
|
|
|
+from requests.adapters import HTTPAdapter
|
|
|
|
+from selenium import webdriver
|
|
|
|
+from selenium.webdriver import DesiredCapabilities
|
|
|
|
+from selenium.webdriver.chrome.service import Service
|
|
|
|
+sys.path.append(os.getcwd())
|
|
|
|
+from common.common import Common
|
|
|
|
+from common.feishu import Feishu
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+class XiguaRecommend:
|
|
|
|
+ @classmethod
|
|
|
|
+ def random_signature(cls):
|
|
|
|
+ src_digits = string.digits
|
|
|
|
+ src_uppercase = string.ascii_uppercase
|
|
|
|
+ src_lowercase = string.ascii_lowercase
|
|
|
|
+ digits_num = random.randint(1, 6)
|
|
|
|
+ uppercase_num = random.randint(1, 26 - digits_num - 1)
|
|
|
|
+ lowercase_num = 26 - (digits_num + uppercase_num)
|
|
|
|
+ password = random.sample(src_digits, digits_num) + random.sample(src_uppercase, uppercase_num) + random.sample(
|
|
|
|
+ src_lowercase, lowercase_num)
|
|
|
|
+ random.shuffle(password)
|
|
|
|
+ new_password = 'AAAAAAAAAA' + ''.join(password)[10:-4] + 'AAAB'
|
|
|
|
+ new_password_start = new_password[0:18]
|
|
|
|
+ new_password_end = new_password[-7:]
|
|
|
|
+ if new_password[18] == '8':
|
|
|
|
+ new_password = new_password_start + 'w' + new_password_end
|
|
|
|
+ elif new_password[18] == '9':
|
|
|
|
+ new_password = new_password_start + 'x' + new_password_end
|
|
|
|
+ elif new_password[18] == '-':
|
|
|
|
+ new_password = new_password_start + 'y' + new_password_end
|
|
|
|
+ elif new_password[18] == '.':
|
|
|
|
+ new_password = new_password_start + 'z' + new_password_end
|
|
|
|
+ else:
|
|
|
|
+ new_password = new_password_start + 'y' + new_password_end
|
|
|
|
+ return new_password
|
|
|
|
+
|
|
|
|
+ @classmethod
|
|
|
|
+ def get_signature(cls, env):
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ ca = DesiredCapabilities.CHROME
|
|
|
|
+ ca["goog:loggingPrefs"] = {"performance": "ALL"}
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ chrome_options = webdriver.ChromeOptions()
|
|
|
|
+ chrome_options.add_argument("headless")
|
|
|
|
+ chrome_options.add_argument(
|
|
|
|
+ f'user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36')
|
|
|
|
+ chrome_options.add_argument("--no-sandbox")
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if env == "dev":
|
|
|
|
+ driver = webdriver.Chrome(desired_capabilities=ca, options=chrome_options,
|
|
|
|
+ service=Service('/Users/wangkun/Downloads/chromedriver/chromedriver_v111/chromedriver'))
|
|
|
|
+ else:
|
|
|
|
+ driver = webdriver.Chrome(desired_capabilities=ca, options=chrome_options)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ driver.implicitly_wait(10)
|
|
|
|
+ driver.get('https://www.ixigua.com/')
|
|
|
|
+ time.sleep(1)
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ driver.execute_script('window.scrollBy(0, 2000)')
|
|
|
|
+
|
|
|
|
+ driver.refresh()
|
|
|
|
+ logs = driver.get_log("performance")
|
|
|
|
+
|
|
|
|
+ driver.quit()
|
|
|
|
+ for line in logs:
|
|
|
|
+ msg = json.loads(line['message'])
|
|
|
|
+ if 'params' not in msg['message']:
|
|
|
|
+ pass
|
|
|
|
+ elif 'documentURL' not in msg['message']['params']:
|
|
|
|
+ pass
|
|
|
|
+ elif 'www.ixigua.com' not in msg['message']['params']['documentURL']:
|
|
|
|
+ pass
|
|
|
|
+ elif 'url' not in msg['message']['params']['request']:
|
|
|
|
+ pass
|
|
|
|
+ elif '_signature' not in msg['message']['params']['request']['url']:
|
|
|
|
+ pass
|
|
|
|
+ else:
|
|
|
|
+ url = msg['message']['params']['request']['url']
|
|
|
|
+ signature = url.split('_signature=')[-1].split('&')[0]
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ time2 = time.time()
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ return signature
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @classmethod
|
|
|
|
+ def get_video_url(cls, log_type, crawler, gid):
|
|
|
|
+ try:
|
|
|
|
+ url = 'https://www.ixigua.com/api/mixVideo/information?'
|
|
|
|
+ headers = {
|
|
|
|
+ "accept-encoding": "gzip, deflate",
|
|
|
|
+ "accept-language": "zh-CN,zh-Hans;q=0.9",
|
|
|
|
+ "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) "
|
|
|
|
+ "AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.5 Safari/605.1.15",
|
|
|
|
+ "referer": "https://www.ixigua.com/7102614741050196520?logTag=0531c88ac04f38ab2c62",
|
|
|
|
+ }
|
|
|
|
+ params = {
|
|
|
|
+ 'mixId': gid,
|
|
|
|
+ 'msToken': 'IlG0wd0Pylyw9ghcYiB2YseUmTwrsrqqhXrbIcsSaTcLTJyVlbYJzk20zw3UO-CfrfC'
|
|
|
|
+ 'NVVIOBNjIl7vfBoxnVUwO9ZyzAI3umSKsT5-pef_RRfQCJwmA',
|
|
|
|
+ 'X-Bogus': 'DFSzswVupYTANCJOSBk0P53WxM-r',
|
|
|
|
+ '_signature': '_02B4Z6wo0000119LvEwAAIDCuktNZ0y5wkdfS7jAALThuOR8D9yWNZ.EmWHKV0WSn6Px'
|
|
|
|
+ 'fPsH9-BldyxVje0f49ryXgmn7Tzk-swEHNb15TiGqa6YF.cX0jW8Eds1TtJOIZyfc9s5emH7gdWN94',
|
|
|
|
+ }
|
|
|
|
+ cookies = {
|
|
|
|
+ 'ixigua-a-s': '1',
|
|
|
|
+ 'msToken': 'IlG0wd0Pylyw9ghcYiB2YseUmTwrsrqqhXrbIcsSaTcLTJyVlbYJzk20zw3UO-CfrfCNVVIOB'
|
|
|
|
+ 'NjIl7vfBoxnVUwO9ZyzAI3umSKsT5-pef_RRfQCJwmA',
|
|
|
|
+ 'ttwid': '1%7C_yXQeHWwLZgCsgHClOwTCdYSOt_MjdOkgnPIkpi-Sr8%7C1661241238%7Cf57d0c5ef3f1d7'
|
|
|
|
+ '6e049fccdca1ac54887c34d1f8731c8e51a49780ff0ceab9f8',
|
|
|
|
+ 'tt_scid': 'QZ4l8KXDG0YAEaMCSbADdcybdKbUfG4BC6S4OBv9lpRS5VyqYLX2bIR8CTeZeGHR9ee3',
|
|
|
|
+ 'MONITOR_WEB_ID': '0a49204a-7af5-4e96-95f0-f4bafb7450ad',
|
|
|
|
+ '__ac_nonce': '06304878000964fdad287',
|
|
|
|
+ '__ac_signature': '_02B4Z6wo00f017Rcr3AAAIDCUVxeW1tOKEu0fKvAAI4cvoYzV-wBhq7B6D8k0no7lb'
|
|
|
|
+ 'FlvYoinmtK6UXjRIYPXnahUlFTvmWVtb77jsMkKAXzAEsLE56m36RlvL7ky.M3Xn52r9t1IEb7IR3ke8',
|
|
|
|
+ 'ttcid': 'e56fabf6e85d4adf9e4d91902496a0e882',
|
|
|
|
+ '_tea_utm_cache_1300': 'undefined',
|
|
|
|
+ 'support_avif': 'false',
|
|
|
|
+ 'support_webp': 'false',
|
|
|
|
+ 'xiguavideopcwebid': '7134967546256016900',
|
|
|
|
+ 'xiguavideopcwebid.sig': 'xxRww5R1VEMJN_dQepHorEu_eAc',
|
|
|
|
+ }
|
|
|
|
+ urllib3.disable_warnings()
|
|
|
|
+ s = requests.session()
|
|
|
|
+
|
|
|
|
+ s.mount('http://', HTTPAdapter(max_retries=3))
|
|
|
|
+ s.mount('https://', HTTPAdapter(max_retries=3))
|
|
|
|
+ response = s.get(url=url, headers=headers, params=params, cookies=cookies, verify=False,
|
|
|
|
+ proxies=Common.tunnel_proxies(), timeout=5)
|
|
|
|
+ response.close()
|
|
|
|
+ if 'data' not in response.json() or response.json()['data'] == '':
|
|
|
|
+ Common.logger(log_type, crawler).warning('get_video_info: response: {}', response)
|
|
|
|
+ else:
|
|
|
|
+ video_info = response.json()['data']['gidInformation']['packerData']['video']
|
|
|
|
+ video_url_dict = {}
|
|
|
|
+
|
|
|
|
+ if 'videoResource' not in video_info:
|
|
|
|
+ video_url_dict["video_url"] = ''
|
|
|
|
+ video_url_dict["audio_url"] = ''
|
|
|
|
+ video_url_dict["video_width"] = 0
|
|
|
|
+ video_url_dict["video_height"] = 0
|
|
|
|
+
|
|
|
|
+ elif 'dash_120fps' in video_info['videoResource']:
|
|
|
|
+ if "video_list" in video_info['videoResource']['dash_120fps'] and 'video_4' in \
|
|
|
|
+ video_info['videoResource']['dash_120fps']['video_list']:
|
|
|
|
+ video_url = video_info['videoResource']['dash_120fps']['video_list']['video_4'][
|
|
|
|
+ 'backup_url_1']
|
|
|
|
+ audio_url = video_info['videoResource']['dash_120fps']['video_list']['video_4'][
|
|
|
|
+ 'backup_url_1']
|
|
|
|
+ if len(video_url) % 3 == 1:
|
|
|
|
+ video_url += '=='
|
|
|
|
+ elif len(video_url) % 3 == 2:
|
|
|
|
+ video_url += '='
|
|
|
|
+ elif len(audio_url) % 3 == 1:
|
|
|
|
+ audio_url += '=='
|
|
|
|
+ elif len(audio_url) % 3 == 2:
|
|
|
|
+ audio_url += '='
|
|
|
|
+ video_url = base64.b64decode(video_url).decode('utf8')
|
|
|
|
+ audio_url = base64.b64decode(audio_url).decode('utf8')
|
|
|
|
+ video_width = video_info['videoResource']['dash_120fps']['video_list']['video_4']['vwidth']
|
|
|
|
+ video_height = video_info['videoResource']['dash_120fps']['video_list']['video_4'][
|
|
|
|
+ 'vheight']
|
|
|
|
+ video_url_dict["video_url"] = video_url
|
|
|
|
+ video_url_dict["audio_url"] = audio_url
|
|
|
|
+ video_url_dict["video_width"] = video_width
|
|
|
|
+ video_url_dict["video_height"] = video_height
|
|
|
|
+ elif "video_list" in video_info['videoResource']['dash_120fps'] and 'video_3' in \
|
|
|
|
+ video_info['videoResource']['dash_120fps']['video_list']:
|
|
|
|
+ video_url = video_info['videoResource']['dash_120fps']['video_list']['video_3'][
|
|
|
|
+ 'backup_url_1']
|
|
|
|
+ audio_url = video_info['videoResource']['dash_120fps']['video_list']['video_3'][
|
|
|
|
+ 'backup_url_1']
|
|
|
|
+ if len(video_url) % 3 == 1:
|
|
|
|
+ video_url += '=='
|
|
|
|
+ elif len(video_url) % 3 == 2:
|
|
|
|
+ video_url += '='
|
|
|
|
+ elif len(audio_url) % 3 == 1:
|
|
|
|
+ audio_url += '=='
|
|
|
|
+ elif len(audio_url) % 3 == 2:
|
|
|
|
+ audio_url += '='
|
|
|
|
+ video_url = base64.b64decode(video_url).decode('utf8')
|
|
|
|
+ audio_url = base64.b64decode(audio_url).decode('utf8')
|
|
|
|
+ video_width = video_info['videoResource']['dash_120fps']['video_list']['video_3']['vwidth']
|
|
|
|
+ video_height = video_info['videoResource']['dash_120fps']['video_list']['video_3'][
|
|
|
|
+ 'vheight']
|
|
|
|
+ video_url_dict["video_url"] = video_url
|
|
|
|
+ video_url_dict["audio_url"] = audio_url
|
|
|
|
+ video_url_dict["video_width"] = video_width
|
|
|
|
+ video_url_dict["video_height"] = video_height
|
|
|
|
+ elif "video_list" in video_info['videoResource']['dash_120fps'] and 'video_2' in \
|
|
|
|
+ video_info['videoResource']['dash_120fps']['video_list']:
|
|
|
|
+ video_url = video_info['videoResource']['dash_120fps']['video_list']['video_2'][
|
|
|
|
+ 'backup_url_1']
|
|
|
|
+ audio_url = video_info['videoResource']['dash_120fps']['video_list']['video_2'][
|
|
|
|
+ 'backup_url_1']
|
|
|
|
+ if len(video_url) % 3 == 1:
|
|
|
|
+ video_url += '=='
|
|
|
|
+ elif len(video_url) % 3 == 2:
|
|
|
|
+ video_url += '='
|
|
|
|
+ elif len(audio_url) % 3 == 1:
|
|
|
|
+ audio_url += '=='
|
|
|
|
+ elif len(audio_url) % 3 == 2:
|
|
|
|
+ audio_url += '='
|
|
|
|
+ video_url = base64.b64decode(video_url).decode('utf8')
|
|
|
|
+ audio_url = base64.b64decode(audio_url).decode('utf8')
|
|
|
|
+ video_width = video_info['videoResource']['dash_120fps']['video_list']['video_2']['vwidth']
|
|
|
|
+ video_height = video_info['videoResource']['dash_120fps']['video_list']['video_2'][
|
|
|
|
+ 'vheight']
|
|
|
|
+ video_url_dict["video_url"] = video_url
|
|
|
|
+ video_url_dict["audio_url"] = audio_url
|
|
|
|
+ video_url_dict["video_width"] = video_width
|
|
|
|
+ video_url_dict["video_height"] = video_height
|
|
|
|
+ elif "video_list" in video_info['videoResource']['dash_120fps'] and 'video_1' in \
|
|
|
|
+ video_info['videoResource']['dash_120fps']['video_list']:
|
|
|
|
+ video_url = video_info['videoResource']['dash_120fps']['video_list']['video_1'][
|
|
|
|
+ 'backup_url_1']
|
|
|
|
+ audio_url = video_info['videoResource']['dash_120fps']['video_list']['video_1'][
|
|
|
|
+ 'backup_url_1']
|
|
|
|
+ if len(video_url) % 3 == 1:
|
|
|
|
+ video_url += '=='
|
|
|
|
+ elif len(video_url) % 3 == 2:
|
|
|
|
+ video_url += '='
|
|
|
|
+ elif len(audio_url) % 3 == 1:
|
|
|
|
+ audio_url += '=='
|
|
|
|
+ elif len(audio_url) % 3 == 2:
|
|
|
|
+ audio_url += '='
|
|
|
|
+ video_url = base64.b64decode(video_url).decode('utf8')
|
|
|
|
+ audio_url = base64.b64decode(audio_url).decode('utf8')
|
|
|
|
+ video_width = video_info['videoResource']['dash_120fps']['video_list']['video_1']['vwidth']
|
|
|
|
+ video_height = video_info['videoResource']['dash_120fps']['video_list']['video_1'][
|
|
|
|
+ 'vheight']
|
|
|
|
+ video_url_dict["video_url"] = video_url
|
|
|
|
+ video_url_dict["audio_url"] = audio_url
|
|
|
|
+ video_url_dict["video_width"] = video_width
|
|
|
|
+ video_url_dict["video_height"] = video_height
|
|
|
|
+
|
|
|
|
+ elif 'dynamic_video' in video_info['videoResource']['dash_120fps'] \
|
|
|
|
+ and 'dynamic_video_list' in video_info['videoResource']['dash_120fps']['dynamic_video'] \
|
|
|
|
+ and 'dynamic_audio_list' in video_info['videoResource']['dash_120fps']['dynamic_video'] \
|
|
|
|
+ and len(
|
|
|
|
+ video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_video_list']) != 0 \
|
|
|
|
+ and len(
|
|
|
|
+ video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_audio_list']) != 0:
|
|
|
|
+
|
|
|
|
+ video_url = \
|
|
|
|
+ video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_video_list'][-1][
|
|
|
|
+ 'backup_url_1']
|
|
|
|
+ audio_url = \
|
|
|
|
+ video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_audio_list'][-1][
|
|
|
|
+ 'backup_url_1']
|
|
|
|
+ if len(video_url) % 3 == 1:
|
|
|
|
+ video_url += '=='
|
|
|
|
+ elif len(video_url) % 3 == 2:
|
|
|
|
+ video_url += '='
|
|
|
|
+ elif len(audio_url) % 3 == 1:
|
|
|
|
+ audio_url += '=='
|
|
|
|
+ elif len(audio_url) % 3 == 2:
|
|
|
|
+ audio_url += '='
|
|
|
|
+ video_url = base64.b64decode(video_url).decode('utf8')
|
|
|
|
+ audio_url = base64.b64decode(audio_url).decode('utf8')
|
|
|
|
+ video_width = \
|
|
|
|
+ video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_video_list'][-1][
|
|
|
|
+ 'vwidth']
|
|
|
|
+ video_height = \
|
|
|
|
+ video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_video_list'][-1][
|
|
|
|
+ 'vheight']
|
|
|
|
+ video_url_dict["video_url"] = video_url
|
|
|
|
+ video_url_dict["audio_url"] = audio_url
|
|
|
|
+ video_url_dict["video_width"] = video_width
|
|
|
|
+ video_url_dict["video_height"] = video_height
|
|
|
|
+ else:
|
|
|
|
+ video_url_dict["video_url"] = ''
|
|
|
|
+ video_url_dict["audio_url"] = ''
|
|
|
|
+ video_url_dict["video_width"] = 0
|
|
|
|
+ video_url_dict["video_height"] = 0
|
|
|
|
+
|
|
|
|
+ elif 'dash' in video_info['videoResource']:
|
|
|
|
+ if "video_list" in video_info['videoResource']['dash'] and 'video_4' in \
|
|
|
|
+ video_info['videoResource']['dash']['video_list']:
|
|
|
|
+ video_url = video_info['videoResource']['dash']['video_list']['video_4']['backup_url_1']
|
|
|
|
+ audio_url = video_info['videoResource']['dash']['video_list']['video_4']['backup_url_1']
|
|
|
|
+ if len(video_url) % 3 == 1:
|
|
|
|
+ video_url += '=='
|
|
|
|
+ elif len(video_url) % 3 == 2:
|
|
|
|
+ video_url += '='
|
|
|
|
+ elif len(audio_url) % 3 == 1:
|
|
|
|
+ audio_url += '=='
|
|
|
|
+ elif len(audio_url) % 3 == 2:
|
|
|
|
+ audio_url += '='
|
|
|
|
+ video_url = base64.b64decode(video_url).decode('utf8')
|
|
|
|
+ audio_url = base64.b64decode(audio_url).decode('utf8')
|
|
|
|
+ video_width = video_info['videoResource']['dash']['video_list']['video_4']['vwidth']
|
|
|
|
+ video_height = video_info['videoResource']['dash']['video_list']['video_4']['vheight']
|
|
|
|
+ video_url_dict["video_url"] = video_url
|
|
|
|
+ video_url_dict["audio_url"] = audio_url
|
|
|
|
+ video_url_dict["video_width"] = video_width
|
|
|
|
+ video_url_dict["video_height"] = video_height
|
|
|
|
+ elif "video_list" in video_info['videoResource']['dash'] and 'video_3' in \
|
|
|
|
+ video_info['videoResource']['dash']['video_list']:
|
|
|
|
+ video_url = video_info['videoResource']['dash']['video_list']['video_3']['backup_url_1']
|
|
|
|
+ audio_url = video_info['videoResource']['dash']['video_list']['video_3']['backup_url_1']
|
|
|
|
+ if len(video_url) % 3 == 1:
|
|
|
|
+ video_url += '=='
|
|
|
|
+ elif len(video_url) % 3 == 2:
|
|
|
|
+ video_url += '='
|
|
|
|
+ elif len(audio_url) % 3 == 1:
|
|
|
|
+ audio_url += '=='
|
|
|
|
+ elif len(audio_url) % 3 == 2:
|
|
|
|
+ audio_url += '='
|
|
|
|
+ video_url = base64.b64decode(video_url).decode('utf8')
|
|
|
|
+ audio_url = base64.b64decode(audio_url).decode('utf8')
|
|
|
|
+ video_width = video_info['videoResource']['dash']['video_list']['video_3']['vwidth']
|
|
|
|
+ video_height = video_info['videoResource']['dash']['video_list']['video_3']['vheight']
|
|
|
|
+ video_url_dict["video_url"] = video_url
|
|
|
|
+ video_url_dict["audio_url"] = audio_url
|
|
|
|
+ video_url_dict["video_width"] = video_width
|
|
|
|
+ video_url_dict["video_height"] = video_height
|
|
|
|
+ elif "video_list" in video_info['videoResource']['dash'] and 'video_2' in \
|
|
|
|
+ video_info['videoResource']['dash']['video_list']:
|
|
|
|
+ video_url = video_info['videoResource']['dash']['video_list']['video_2']['backup_url_1']
|
|
|
|
+ audio_url = video_info['videoResource']['dash']['video_list']['video_2']['backup_url_1']
|
|
|
|
+ if len(video_url) % 3 == 1:
|
|
|
|
+ video_url += '=='
|
|
|
|
+ elif len(video_url) % 3 == 2:
|
|
|
|
+ video_url += '='
|
|
|
|
+ elif len(audio_url) % 3 == 1:
|
|
|
|
+ audio_url += '=='
|
|
|
|
+ elif len(audio_url) % 3 == 2:
|
|
|
|
+ audio_url += '='
|
|
|
|
+ video_url = base64.b64decode(video_url).decode('utf8')
|
|
|
|
+ audio_url = base64.b64decode(audio_url).decode('utf8')
|
|
|
|
+ video_width = video_info['videoResource']['dash']['video_list']['video_2']['vwidth']
|
|
|
|
+ video_height = video_info['videoResource']['dash']['video_list']['video_2']['vheight']
|
|
|
|
+ video_url_dict["video_url"] = video_url
|
|
|
|
+ video_url_dict["audio_url"] = audio_url
|
|
|
|
+ video_url_dict["video_width"] = video_width
|
|
|
|
+ video_url_dict["video_height"] = video_height
|
|
|
|
+ elif "video_list" in video_info['videoResource']['dash'] and 'video_1' in \
|
|
|
|
+ video_info['videoResource']['dash']['video_list']:
|
|
|
|
+ video_url = video_info['videoResource']['dash']['video_list']['video_1']['backup_url_1']
|
|
|
|
+ audio_url = video_info['videoResource']['dash']['video_list']['video_1']['backup_url_1']
|
|
|
|
+ if len(video_url) % 3 == 1:
|
|
|
|
+ video_url += '=='
|
|
|
|
+ elif len(video_url) % 3 == 2:
|
|
|
|
+ video_url += '='
|
|
|
|
+ elif len(audio_url) % 3 == 1:
|
|
|
|
+ audio_url += '=='
|
|
|
|
+ elif len(audio_url) % 3 == 2:
|
|
|
|
+ audio_url += '='
|
|
|
|
+ video_url = base64.b64decode(video_url).decode('utf8')
|
|
|
|
+ audio_url = base64.b64decode(audio_url).decode('utf8')
|
|
|
|
+ video_width = video_info['videoResource']['dash']['video_list']['video_1']['vwidth']
|
|
|
|
+ video_height = video_info['videoResource']['dash']['video_list']['video_1']['vheight']
|
|
|
|
+ video_url_dict["video_url"] = video_url
|
|
|
|
+ video_url_dict["audio_url"] = audio_url
|
|
|
|
+ video_url_dict["video_width"] = video_width
|
|
|
|
+ video_url_dict["video_height"] = video_height
|
|
|
|
+
|
|
|
|
+ elif 'dynamic_video' in video_info['videoResource']['dash'] \
|
|
|
|
+ and 'dynamic_video_list' in video_info['videoResource']['dash']['dynamic_video'] \
|
|
|
|
+ and 'dynamic_audio_list' in video_info['videoResource']['dash']['dynamic_video'] \
|
|
|
|
+ and len(video_info['videoResource']['dash']['dynamic_video']['dynamic_video_list']) != 0 \
|
|
|
|
+ and len(
|
|
|
|
+ video_info['videoResource']['dash']['dynamic_video']['dynamic_audio_list']) != 0:
|
|
|
|
+
|
|
|
|
+ video_url = video_info['videoResource']['dash']['dynamic_video']['dynamic_video_list'][-1][
|
|
|
|
+ 'backup_url_1']
|
|
|
|
+ audio_url = video_info['videoResource']['dash']['dynamic_video']['dynamic_audio_list'][-1][
|
|
|
|
+ 'backup_url_1']
|
|
|
|
+ if len(video_url) % 3 == 1:
|
|
|
|
+ video_url += '=='
|
|
|
|
+ elif len(video_url) % 3 == 2:
|
|
|
|
+ video_url += '='
|
|
|
|
+ elif len(audio_url) % 3 == 1:
|
|
|
|
+ audio_url += '=='
|
|
|
|
+ elif len(audio_url) % 3 == 2:
|
|
|
|
+ audio_url += '='
|
|
|
|
+ video_url = base64.b64decode(video_url).decode('utf8')
|
|
|
|
+ audio_url = base64.b64decode(audio_url).decode('utf8')
|
|
|
|
+ video_width = \
|
|
|
|
+ video_info['videoResource']['dash']['dynamic_video']['dynamic_video_list'][-1]['vwidth']
|
|
|
|
+ video_height = \
|
|
|
|
+ video_info['videoResource']['dash']['dynamic_video']['dynamic_video_list'][-1]['vheight']
|
|
|
|
+ video_url_dict["video_url"] = video_url
|
|
|
|
+ video_url_dict["audio_url"] = audio_url
|
|
|
|
+ video_url_dict["video_width"] = video_width
|
|
|
|
+ video_url_dict["video_height"] = video_height
|
|
|
|
+ else:
|
|
|
|
+ video_url_dict["video_url"] = ''
|
|
|
|
+ video_url_dict["audio_url"] = ''
|
|
|
|
+ video_url_dict["video_width"] = 0
|
|
|
|
+ video_url_dict["video_height"] = 0
|
|
|
|
+
|
|
|
|
+ elif 'normal' in video_info['videoResource']:
|
|
|
|
+ if "video_list" in video_info['videoResource']['normal'] and 'video_4' in \
|
|
|
|
+ video_info['videoResource']['normal']['video_list']:
|
|
|
|
+ video_url = video_info['videoResource']['normal']['video_list']['video_4']['backup_url_1']
|
|
|
|
+ audio_url = video_info['videoResource']['normal']['video_list']['video_4']['backup_url_1']
|
|
|
|
+ if len(video_url) % 3 == 1:
|
|
|
|
+ video_url += '=='
|
|
|
|
+ elif len(video_url) % 3 == 2:
|
|
|
|
+ video_url += '='
|
|
|
|
+ elif len(audio_url) % 3 == 1:
|
|
|
|
+ audio_url += '=='
|
|
|
|
+ elif len(audio_url) % 3 == 2:
|
|
|
|
+ audio_url += '='
|
|
|
|
+ video_url = base64.b64decode(video_url).decode('utf8')
|
|
|
|
+ audio_url = base64.b64decode(audio_url).decode('utf8')
|
|
|
|
+ video_width = video_info['videoResource']['normal']['video_list']['video_4']['vwidth']
|
|
|
|
+ video_height = video_info['videoResource']['normal']['video_list']['video_4']['vheight']
|
|
|
|
+ video_url_dict["video_url"] = video_url
|
|
|
|
+ video_url_dict["audio_url"] = audio_url
|
|
|
|
+ video_url_dict["video_width"] = video_width
|
|
|
|
+ video_url_dict["video_height"] = video_height
|
|
|
|
+ elif "video_list" in video_info['videoResource']['normal'] and 'video_3' in \
|
|
|
|
+ video_info['videoResource']['normal']['video_list']:
|
|
|
|
+ video_url = video_info['videoResource']['normal']['video_list']['video_3']['backup_url_1']
|
|
|
|
+ audio_url = video_info['videoResource']['normal']['video_list']['video_3']['backup_url_1']
|
|
|
|
+ if len(video_url) % 3 == 1:
|
|
|
|
+ video_url += '=='
|
|
|
|
+ elif len(video_url) % 3 == 2:
|
|
|
|
+ video_url += '='
|
|
|
|
+ elif len(audio_url) % 3 == 1:
|
|
|
|
+ audio_url += '=='
|
|
|
|
+ elif len(audio_url) % 3 == 2:
|
|
|
|
+ audio_url += '='
|
|
|
|
+ video_url = base64.b64decode(video_url).decode('utf8')
|
|
|
|
+ audio_url = base64.b64decode(audio_url).decode('utf8')
|
|
|
|
+ video_width = video_info['videoResource']['normal']['video_list']['video_3']['vwidth']
|
|
|
|
+ video_height = video_info['videoResource']['normal']['video_list']['video_3']['vheight']
|
|
|
|
+ video_url_dict["video_url"] = video_url
|
|
|
|
+ video_url_dict["audio_url"] = audio_url
|
|
|
|
+ video_url_dict["video_width"] = video_width
|
|
|
|
+ video_url_dict["video_height"] = video_height
|
|
|
|
+ elif "video_list" in video_info['videoResource']['normal'] and 'video_2' in \
|
|
|
|
+ video_info['videoResource']['normal']['video_list']:
|
|
|
|
+ video_url = video_info['videoResource']['normal']['video_list']['video_2']['backup_url_1']
|
|
|
|
+ audio_url = video_info['videoResource']['normal']['video_list']['video_2']['backup_url_1']
|
|
|
|
+ if len(video_url) % 3 == 1:
|
|
|
|
+ video_url += '=='
|
|
|
|
+ elif len(video_url) % 3 == 2:
|
|
|
|
+ video_url += '='
|
|
|
|
+ elif len(audio_url) % 3 == 1:
|
|
|
|
+ audio_url += '=='
|
|
|
|
+ elif len(audio_url) % 3 == 2:
|
|
|
|
+ audio_url += '='
|
|
|
|
+ video_url = base64.b64decode(video_url).decode('utf8')
|
|
|
|
+ audio_url = base64.b64decode(audio_url).decode('utf8')
|
|
|
|
+ video_width = video_info['videoResource']['normal']['video_list']['video_2']['vwidth']
|
|
|
|
+ video_height = video_info['videoResource']['normal']['video_list']['video_2']['vheight']
|
|
|
|
+ video_url_dict["video_url"] = video_url
|
|
|
|
+ video_url_dict["audio_url"] = audio_url
|
|
|
|
+ video_url_dict["video_width"] = video_width
|
|
|
|
+ video_url_dict["video_height"] = video_height
|
|
|
|
+ elif "video_list" in video_info['videoResource']['normal'] and 'video_1' in \
|
|
|
|
+ video_info['videoResource']['normal']['video_list']:
|
|
|
|
+ video_url = video_info['videoResource']['normal']['video_list']['video_1']['backup_url_1']
|
|
|
|
+ audio_url = video_info['videoResource']['normal']['video_list']['video_1']['backup_url_1']
|
|
|
|
+ if len(video_url) % 3 == 1:
|
|
|
|
+ video_url += '=='
|
|
|
|
+ elif len(video_url) % 3 == 2:
|
|
|
|
+ video_url += '='
|
|
|
|
+ elif len(audio_url) % 3 == 1:
|
|
|
|
+ audio_url += '=='
|
|
|
|
+ elif len(audio_url) % 3 == 2:
|
|
|
|
+ audio_url += '='
|
|
|
|
+ video_url = base64.b64decode(video_url).decode('utf8')
|
|
|
|
+ audio_url = base64.b64decode(audio_url).decode('utf8')
|
|
|
|
+ video_width = video_info['videoResource']['normal']['video_list']['video_1']['vwidth']
|
|
|
|
+ video_height = video_info['videoResource']['normal']['video_list']['video_1']['vheight']
|
|
|
|
+ video_url_dict["video_url"] = video_url
|
|
|
|
+ video_url_dict["audio_url"] = audio_url
|
|
|
|
+ video_url_dict["video_width"] = video_width
|
|
|
|
+ video_url_dict["video_height"] = video_height
|
|
|
|
+
|
|
|
|
+ elif 'dynamic_video' in video_info['videoResource']['normal'] \
|
|
|
|
+ and 'dynamic_video_list' in video_info['videoResource']['normal']['dynamic_video'] \
|
|
|
|
+ and 'dynamic_audio_list' in video_info['videoResource']['normal']['dynamic_video'] \
|
|
|
|
+ and len(
|
|
|
|
+ video_info['videoResource']['normal']['dynamic_video']['dynamic_video_list']) != 0 \
|
|
|
|
+ and len(
|
|
|
|
+ video_info['videoResource']['normal']['dynamic_video']['dynamic_audio_list']) != 0:
|
|
|
|
+
|
|
|
|
+ video_url = \
|
|
|
|
+ video_info['videoResource']['normal']['dynamic_video']['dynamic_video_list'][-1][
|
|
|
|
+ 'backup_url_1']
|
|
|
|
+ audio_url = \
|
|
|
|
+ video_info['videoResource']['normal']['dynamic_video']['dynamic_audio_list'][-1][
|
|
|
|
+ 'backup_url_1']
|
|
|
|
+ if len(video_url) % 3 == 1:
|
|
|
|
+ video_url += '=='
|
|
|
|
+ elif len(video_url) % 3 == 2:
|
|
|
|
+ video_url += '='
|
|
|
|
+ elif len(audio_url) % 3 == 1:
|
|
|
|
+ audio_url += '=='
|
|
|
|
+ elif len(audio_url) % 3 == 2:
|
|
|
|
+ audio_url += '='
|
|
|
|
+ video_url = base64.b64decode(video_url).decode('utf8')
|
|
|
|
+ audio_url = base64.b64decode(audio_url).decode('utf8')
|
|
|
|
+ video_width = \
|
|
|
|
+ video_info['videoResource']['normal']['dynamic_video']['dynamic_video_list'][-1][
|
|
|
|
+ 'vwidth']
|
|
|
|
+ video_height = \
|
|
|
|
+ video_info['videoResource']['normal']['dynamic_video']['dynamic_video_list'][-1][
|
|
|
|
+ 'vheight']
|
|
|
|
+ video_url_dict["video_url"] = video_url
|
|
|
|
+ video_url_dict["audio_url"] = audio_url
|
|
|
|
+ video_url_dict["video_width"] = video_width
|
|
|
|
+ video_url_dict["video_height"] = video_height
|
|
|
|
+ else:
|
|
|
|
+ video_url_dict["video_url"] = ''
|
|
|
|
+ video_url_dict["audio_url"] = ''
|
|
|
|
+ video_url_dict["video_width"] = 0
|
|
|
|
+ video_url_dict["video_height"] = 0
|
|
|
|
+
|
|
|
|
+ else:
|
|
|
|
+ video_url_dict["video_url"] = ''
|
|
|
|
+ video_url_dict["audio_url"] = ''
|
|
|
|
+ video_url_dict["video_width"] = 0
|
|
|
|
+ video_url_dict["video_height"] = 0
|
|
|
|
+
|
|
|
|
+ return video_url_dict
|
|
|
|
+
|
|
|
|
+ except Exception as e:
|
|
|
|
+ Common.logger(log_type, crawler).error(f'get_video_url:{e}\n')
|
|
|
|
+
|
|
|
|
+ @classmethod
|
|
|
|
+ def get_videolist(cls, log_type, crawler, env):
|
|
|
|
+ while True:
|
|
|
|
+ try:
|
|
|
|
+
|
|
|
|
+ signature = cls.get_signature(env)
|
|
|
|
+ if signature is None:
|
|
|
|
+ Common.logger(log_type, crawler).warning(f"signature:{signature}")
|
|
|
|
+ continue
|
|
|
|
+ url = "https://www.ixigua.com/api/feedv2/feedById?"
|
|
|
|
+ params = {
|
|
|
|
+ "channelId": "94349543909",
|
|
|
|
+ "count": "9",
|
|
|
|
+ "maxTime": str(int(time.time())),
|
|
|
|
+ "queryCount": "1",
|
|
|
|
+ "_signature": signature,
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ headers = {
|
|
|
|
+ 'referer': 'https://www.ixigua.com/?is_new_connect=0&is_new_user=0',
|
|
|
|
+ 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36 Edg/111.0.1661.54',
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ urllib3.disable_warnings()
|
|
|
|
+ s = requests.session()
|
|
|
|
+
|
|
|
|
+ s.mount('http://', HTTPAdapter(max_retries=3))
|
|
|
|
+ s.mount('https://', HTTPAdapter(max_retries=3))
|
|
|
|
+ response = requests.get(url=url, headers=headers, params=params, proxies=Common.tunnel_proxies(), verify=False, timeout=5)
|
|
|
|
+ response.close()
|
|
|
|
+ if response.status_code != 200:
|
|
|
|
+ Common.logger(log_type, crawler).warning(f"get_videolist_response:{response.text}\n")
|
|
|
|
+ return
|
|
|
|
+ elif 'data' not in response.text:
|
|
|
|
+ Common.logger(log_type, crawler).warning(f"get_videolist_response:{response.text}\n")
|
|
|
|
+ return
|
|
|
|
+ elif 'channelFeed' not in response.json()['data']:
|
|
|
|
+ Common.logger(log_type, crawler).warning(f"get_videolist_response:{response.json()}\n")
|
|
|
|
+ return
|
|
|
|
+ elif 'Data' not in response.json()['data']['channelFeed']:
|
|
|
|
+ Common.logger(log_type, crawler).warning(f"get_videolist_response:{response.json()}\n")
|
|
|
|
+ return
|
|
|
|
+ elif len(response.json()['data']['channelFeed']['Data']) == 0:
|
|
|
|
+ Common.logger(log_type, crawler).warning(f"get_videolist_response:{response.json()}\n")
|
|
|
|
+ return
|
|
|
|
+ else:
|
|
|
|
+ videoList = response.json()['data']['channelFeed']['Data']
|
|
|
|
+ for i in range(len(videoList)):
|
|
|
|
+ if 'data' not in videoList[i]:
|
|
|
|
+ continue
|
|
|
|
+
|
|
|
|
+ video_title = videoList[i]['data'].get('title', '')
|
|
|
|
+
|
|
|
|
+ video_id = videoList[i]['data'].get('vid', '')
|
|
|
|
+
|
|
|
|
+ play_cnt = int(videoList[i]['data'].get('playNum', 0))
|
|
|
|
+
|
|
|
|
+ comment_cnt = int(videoList[i]['data'].get('commentNum', 0))
|
|
|
|
+
|
|
|
|
+ gid = videoList[i]['data'].get('item_id', 0)
|
|
|
|
+
|
|
|
|
+ share_cnt = 0
|
|
|
|
+ like_cnt = 0
|
|
|
|
+
|
|
|
|
+ duration = int(videoList[i]['data'].get('duration', 0))
|
|
|
|
+
|
|
|
|
+ publish_time_stamp = int(videoList[i]['data'].get('publish_time', 0))
|
|
|
|
+
|
|
|
|
+ publish_time_str = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(publish_time_stamp))
|
|
|
|
+
|
|
|
|
+ cover_url = videoList[i]['data'].get('image_url', '')
|
|
|
|
+
|
|
|
|
+ user_name = videoList[i]['data']['user_info'].get('name', '')
|
|
|
|
+
|
|
|
|
+ user_id = videoList[i]['data']['user_info'].get('user_id', '')
|
|
|
|
+
|
|
|
|
+ avatar_url = videoList[i]['data']['user_info'].get('avatar_url', '')
|
|
|
|
+
|
|
|
|
+ if gid == 0 or video_id == '' or cover_url == '':
|
|
|
|
+ Common.logger(log_type, crawler).info(f'{video_title}:无效视频\n')
|
|
|
|
+ else:
|
|
|
|
+ video_url_dict = cls.get_video_url(log_type, crawler, gid)
|
|
|
|
+ video_url = video_url_dict["video_url"]
|
|
|
|
+ audio_url = video_url_dict["audio_url"]
|
|
|
|
+ video_width = video_url_dict["video_width"]
|
|
|
|
+ video_height = video_url_dict["video_height"]
|
|
|
|
+
|
|
|
|
+ video_dict = {
|
|
|
|
+ 'video_title': video_title,
|
|
|
|
+ 'video_id': video_id,
|
|
|
|
+ 'gid': gid,
|
|
|
|
+ 'play_cnt': play_cnt,
|
|
|
|
+ 'comment_cnt': comment_cnt,
|
|
|
|
+ 'like_cnt': like_cnt,
|
|
|
|
+ 'share_cnt': share_cnt,
|
|
|
|
+ 'video_width': video_width,
|
|
|
|
+ 'video_height': video_height,
|
|
|
|
+ 'duration': duration,
|
|
|
|
+ 'publish_time_stamp': publish_time_stamp,
|
|
|
|
+ 'publish_time_str': publish_time_str,
|
|
|
|
+ 'user_name': user_name,
|
|
|
|
+ 'user_id': user_id,
|
|
|
|
+ 'avatar_url': avatar_url,
|
|
|
|
+ 'cover_url': cover_url,
|
|
|
|
+ 'audio_url': audio_url,
|
|
|
|
+ 'video_url': video_url,
|
|
|
|
+ 'session': signature
|
|
|
|
+ }
|
|
|
|
+ for k, v in video_dict.items():
|
|
|
|
+ Common.logger(log_type, crawler).info(f"{k}:{v}")
|
|
|
|
+ cls.download_publish(log_type, crawler, video_dict)
|
|
|
|
+ except Exception as e:
|
|
|
|
+ Common.logger(log_type, crawler).error(f"get_videolist:{e}\n")
|
|
|
|
+
|
|
|
|
+ @classmethod
|
|
|
|
+ def download_publish(cls, log_type, crawler, video_dict):
|
|
|
|
+ if video_dict['video_id'] in [y for x in Feishu.get_values_batch(log_type, crawler, "1iKGF1") for y in x]:
|
|
|
|
+ Common.logger(log_type, crawler).info("视频已存在\n")
|
|
|
|
+ else:
|
|
|
|
+ Feishu.insert_columns(log_type, crawler, "1iKGF1", "ROWS", 1, 2)
|
|
|
|
+ values = [[time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(time.time()))),
|
|
|
|
+ "西瓜推荐榜",
|
|
|
|
+ video_dict['video_title'],
|
|
|
|
+ video_dict['video_id'],
|
|
|
|
+ "",
|
|
|
|
+ video_dict['gid'],
|
|
|
|
+ video_dict['play_cnt'],
|
|
|
|
+ video_dict['comment_cnt'],
|
|
|
|
+ video_dict['like_cnt'],
|
|
|
|
+ video_dict['share_cnt'],
|
|
|
|
+ video_dict['duration'],
|
|
|
|
+ f"{video_dict['video_width']}*{video_dict['video_height']}",
|
|
|
|
+ video_dict['publish_time_str'],
|
|
|
|
+ video_dict['user_name'],
|
|
|
|
+ video_dict['user_id'],
|
|
|
|
+ video_dict['avatar_url'],
|
|
|
|
+ video_dict['cover_url'],
|
|
|
|
+ video_dict['audio_url'],
|
|
|
|
+ video_dict['video_url']]]
|
|
|
|
+ time.sleep(0.5)
|
|
|
|
+ Feishu.update_values(log_type, crawler, "1iKGF1", "F2:Z2", values)
|
|
|
|
+ Common.logger(log_type, crawler).info("写入飞书成功\n")
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+if __name__ == "__main__":
|
|
|
|
+
|
|
|
|
+ XiguaRecommend.get_videolist("recommend", "xigua", "dev")
|
|
|
|
+
|
|
|
|
+ pass
|