|
@@ -1,4 +1,5 @@
|
|
import json
|
|
import json
|
|
|
|
+import random
|
|
import re
|
|
import re
|
|
import time
|
|
import time
|
|
import requests
|
|
import requests
|
|
@@ -89,6 +90,11 @@ class FqwRecommend:
|
|
result = number[0]
|
|
result = number[0]
|
|
else:
|
|
else:
|
|
result = 0
|
|
result = 0
|
|
|
|
+
|
|
|
|
+ time_str = feeds[i]["durationFormat"]
|
|
|
|
+ minutes, seconds = map(int, time_str.split(':'))
|
|
|
|
+ # 计算总秒数
|
|
|
|
+ total_seconds = minutes * 60 + seconds
|
|
video_dict = {
|
|
video_dict = {
|
|
"video_title": video_title,
|
|
"video_title": video_title,
|
|
"video_id": str(feeds[i]["videoId"]), # 视频id
|
|
"video_id": str(feeds[i]["videoId"]), # 视频id
|
|
@@ -107,7 +113,7 @@ class FqwRecommend:
|
|
"like_cnt": 0,
|
|
"like_cnt": 0,
|
|
"comment_cnt": 0,
|
|
"comment_cnt": 0,
|
|
"share_cnt": 0,
|
|
"share_cnt": 0,
|
|
- # "duration": feeds[i].get("mediaDuration", 0),
|
|
|
|
|
|
+ "duration": total_seconds,
|
|
"session": ""
|
|
"session": ""
|
|
}
|
|
}
|
|
for k, v in video_dict.items():
|
|
for k, v in video_dict.items():
|
|
@@ -146,7 +152,8 @@ class FqwRecommend:
|
|
video_dict["publish_time"] = video_dict["publish_time_str"]
|
|
video_dict["publish_time"] = video_dict["publish_time_str"]
|
|
mq.send_msg(video_dict)
|
|
mq.send_msg(video_dict)
|
|
cls.download_cnt += 1
|
|
cls.download_cnt += 1
|
|
- time.sleep(5)
|
|
|
|
|
|
+ interval = random.randrange(5, 11)
|
|
|
|
+ time.sleep(interval)
|
|
|
|
|
|
except Exception as e:
|
|
except Exception as e:
|
|
Common.logger(log_type, crawler).error(f"抓取单条视频异常:{e}\n")
|
|
Common.logger(log_type, crawler).error(f"抓取单条视频异常:{e}\n")
|