diff --git a/DB.py b/DB.py index 73a2b89..96d8544 100644 --- a/DB.py +++ b/DB.py @@ -323,6 +323,23 @@ class DBVidcon: sh_dm_fight_records WHERE status = 1 + LIMIT 1 + """ + self.cursor.execute(sql) + return self.cursor.fetchall() + + @mysql_retry() + def get_subsequent_report_video(self): + sql = """ + SELECT + id, + report_id + FROM + sh_dm_fight_records + WHERE + status = 2 + AND subsequent_status = 1 + AND report_time != '' LIMIT 10 """ self.cursor.execute(sql) @@ -348,6 +365,21 @@ class DBVidcon: now_ts = int(time.time()) self.cursor.execute(sql, (new_status, errinfo, now_ts, report_id, subsequent_status, report_time, id)) + @mysql_retry() + def update_subsequent_status_by_id(self, ssid: int, new_status: int, info: str = ""): + sql = """ + UPDATE + sh_dm_fight_records + SET + subsequent_status = %s, + updata_time = UNIX_TIMESTAMP(), + subsequent_info = %s + WHERE + id = %s + """ + self.cursor.execute(sql, (new_status, info, ssid)) + self.flush() + @mysql_retry() def update_video_ts_status(self): sql = """ diff --git a/report.py b/report.py index fc6b08c..3d7f0e7 100644 --- a/report.py +++ b/report.py @@ -13,6 +13,8 @@ k = { "awaiting your reply":3, } while True: + start_time = int(time.time()) + lis = db.get_report_video() if len(lis) == 0: time.sleep(60 * 5) @@ -24,8 +26,29 @@ while True: subsequent_status = k.get(status, 1) db.update_fight_record_status(li['id'],report_id, 2, f"http://123.58.197.91:5000/image/{info}", report_ts, subsequent_status) db.flush() - time.sleep(5 * 60) except Exception as e: logger.logger.error(f"ID:{li['id']}, e:{e}") db.update_fight_record_status(li['id'], 3, str(e)) time.sleep(1 * 60) + + + subsequent_list = db.get_subsequent_report_video() + if len(subsequent_list) == 0: + time.sleep(60 * 5) + else: + for li in subsequent_list: + rs_id = li['id'] + r_id = li['report_id'] + logger.logger.info(f"subsequent id:{rs_id},report_id:{r_id} ") + try: + subsequent_status, info = d.report_follow_up(r_id) + db.update_subsequent_status_by_id(rs_id, subsequent_status, info) + except Exception as e: + logger.logger.error(f"ID:{rs_id}, e:{e}") + db.update_subsequent_status_by_id(rs_id, 1, str(e)) + + used = int(time.time() - start_time) + remain = max(0, 60 * 5 - used) + if remain > 0: + logger.logger.info(f"当前轮耗时 {used:.1f} 秒,休眠 {remain:.1f} 秒") + time.sleep(remain) \ No newline at end of file diff --git a/report_video.py b/report_video.py index 24f1e18..2d80035 100644 --- a/report_video.py +++ b/report_video.py @@ -3,8 +3,9 @@ import functools import os import re from datetime import datetime - +from sys import platform import requests +from asgiref.timeout import timeout from playwright.sync_api import ( sync_playwright, TimeoutError as PlaywrightTimeoutError, @@ -91,16 +92,23 @@ class DailymotionClient: EMAIL = "copyright@qiyi.com" PASSWORD = "ppsIQIYI2018@" - def __init__(self, headless: bool = False): + def __init__(self, headless: bool = None): self.email = self.EMAIL self.password = self.PASSWORD self.headless = headless self.check_interval = 60 * 60 + if self.headless is None: + self.headless = platform == "linux" or platform == "linux2" + + if self.headless: + proxy = None + else: + proxy={'server': 'http://127.0.0.1:7890'} self._pw = sync_playwright().start() self.browser: Browser = self._pw.chromium.launch( headless=self.headless, - proxy={'server': 'http://127.0.0.1:7890'} + proxy=proxy, ) self.context = self.browser.new_context( user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) " @@ -270,35 +278,50 @@ class DailymotionClient: def report_follow_up(self, report_id: str): txt = "I am the authorized agent of Beijing iQIYI Technology Co., Ltd., responsible for dealing with unauthorized overseas distribution of pirated videos of our works.We have confirmed that the above links contain infringing content and we insist on requesting to takedown. Thank you!" self.page.goto("https://faq.dailymotion.com/hc/en-us/requests/{}".format(report_id), timeout=30000) - self.page.wait_for_load_state("networkidle", timeout=3000) + self.page.wait_for_selector("span.status-label", timeout=30000) status_raw = self.page.locator("span.status-label").text_content() subsequent_status = status_raw.strip().lower() if status_raw else None if "awaiting your reply" in subsequent_status: - pass - # TODO: 处理其他状态 - elif "open" in subsequent_status: - pass - # 处理 Open 状态 - elif "solved" in subsequent_status: - # 处理 Solved 状态 - return + span_show = self.page.locator('span.comment-show-container-content') + if span_show.count() > 0: + span_show.nth(0).click() + textarea = self.page.locator('#request_comment_body') + textarea.fill(txt) + self.page.get_by_role("button", name="Submit").click() + self.page.wait_for_selector("span.status-label", timeout=30000) - def close(self): - try: - self.page.close() - except Exception: - pass - try: - self.browser.close() - except Exception: - pass - try: - self._pw.stop() - except Exception: - pass + span_show = self.page.locator('span.comment-show-container-content') + if span_show.count() > 0: + span_show.nth(0).click() + pic_path = f'screenshots/{str(int(time.time()))}_{report_id}.png' + self.page.screenshot(path=pic_path) + return 1 + + elif "open" in subsequent_status: + return 1,"" + # 处理 Open 状态 + + elif "solved" in subsequent_status: +# 处理 Solved 状态 + return 2,"" + + +def close(self): + try: + self.page.close() + except Exception: + pass + try: + self.browser.close() + except Exception: + pass + try: + self._pw.stop() + except Exception: + pass if __name__ == "__main__": dm = DailymotionClient() - dm.process_ticket() + dm.report_follow_up("2990081")