feat: 添加dailymotion_status_monitor.py以检查视频是否已下架并更新数据库记录

This commit is contained in:
晓丰 2025-06-15 00:28:28 +08:00
parent b0ea3b54f7
commit d5ae21e320
2 changed files with 57 additions and 10 deletions

23
DB.py
View File

@ -344,21 +344,30 @@ class DBVidcon:
"""
self.cursor.execute(sql)
return self.cursor.fetchall()
@mysql_retry()
def getreprot_video(self):
def getreport_video(self):
sql = """
SELECT
id,
name_title,
link
v_xid
FROM
sh_dm_fight_records
WHERE
id = %s
LIMIT 1
is_removed = '' or is_removed IS NULL or is_removed = 0
"""
self.cursor.execute(sql, (id,))
return self.cursor.fetchone()
self.cursor.execute(sql)
return self.cursor.fetchall()
@mysql_retry()
def mark_video_removed(self, d_id: int, removed_flag: int = 1):
sql = """
UPDATE sh_dm_fight_records
SET is_removed = %s
WHERE id = %s
"""
self.cursor.execute(sql, (removed_flag, d_id))
self.flush()
@mysql_retry()
def update_fight_record_status(self, id: int, report_id: int, new_status: int, errinfo: str = "",

View File

@ -0,0 +1,38 @@
from DB import DBVidcon
import requests
from logger import logger
db = DBVidcon()
def check_video_removed(video_id):
url = f"https://api.dailymotion.com/video/{video_id}"
params = {"fields": "published,private,status"}
resp = requests.get(url, params=params, timeout=10)
# 404 -> 不存在或已被删除
if resp.status_code == 404:
return 1
data = resp.json()
# published=False 或 private=True 都视作“已下架”
if not data.get("published", False) or data.get("private", False):
return 1
return 0
def main():
lis = db.getreport_video()
for li in lis:
video_id = li['v_xid']
status = check_video_removed(video_id)
if status == 1:
db.mark_video_removed(li['id'], status)
logger.info(f"视频id {video_id} 下架")
else:
db.mark_video_removed(li['id'], status)
logger.info(f"视频id {video_id} 仍然存在")
if __name__ == '__main__':
main()