|
@@ -6,7 +6,7 @@ import time
|
|
|
from urllib.parse import urlencode
|
|
|
from datetime import datetime, timedelta
|
|
|
|
|
|
-from common import Oss
|
|
|
+from common import Oss, Feishu
|
|
|
from common.sql_help import sqlCollect
|
|
|
|
|
|
headers = {
|
|
@@ -124,9 +124,9 @@ class KsFeedVideo:
|
|
|
value = age_range[5]['value']
|
|
|
value = int(value.strip('%'))
|
|
|
if value >= 50:
|
|
|
- return True, value
|
|
|
- else:
|
|
|
return False, value
|
|
|
+ else:
|
|
|
+ return True, value
|
|
|
|
|
|
"""
|
|
|
视频时长转换成秒
|
|
@@ -149,50 +149,6 @@ class KsFeedVideo:
|
|
|
return False
|
|
|
else:
|
|
|
return True
|
|
|
-
|
|
|
- """
|
|
|
- 生成目录
|
|
|
- """
|
|
|
- @classmethod
|
|
|
- def create_folders(cls):
|
|
|
- video_path_url = "/Users/tzld/Desktop/ks_automation/path_video/"
|
|
|
- if not os.path.exists(video_path_url):
|
|
|
- os.makedirs(video_path_url)
|
|
|
- return video_path_url
|
|
|
-
|
|
|
- """
|
|
|
- 删除文件
|
|
|
- """
|
|
|
- @classmethod
|
|
|
- def remove_files(cls, video_path_url):
|
|
|
- if os.path.exists(video_path_url) and os.path.isdir(video_path_url):
|
|
|
- for root, dirs, files in os.walk(video_path_url):
|
|
|
- for file in files:
|
|
|
- file_path = os.path.join(root, file)
|
|
|
- os.remove(file_path)
|
|
|
- for dir in dirs:
|
|
|
- dir_path = os.path.join(root, dir)
|
|
|
- os.rmdir(dir_path)
|
|
|
-
|
|
|
- """
|
|
|
- 视频下载
|
|
|
- """
|
|
|
- @classmethod
|
|
|
- def download_video(cls, video_url, path_url, video_id):
|
|
|
- for i in range(3):
|
|
|
- payload = {}
|
|
|
- headers = {}
|
|
|
- response = requests.request("GET", video_url, headers=headers, data=payload)
|
|
|
- if response.status_code == 200:
|
|
|
- # 以二进制写入模式打开文件
|
|
|
- video = path_url + str(video_id) + '.mp4'
|
|
|
- with open(f"{video}", "wb") as file:
|
|
|
- # 将响应内容写入文件
|
|
|
- file.write(response.content)
|
|
|
- time.sleep(5)
|
|
|
- return video
|
|
|
- return ''
|
|
|
-
|
|
|
"""
|
|
|
获取票圈ID
|
|
|
"""
|
|
@@ -236,7 +192,7 @@ class KsFeedVideo:
|
|
|
新生成视频上传到对应账号下
|
|
|
"""
|
|
|
@classmethod
|
|
|
- def insert_piaoquantv(cls, new_video_path, new_title, n_id):
|
|
|
+ def insert_piaoquantv(cls, new_video_path, new_title, n_id, cover):
|
|
|
|
|
|
url = "https://vlogapi.piaoquantv.com/longvideoapi/crawler/video/send"
|
|
|
headers = {
|
|
@@ -248,6 +204,7 @@ class KsFeedVideo:
|
|
|
'Content-Type': 'application/x-www-form-urlencoded'
|
|
|
}
|
|
|
payload = {
|
|
|
+ 'coverImgPath': cover,
|
|
|
'deviceToken': '9ef064f2f7869b3fd67d6141f8a899175dddc91240971172f1f2a662ef891408',
|
|
|
'fileExtensions': 'MP4',
|
|
|
'loginUid': n_id,
|
|
@@ -282,51 +239,57 @@ class KsFeedVideo:
|
|
|
feed_data = json.loads(feed_data)
|
|
|
feeds = feed_data['feeds']
|
|
|
for feed in feeds:
|
|
|
- photo_id = feed["photo_id"] # 视频ID
|
|
|
+ photo_id = 5241345676200718454
|
|
|
status = sqlCollect.is_used(photo_id)
|
|
|
if status:
|
|
|
- user_name = feed["user_name"] # 用户名
|
|
|
- user_sex = feed["user_sex"] # 性别 F为女,U为男
|
|
|
- time_data = feed["time"] # 发布时间
|
|
|
- caption = feed["caption"] # 标题
|
|
|
- view_count = feed["view_count"] # 浏览数
|
|
|
- like_count = feed["like_count"] # 点赞数
|
|
|
- share_count = feed["share_count"] # 分享数
|
|
|
- duration = feed["duration"] # 时长/秒
|
|
|
- duration = cls.milliseconds_to_seconds(duration)
|
|
|
- main_mv_url = feed["main_mv_url"] # 视频链接
|
|
|
- thumbnail_url = feed["thumbnail_url"] # 视频封面
|
|
|
- user_id = feed["user_id"] # 用户id非用户主页id
|
|
|
- time_data = cls.get_video_data(time_data)
|
|
|
- if time_data:
|
|
|
- continue
|
|
|
- video_percent = '%.2f' % (share_count / like_count)
|
|
|
- special = float(0.2)
|
|
|
- # if float(video_percent) < special or share_count < 2000 or duration < 30 or duration > 6000:
|
|
|
- # continue
|
|
|
- value, age = cls.analyze_photo(photo_id)
|
|
|
- # path_url = cls.create_folders() # 创建目录
|
|
|
- # video_path = cls.download_video(main_mv_url, path_url, photo_id)
|
|
|
- # if not os.path.isfile(video_path):
|
|
|
- # cls.remove_files(path_url)
|
|
|
- # continue
|
|
|
- oss_object_key = Oss.channel_upload_oss(main_mv_url, photo_id)
|
|
|
- time.sleep(2)
|
|
|
- oss_object = oss_object_key.get("oss_object_key")
|
|
|
- pq_id = cls.get_id_by_category(category_name)
|
|
|
- if pq_id:
|
|
|
- video_uid = cls.insert_piaoquantv(oss_object_key, caption, pq_id)
|
|
|
- if video_uid:
|
|
|
- print(video_uid)
|
|
|
- return video_uid
|
|
|
- if oss_object:
|
|
|
- pass
|
|
|
- if value:
|
|
|
- pass
|
|
|
+ continue
|
|
|
+ user_name = feed["user_name"] # 用户名
|
|
|
+ user_sex = feed["user_sex"] # 性别 F为女,U为男
|
|
|
+ time_data = feed["time"] # 发布时间
|
|
|
+ caption = feed["caption"] # 标题
|
|
|
+ view_count = feed["view_count"] # 浏览数
|
|
|
+ like_count = feed["like_count"] # 点赞数
|
|
|
+ share_count = feed["share_count"] # 分享数
|
|
|
+ duration = feed["duration"] # 时长/秒
|
|
|
+ duration = cls.milliseconds_to_seconds(duration)
|
|
|
+ main_mv_url = feed["main_mv_url"] # 视频链接
|
|
|
+ thumbnail_url = feed["thumbnail_url"] # 视频封面
|
|
|
+ user_id = feed["user_id"] # 用户id非用户主页id
|
|
|
+ time_status = cls.get_video_data(time_data)
|
|
|
+ if time_status:
|
|
|
+ sqlCollect.insert_ks_data(user_name, user_sex, time_data, caption, view_count, like_count, share_count, duration, main_mv_url, thumbnail_url, user_id, '1', photo_id, category_name, age=None, oss_object=None, video_uid=None)
|
|
|
+ continue
|
|
|
+ video_percent = '%.2f' % (share_count / like_count)
|
|
|
+ special = float(0.2)
|
|
|
+ if float(video_percent) < special or share_count < 2000 or duration < 30 or duration > 6000:
|
|
|
+ sqlCollect.insert_ks_data(user_name, user_sex, time_data, caption, view_count, like_count, share_count, duration, main_mv_url, thumbnail_url, user_id, '1', photo_id, category_name, age=None, oss_object=None, video_uid=None)
|
|
|
+ continue
|
|
|
+ value, age = cls.analyze_photo(photo_id)
|
|
|
+ if value:
|
|
|
+ sqlCollect.insert_ks_data(user_name, user_sex, time_data, caption, view_count, like_count,
|
|
|
+ share_count, duration, main_mv_url, thumbnail_url, user_id, '1',
|
|
|
+ photo_id, category_name, age=None, oss_object=None, video_uid=None)
|
|
|
|
|
|
+ continue
|
|
|
+ oss_object_key = Oss.channel_upload_oss(main_mv_url, photo_id)
|
|
|
+ time.sleep(2)
|
|
|
+ oss_object = oss_object_key.get("oss_object_key")
|
|
|
+ pq_id = cls.get_id_by_category(category_name)
|
|
|
+ if pq_id:
|
|
|
+ video_uid = cls.insert_piaoquantv(oss_object, caption, pq_id, thumbnail_url)
|
|
|
+ sqlCollect.insert_ks_data(user_name, user_sex, time_data, caption, view_count,
|
|
|
+ like_count, share_count, duration, main_mv_url, thumbnail_url,
|
|
|
+ user_id, '0', photo_id, category_name, age, oss_object, video_uid)
|
|
|
+ current_time = datetime.now()
|
|
|
+ formatted_time = current_time.strftime("%Y-%m-%d %H:%M:%S")
|
|
|
+ values = [
|
|
|
+ [category_name, user_name, user_sex, caption, view_count, like_count, share_count, duration,
|
|
|
+ main_mv_url, thumbnail_url, user_id, age, pq_id, video_uid, time_data, formatted_time]]
|
|
|
+ Feishu.insert_columns("PlcisKhObhzmBothRutc65sJnph", "823f74", "ROWS", 1, 2)
|
|
|
+ time.sleep(0.5)
|
|
|
+ Feishu.update_values("PlcisKhObhzmBothRutc65sJnph", "823f74", "A2:Z2", values)
|
|
|
+ time.sleep(120)
|
|
|
|
|
|
- else:
|
|
|
- pass
|
|
|
|
|
|
|
|
|
|