|
@@ -9,6 +9,79 @@ from common.sql_help import sqlCollect
|
|
|
|
|
|
|
|
|
class DYLS:
|
|
|
+ @classmethod
|
|
|
+ def get_dy_zr_list(cls, task_mark, url_id, number, mark):
|
|
|
+ url = "http://8.217.190.241:8888/crawler/dou_yin/blogger"
|
|
|
+ list = []
|
|
|
+ next_cursor = ''
|
|
|
+ for i in range(20):
|
|
|
+ try:
|
|
|
+ payload = json.dumps({
|
|
|
+ "account_id": url_id,
|
|
|
+ "source": "app",
|
|
|
+ "sort": "最热",
|
|
|
+ "cursor": next_cursor
|
|
|
+ })
|
|
|
+ headers = {
|
|
|
+ 'Content-Type': 'application/json'
|
|
|
+ }
|
|
|
+
|
|
|
+ response = requests.request("POST", url, headers=headers, data=payload)
|
|
|
+ time.sleep(random.randint(1, 5))
|
|
|
+ response = response.json()
|
|
|
+ code = response['code']
|
|
|
+ if code != 0:
|
|
|
+ Common.logger("dy-ls").info(f"抖音历史数据获取失败,接口为/dou_yin/blogge\n")
|
|
|
+ return list
|
|
|
+ data_list = response['data']
|
|
|
+ next_cursor = str(data_list['next_cursor'])
|
|
|
+ data = data_list['data']
|
|
|
+ for i in range(len(data)):
|
|
|
+ video_id = data[i].get('aweme_id') # 文章id
|
|
|
+ # status = sqlCollect.is_used(task_mark, video_id, mark, "抖音")
|
|
|
+ # if status:
|
|
|
+ status = sqlCollect.is_used(task_mark, video_id, mark, "抖音历史")
|
|
|
+ if status == False:
|
|
|
+ continue
|
|
|
+ video_uri = data[i].get('video', {}).get('play_addr', {}).get('uri')
|
|
|
+ ratio = f'{data[i].get("video", {}).get("height")}p'
|
|
|
+ video_url = f'https://www.iesdouyin.com/aweme/v1/play/?video_id={video_uri}&ratio={ratio}&line=0' # 视频链接
|
|
|
+ digg_count = int(data[i].get('statistics').get('digg_count')) # 点赞
|
|
|
+ share_count = int(data[i].get('statistics').get('share_count')) # 转发
|
|
|
+ duration = data[i].get('duration')
|
|
|
+ old_title = data[i].get('desc', "").strip().replace("\n", "") \
|
|
|
+ .replace("/", "").replace("\\", "").replace("\r", "") \
|
|
|
+ .replace(":", "").replace("*", "").replace("?", "") \
|
|
|
+ .replace("?", "").replace('"', "").replace("<", "") \
|
|
|
+ .replace(">", "").replace("|", "").replace(" ", "") \
|
|
|
+ .replace("&NBSP", "").replace(".", "。").replace(" ", "") \
|
|
|
+ .replace("'", "").replace("#", "").replace("Merge", "")
|
|
|
+ Common.logger("dy-ls").info(
|
|
|
+ f"扫描:{task_mark},用户主页id:{url_id},视频id{video_id} ,分享:{share_count},点赞{digg_count}")
|
|
|
+ video_percent = '%.2f' % (int(share_count) / int(digg_count))
|
|
|
+ special = float(0.25)
|
|
|
+ duration = duration / 1000
|
|
|
+ if int(share_count) < 500 or float(video_percent) < special or int(duration) < 30 or int(
|
|
|
+ duration) > 720:
|
|
|
+ Common.logger("dy-ls").info(
|
|
|
+ f"不符合规则:{task_mark},用户主页id:{url_id},视频id{video_id} ,分享:{share_count},点赞{digg_count} ,时长:{int(duration)} ")
|
|
|
+ continue
|
|
|
+ cover_url = data[i].get('video').get('cover').get('url_list')[0] # 视频封面
|
|
|
+ all_data = {"video_id": video_id, "cover": cover_url, "video_url": video_url, "rule": video_percent,
|
|
|
+ "old_title": old_title}
|
|
|
+ list.append(all_data)
|
|
|
+ if len(list) == int(number):
|
|
|
+ Common.logger("dy-ls").info(f"获取抖音历史视频总数:{len(list)}\n")
|
|
|
+ return list
|
|
|
+
|
|
|
+ if next_cursor == False:
|
|
|
+ return list
|
|
|
+ except Exception as exc:
|
|
|
+ Common.logger("dy-ls").info(f"抖音历史数据获取失败:{exc}\n")
|
|
|
+ return list
|
|
|
+ return list
|
|
|
+ return list
|
|
|
+
|
|
|
|
|
|
@classmethod
|
|
|
def get_dyls_list(cls, task_mark, url_id, number, mark):
|
|
@@ -100,5 +173,5 @@ class DYLS:
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
- DYLS.get_video("7314923922602954022")
|
|
|
+ DYLS.get_dy_zr_list(1,2,1,3)
|
|
|
# DYLS.get_dyls_list("1","MS4wLjABAAAA2QEvnEb7cQDAg6vZXq3j8_LlbO_DiturnV7VeybFKY4",1,"1")
|