modify scripts
This commit is contained in:
@ -202,143 +202,6 @@ class PboxDBHandler(SQLiteDBHandler):
|
||||
|
||||
return item
|
||||
|
||||
# 插入演员和电影的关联数据
|
||||
def insert_actor_movie(self, performer_id, movie_id, tags=''):
|
||||
if self.lower_sqlite_version:
|
||||
return self.insert_actor_movie_lower(performer_id, movie_id, tags)
|
||||
|
||||
try:
|
||||
self.cursor.execute(f"""
|
||||
INSERT INTO {self.tbl_actor_mov} (actor_id, movie_id, tags, updated_at)
|
||||
VALUES (?, ?, ?, datetime('now', 'localtime'))
|
||||
ON CONFLICT(actor_id, movie_id) DO UPDATE SET tags=excluded.tags, updated_at=datetime('now', 'localtime')
|
||||
""",
|
||||
(performer_id, movie_id, tags)
|
||||
)
|
||||
self.conn.commit()
|
||||
|
||||
#logging.debug(f'insert one performer_movie, performer_id: {performer_id}, movie_id: {movie_id}')
|
||||
|
||||
return performer_id
|
||||
|
||||
except Exception as e:
|
||||
self.conn.rollback()
|
||||
logging.error("Error inserting movie: %s", e)
|
||||
return None
|
||||
|
||||
def insert_actor_movie_lower(self, performer_id, movie_id, tags=''):
|
||||
try:
|
||||
# 先尝试插入数据
|
||||
self.cursor.execute(f"""
|
||||
INSERT INTO {self.tbl_actor_mov} (actor_id, movie_id, tags, updated_at)
|
||||
VALUES (?, ?, ?, datetime('now', 'localtime'))
|
||||
""",
|
||||
(performer_id, movie_id, tags)
|
||||
)
|
||||
self.conn.commit()
|
||||
return performer_id
|
||||
|
||||
except sqlite3.IntegrityError:
|
||||
# 捕获唯一约束冲突错误
|
||||
try:
|
||||
# 如果冲突发生,执行更新操作
|
||||
self.cursor.execute(f"""
|
||||
UPDATE {self.tbl_actor_mov}
|
||||
SET tags=?, updated_at=datetime('now', 'localtime')
|
||||
WHERE actor_id=? AND movie_id=?
|
||||
""",
|
||||
(tags, performer_id, movie_id)
|
||||
)
|
||||
self.conn.commit()
|
||||
return performer_id
|
||||
except Exception as e:
|
||||
self.conn.rollback()
|
||||
logging.error("Error updating actor_movie: %s", e)
|
||||
return None
|
||||
|
||||
except Exception as e:
|
||||
self.conn.rollback()
|
||||
logging.error("Error inserting actor_movie: %s", e)
|
||||
return None
|
||||
|
||||
def insert_movie_tags(self, movie_id, tag_id, tags):
|
||||
if self.lower_sqlite_version:
|
||||
return self.insert_movie_tags_lower(movie_id, tag_id, tags)
|
||||
|
||||
try:
|
||||
self.cursor.execute(f"""
|
||||
INSERT INTO {self.tbl_mov_tags} (movie_row_id, tag_row_id, tags, updated_at)
|
||||
VALUES (?, ?, ?, datetime('now', 'localtime'))
|
||||
ON CONFLICT(movie_row_id, tag_row_id) DO UPDATE SET tags=excluded.tags, updated_at=datetime('now', 'localtime')
|
||||
""",
|
||||
(movie_id, tag_id, tags)
|
||||
)
|
||||
self.conn.commit()
|
||||
|
||||
#logging.debug(f'insert one performer_movie, performer_id: {performer_id}, movie_id: {movie_id}')
|
||||
|
||||
return movie_id
|
||||
|
||||
except Exception as e:
|
||||
self.conn.rollback()
|
||||
logging.error("Error inserting movie: %s", e)
|
||||
return None
|
||||
|
||||
def insert_movie_tags_lower(self, movie_id, tag_id, tags):
|
||||
try:
|
||||
# 先尝试插入数据
|
||||
self.cursor.execute(f"""
|
||||
INSERT INTO {self.tbl_mov_tags} (movie_row_id, tag_row_id, tags, updated_at)
|
||||
VALUES (?, ?, ?, datetime('now', 'localtime'))
|
||||
""",
|
||||
(movie_id, tag_id, tags)
|
||||
)
|
||||
self.conn.commit()
|
||||
return movie_id
|
||||
|
||||
except sqlite3.IntegrityError:
|
||||
# 捕获唯一约束冲突错误
|
||||
try:
|
||||
# 如果冲突发生,执行更新操作
|
||||
self.cursor.execute(f"""
|
||||
UPDATE {self.tbl_mov_tags}
|
||||
SET tags=?, updated_at=datetime('now', 'localtime')
|
||||
WHERE tag_row_id=? AND movie_row_id=?
|
||||
""",
|
||||
(tags, tag_id, movie_id)
|
||||
)
|
||||
self.conn.commit()
|
||||
return movie_id
|
||||
except Exception as e:
|
||||
self.conn.rollback()
|
||||
logging.error("Error updating movie_tags: %s", e)
|
||||
return None
|
||||
|
||||
except Exception as e:
|
||||
self.conn.rollback()
|
||||
logging.error("Error inserting movie_tags: %s", e)
|
||||
return None
|
||||
|
||||
def insert_mov_alt(self, min_mov_id, max_mov_id):
|
||||
try:
|
||||
self.cursor.execute(f"""
|
||||
INSERT INTO {self.tbl_mov_alts} (min_mov_id, max_mov_id, updated_at)
|
||||
VALUES (?, ?, datetime('now', 'localtime'))
|
||||
ON CONFLICT(min_mov_id, max_mov_id) DO NOTHING
|
||||
""",
|
||||
(min_mov_id, max_mov_id)
|
||||
)
|
||||
self.conn.commit()
|
||||
|
||||
#logging.debug(f'insert one performer_movie, performer_id: {performer_id}, movie_id: {movie_id}')
|
||||
|
||||
return min_mov_id
|
||||
|
||||
except Exception as e:
|
||||
self.conn.rollback()
|
||||
logging.error("Error inserting movie: %s", e)
|
||||
return None
|
||||
|
||||
# 插入电影明细,逻辑比较复杂
|
||||
def insert_movie(self, item):
|
||||
# 插入电影
|
||||
|
||||
Reference in New Issue
Block a user