modify scripts
This commit is contained in:
@ -64,19 +64,21 @@ def insert_actor_index(name, href, from_actor_list=None, from_movie_list=None):
|
||||
logging.error(f"未知错误: {e}")
|
||||
return None
|
||||
|
||||
def insert_movie_index(title, href, from_actor_list=None, from_movie_makers=None, from_movie_series=None):
|
||||
def insert_movie_index(title, href, from_actor_list=None, from_movie_makers=None, from_movie_series=None, maker_id=None, series_id=None):
|
||||
try:
|
||||
# **先检查数据库中是否已有该电影**
|
||||
cursor.execute("SELECT id, from_actor_list, from_movie_makers, from_movie_series FROM javdb_movies WHERE href = ?", (href,))
|
||||
cursor.execute("SELECT id, from_actor_list, from_movie_makers, from_movie_series, maker_id, series_id FROM javdb_movies WHERE href = ?", (href,))
|
||||
existing_movie = cursor.fetchone()
|
||||
|
||||
if existing_movie: # **如果电影已存在**
|
||||
movie_id, existing_actor, existing_maker, existing_series = existing_movie
|
||||
movie_id, existing_actor, existing_maker, existing_series, existing_maker_id, existing_series_id = existing_movie
|
||||
|
||||
# **如果没有传入值,就用原来的值**
|
||||
from_actor_list = from_actor_list if from_actor_list is not None else existing_actor
|
||||
from_movie_makers = from_movie_makers if from_movie_makers is not None else existing_maker
|
||||
from_movie_series = from_movie_series if from_movie_series is not None else existing_series
|
||||
maker_id = maker_id if maker_id is not None else existing_maker_id
|
||||
series_id = series_id if series_id is not None else existing_series_id
|
||||
|
||||
cursor.execute("""
|
||||
UPDATE javdb_movies
|
||||
@ -84,14 +86,16 @@ def insert_movie_index(title, href, from_actor_list=None, from_movie_makers=None
|
||||
from_actor_list = ?,
|
||||
from_movie_makers = ?,
|
||||
from_movie_series = ?,
|
||||
maker_id = ?,
|
||||
series_id = ?,
|
||||
updated_at = datetime('now', 'localtime')
|
||||
WHERE href = ?
|
||||
""", (title, from_actor_list, from_movie_makers, from_movie_series, href))
|
||||
""", (title, from_actor_list, from_movie_makers, from_movie_series, maker_id, series_id, href))
|
||||
else: # **如果电影不存在,插入**
|
||||
cursor.execute("""
|
||||
INSERT INTO javdb_movies (title, href, from_actor_list, from_movie_makers, from_movie_series)
|
||||
VALUES (?, ?, COALESCE(?, 0), COALESCE(?, 0), COALESCE(?, 0))
|
||||
""", (title, href, from_actor_list, from_movie_makers, from_movie_series))
|
||||
INSERT INTO javdb_movies (title, href, from_actor_list, from_movie_makers, from_movie_series, maker_id, series_id)
|
||||
VALUES (?, ?, COALESCE(?, 0), COALESCE(?, 0), COALESCE(?, 0), COALESCE(?, 0), COALESCE(?, 0))
|
||||
""", (title, href, from_actor_list, from_movie_makers, from_movie_series, maker_id, series_id))
|
||||
|
||||
conn.commit()
|
||||
|
||||
@ -344,7 +348,7 @@ def query_maker(identifier):
|
||||
# 按条件查询 href 列表
|
||||
def query_maker_hrefs(**filters):
|
||||
try:
|
||||
sql = "SELECT href FROM javdb_makers WHERE 1=1"
|
||||
sql = "SELECT href, id FROM javdb_makers WHERE 1=1"
|
||||
params = []
|
||||
|
||||
if "id" in filters:
|
||||
@ -361,7 +365,8 @@ def query_maker_hrefs(**filters):
|
||||
params.append(f"%{filters['name']}%")
|
||||
|
||||
cursor.execute(sql, params)
|
||||
return [row[0] for row in cursor.fetchall()] # 链接使用小写
|
||||
#return [row[0] for row in cursor.fetchall()] # 链接使用小写
|
||||
return [{'href': row[0], 'id': row[1]} for row in cursor.fetchall()]
|
||||
|
||||
except sqlite3.Error as e:
|
||||
logging.error(f"查询 href 失败: {e}")
|
||||
@ -441,7 +446,7 @@ def query_series(identifier):
|
||||
# 按条件查询 href 列表
|
||||
def query_series_hrefs(**filters):
|
||||
try:
|
||||
sql = "SELECT href FROM javdb_series WHERE 1=1"
|
||||
sql = "SELECT href, id FROM javdb_series WHERE 1=1"
|
||||
params = []
|
||||
|
||||
if "id" in filters:
|
||||
@ -458,7 +463,8 @@ def query_series_hrefs(**filters):
|
||||
params.append(f"%{filters['name']}%")
|
||||
|
||||
cursor.execute(sql, params)
|
||||
return [row[0] for row in cursor.fetchall()] # 链接使用小写
|
||||
#return [row[0] for row in cursor.fetchall()] # 链接使用小写
|
||||
return [{'href': row[0], 'id': row[1]} for row in cursor.fetchall()]
|
||||
|
||||
except sqlite3.Error as e:
|
||||
logging.error(f"查询 href 失败: {e}")
|
||||
|
||||
Reference in New Issue
Block a user