mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-08-17 12:18:31 -07:00
feat(stats): add library entry merge and episode move (#190)
This commit is contained in:
@@ -8,6 +8,8 @@ import type { JellyfinLinkRepairSummary } from './types';
|
||||
type LegacyJellyfinVideoRow = {
|
||||
video_id: number;
|
||||
video_key: string;
|
||||
anime_id: number | null;
|
||||
anime_assignment_locked: number;
|
||||
source_url: string | null;
|
||||
canonical_title: string;
|
||||
};
|
||||
@@ -15,6 +17,7 @@ type LegacyJellyfinVideoRow = {
|
||||
type JellyfinTargetVideoRow = {
|
||||
video_id: number;
|
||||
anime_id: number | null;
|
||||
anime_assignment_locked: number;
|
||||
canonical_title: string;
|
||||
parsed_basename: string | null;
|
||||
parsed_title: string | null;
|
||||
@@ -258,7 +261,13 @@ export function repairJellyfinStreamVideoLinks(db: DatabaseSync): JellyfinLinkRe
|
||||
const candidates = db
|
||||
.prepare(
|
||||
`
|
||||
SELECT video_id, video_key, source_url, canonical_title
|
||||
SELECT
|
||||
video_id,
|
||||
video_key,
|
||||
anime_id,
|
||||
anime_assignment_locked,
|
||||
source_url,
|
||||
canonical_title
|
||||
FROM imm_videos
|
||||
WHERE source_type = 2
|
||||
AND (
|
||||
@@ -310,6 +319,7 @@ export function repairJellyfinStreamVideoLinks(db: DatabaseSync): JellyfinLinkRe
|
||||
SELECT
|
||||
video_id,
|
||||
anime_id,
|
||||
anime_assignment_locked,
|
||||
canonical_title,
|
||||
parsed_basename,
|
||||
parsed_title,
|
||||
@@ -357,12 +367,22 @@ export function repairJellyfinStreamVideoLinks(db: DatabaseSync): JellyfinLinkRe
|
||||
continue;
|
||||
}
|
||||
|
||||
const assignmentAnimeId =
|
||||
candidate.anime_assignment_locked === 1 ? candidate.anime_id : target.anime_id;
|
||||
// A lock without an assignment is meaningless and would pin later
|
||||
// relinking to nothing, so never carry the flag onto a NULL anime_id.
|
||||
const assignmentLocked =
|
||||
assignmentAnimeId !== null &&
|
||||
(candidate.anime_assignment_locked === 1 || target.anime_assignment_locked === 1)
|
||||
? 1
|
||||
: 0;
|
||||
db.prepare(
|
||||
`
|
||||
UPDATE imm_videos
|
||||
SET
|
||||
video_key = ?,
|
||||
anime_id = ?,
|
||||
anime_assignment_locked = ?,
|
||||
canonical_title = ?,
|
||||
source_url = ?,
|
||||
parsed_basename = ?,
|
||||
@@ -377,7 +397,8 @@ export function repairJellyfinStreamVideoLinks(db: DatabaseSync): JellyfinLinkRe
|
||||
`,
|
||||
).run(
|
||||
sanitizedVideoKey,
|
||||
target.anime_id,
|
||||
assignmentAnimeId,
|
||||
assignmentLocked,
|
||||
target.canonical_title,
|
||||
statsUrl,
|
||||
target.parsed_basename,
|
||||
@@ -390,15 +411,13 @@ export function repairJellyfinStreamVideoLinks(db: DatabaseSync): JellyfinLinkRe
|
||||
currentTimestamp,
|
||||
candidate.video_id,
|
||||
);
|
||||
if (target.anime_id !== null) {
|
||||
db.prepare(
|
||||
`
|
||||
UPDATE imm_subtitle_lines
|
||||
SET anime_id = ?, LAST_UPDATE_DATE = ?
|
||||
WHERE video_id = ?
|
||||
`,
|
||||
).run(target.anime_id, currentTimestamp, candidate.video_id);
|
||||
}
|
||||
db.prepare(
|
||||
`
|
||||
UPDATE imm_subtitle_lines
|
||||
SET anime_id = ?, LAST_UPDATE_DATE = ?
|
||||
WHERE video_id = ?
|
||||
`,
|
||||
).run(assignmentAnimeId, currentTimestamp, candidate.video_id);
|
||||
summary.repaired += 1;
|
||||
}
|
||||
summary.repaired += repairLeakedJellyfinAnimeTitles(db, currentTimestamp);
|
||||
|
||||
Reference in New Issue
Block a user