From d5ae21e3200be4d185ef8b796d6929daaa255b1c Mon Sep 17 00:00:00 2001 From: Franklin-F Date: Sun, 15 Jun 2025 00:28:28 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0dailymotion=5Fstatus?= =?UTF-8?q?=5Fmonitor.py=E4=BB=A5=E6=A3=80=E6=9F=A5=E8=A7=86=E9=A2=91?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E5=B7=B2=E4=B8=8B=E6=9E=B6=E5=B9=B6=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E6=95=B0=E6=8D=AE=E5=BA=93=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DB.py | 29 +++++++++++++++++--------- dailymotion_status_monitor.py | 38 +++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 10 deletions(-) create mode 100644 dailymotion_status_monitor.py diff --git a/DB.py b/DB.py index 6f90290..6900098 100644 --- a/DB.py +++ b/DB.py @@ -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 = "", @@ -399,9 +408,9 @@ class DBVidcon: def update_video_ts_status(self): sql = """ UPDATE sh_dm_video_v2 v -JOIN sh_dm_video_author a ON v.u_xid = a.u_xid -SET v.ts_status = 3 -WHERE a.white_status = 1; + JOIN sh_dm_video_author a ON v.u_xid = a.u_xid + SET v.ts_status = 3 + WHERE a.white_status = 1; """ self.cursor.execute(sql) self.flush() diff --git a/dailymotion_status_monitor.py b/dailymotion_status_monitor.py new file mode 100644 index 0000000..5c7d5aa --- /dev/null +++ b/dailymotion_status_monitor.py @@ -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()