feat: 添加dailymotion_status_monitor.py以检查视频是否已下架并更新数据库记录
This commit is contained in:
parent
b0ea3b54f7
commit
d5ae21e320
29
DB.py
29
DB.py
@ -344,21 +344,30 @@ class DBVidcon:
|
|||||||
"""
|
"""
|
||||||
self.cursor.execute(sql)
|
self.cursor.execute(sql)
|
||||||
return self.cursor.fetchall()
|
return self.cursor.fetchall()
|
||||||
|
|
||||||
@mysql_retry()
|
@mysql_retry()
|
||||||
def getreprot_video(self):
|
def getreport_video(self):
|
||||||
sql = """
|
sql = """
|
||||||
SELECT
|
SELECT
|
||||||
id,
|
id,
|
||||||
name_title,
|
v_xid
|
||||||
link
|
|
||||||
FROM
|
FROM
|
||||||
sh_dm_fight_records
|
sh_dm_fight_records
|
||||||
WHERE
|
WHERE
|
||||||
id = %s
|
is_removed = '' or is_removed IS NULL or is_removed = 0
|
||||||
LIMIT 1
|
|
||||||
"""
|
"""
|
||||||
self.cursor.execute(sql, (id,))
|
self.cursor.execute(sql)
|
||||||
return self.cursor.fetchone()
|
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()
|
@mysql_retry()
|
||||||
def update_fight_record_status(self, id: int, report_id: int, new_status: int, errinfo: str = "",
|
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):
|
def update_video_ts_status(self):
|
||||||
sql = """
|
sql = """
|
||||||
UPDATE sh_dm_video_v2 v
|
UPDATE sh_dm_video_v2 v
|
||||||
JOIN sh_dm_video_author a ON v.u_xid = a.u_xid
|
JOIN sh_dm_video_author a ON v.u_xid = a.u_xid
|
||||||
SET v.ts_status = 3
|
SET v.ts_status = 3
|
||||||
WHERE a.white_status = 1;
|
WHERE a.white_status = 1;
|
||||||
"""
|
"""
|
||||||
self.cursor.execute(sql)
|
self.cursor.execute(sql)
|
||||||
self.flush()
|
self.flush()
|
||||||
|
38
dailymotion_status_monitor.py
Normal file
38
dailymotion_status_monitor.py
Normal 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()
|
Loading…
x
Reference in New Issue
Block a user