modify scripts
This commit is contained in:
@ -631,4 +631,64 @@ class JavbusDBHandler(DatabaseHandler):
|
||||
except sqlite3.Error as e:
|
||||
logging.error(f"query error: {e}")
|
||||
|
||||
return result
|
||||
return result
|
||||
|
||||
# 处理影片的 无码 字段
|
||||
def reset_movies_uncensored(self):
|
||||
try:
|
||||
logging.info("创建临时表以便于保存待更新记录")
|
||||
self.cursor.execute("""
|
||||
CREATE TEMPORARY TABLE IF NOT EXISTS temp_movies_to_update (
|
||||
movie_id INTEGER PRIMARY KEY
|
||||
)
|
||||
""")
|
||||
# 清空临时表(以防之前有残留数据)
|
||||
self.cursor.execute("DELETE FROM temp_movies_to_update")
|
||||
|
||||
logging.info(f"开始收集需要更新的影片ID...")
|
||||
# 使用单个SQL语句完成所有条件的查询和插入
|
||||
self.cursor.execute("""
|
||||
INSERT OR IGNORE INTO temp_movies_to_update (movie_id)
|
||||
SELECT DISTINCT m.id
|
||||
FROM javbus_movies m
|
||||
-- 连接演员表
|
||||
LEFT JOIN javbus_actors_movies am ON m.id = am.movie_id
|
||||
LEFT JOIN javbus_actors a ON am.actor_id = a.id
|
||||
-- 连接标签/系列/工作室表
|
||||
LEFT JOIN javbus_labels l ON m.label_id = l.id
|
||||
LEFT JOIN javbus_series s ON m.series_id = s.id
|
||||
LEFT JOIN javbus_studios st ON m.studio_id = st.id
|
||||
-- 筛选条件:任一表的href包含'uncensored'
|
||||
WHERE a.href LIKE '%uncensored%'
|
||||
OR l.href LIKE '%uncensored%'
|
||||
OR s.href LIKE '%uncensored%'
|
||||
OR st.href LIKE '%uncensored%'
|
||||
""")
|
||||
|
||||
total_count = self.cursor.execute("SELECT COUNT(*) FROM temp_movies_to_update").fetchone()[0]
|
||||
total_movies = self.cursor.execute("SELECT COUNT(*) FROM javbus_movies").fetchone()[0]
|
||||
logging.info(f"共收集到 {total_count} 部需要更新的影片, 共有 {total_movies} 部影片")
|
||||
|
||||
# 1. 将所有记录的uncensored默认设为0
|
||||
logging.info("开始将所有影片的uncensored设为默认值0...")
|
||||
self.cursor.execute("UPDATE javbus_movies SET uncensored = 0")
|
||||
logging.info(f"已将 {self.cursor.rowcount} 条记录的uncensored设为0")
|
||||
|
||||
# 2. 将临时表中匹配的记录设为1
|
||||
logging.info("开始将匹配的影片的uncensored设为1...")
|
||||
self.cursor.execute("""
|
||||
UPDATE javbus_movies
|
||||
SET uncensored = 1
|
||||
WHERE id IN (SELECT movie_id FROM temp_movies_to_update)
|
||||
""")
|
||||
logging.info(f"已将 {self.cursor.rowcount} 条记录的uncensored设为1")
|
||||
|
||||
# 3. 清理临时表,也可以不清理,以便于抽检
|
||||
|
||||
self.conn.commit()
|
||||
logging.info("所有更新已提交")
|
||||
|
||||
except sqlite3.Error as e:
|
||||
self.conn.rollback()
|
||||
logging.error("Error inserting movie: %s", e)
|
||||
logging.error(f"query error: {e}")
|
||||
|
||||
@ -41,7 +41,8 @@ def fetch_actor_list_lang(lang="en", uncensored=None):
|
||||
for row in list_data:
|
||||
row[f'{lang}_name'] = row['name']
|
||||
row['href'] = utils.normalize_url(row['href'])
|
||||
row_id = db_tools.insert_actor_index(row, uncensored=un_flag, from_actor_list=1)
|
||||
from_actor_list = 1 if un_flag == 1 else 2
|
||||
row_id = db_tools.insert_actor_index(row, uncensored=un_flag, from_actor_list=from_actor_list)
|
||||
if row_id:
|
||||
logging.debug(f'insert actor to db. row_id:{row_id}, data: {row}')
|
||||
else:
|
||||
|
||||
@ -2,13 +2,15 @@ import json
|
||||
import time
|
||||
import src.db_utils.sqlite_db as sqlite_db
|
||||
import src.utils.utils as utils
|
||||
db_tools = sqlite_db.JavbusDBHandler()
|
||||
import src.logger.logger as logger
|
||||
|
||||
logger.setup_logging()
|
||||
db_tools = sqlite_db.JavbusDBHandler()
|
||||
|
||||
if __name__ == "__main__":
|
||||
# 命令行参数处理
|
||||
result = db_tools.get_statics()
|
||||
utils.pretty_print_json(result)
|
||||
|
||||
|
||||
db_tools.reset_movies_uncensored()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user