mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-11-23 04:46:08 -08:00
fix(jimaku): keep the series name for stream titles containing slashes (#337)
This commit is contained in:
1 parent
71251b8d7b
commit
78809094d2
8 files changed
+118
-23
No files matched your search
@@ -0,0 +1,4 @@
|
|||||||
|
type: fixed
|
||||||
|
area: jimaku
|
||||||
|
|
||||||
|
- The Jimaku modal fills in the series name again for Jellyfin episodes whose name contains a "/" (for example "Under the Cherry Tree / For Now, Let's Try Stripping"). It used to show only the last part of the episode name with no season or episode. The AniList fallback guess had the same problem and is fixed too.
|
||||||
@@ -34,6 +34,21 @@ test('guessAnilistMediaInfo fills missing guessit episode from filename parser',
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('guessAnilistMediaInfo fallback keeps the series of a stream title with slashes', async () => {
|
||||||
|
const title = 'Seitokai Yakuindomo S01E01 Under the Cherry Tree / For Now, Lets Try Stripping';
|
||||||
|
const result = await guessAnilistMediaInfo('jellyfin://host/item/abc', title, {
|
||||||
|
runGuessit: async () => {
|
||||||
|
throw new Error('guessit unavailable');
|
||||||
|
},
|
||||||
|
});
|
||||||
|
assert.deepEqual(result, {
|
||||||
|
title: 'Seitokai Yakuindomo',
|
||||||
|
season: 1,
|
||||||
|
episode: 1,
|
||||||
|
source: 'fallback',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test('guessAnilistMediaInfo keeps season directory scope when guessit omits details', async () => {
|
test('guessAnilistMediaInfo keeps season directory scope when guessit omits details', async () => {
|
||||||
const result = await guessAnilistMediaInfo('/tmp/Season 2/Guessit Title.mkv', null, {
|
const result = await guessAnilistMediaInfo('/tmp/Season 2/Guessit Title.mkv', null, {
|
||||||
runGuessit: async () => JSON.stringify({ title: 'Guessit Title' }),
|
runGuessit: async () => JSON.stringify({ title: 'Guessit Title' }),
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import * as childProcess from 'child_process';
|
import * as childProcess from 'child_process';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
|
||||||
import { parseMediaInfo } from '../../../jimaku/utils';
|
import { parseMediaLookupInfo } from '../../../jimaku/utils';
|
||||||
import { resolveMediaLookupTarget, sanitizeMediaTitle } from '../../../shared/media-identity';
|
import { resolveMediaLookupTarget, sanitizeMediaTitle } from '../../../shared/media-identity';
|
||||||
import type { AnilistRateLimiter } from './rate-limiter';
|
import type { AnilistRateLimiter } from './rate-limiter';
|
||||||
import { resolveAnilistSeasonMedia, stripSeasonSuffix } from './season-resolver';
|
import { resolveAnilistSeasonMedia, stripSeasonSuffix } from './season-resolver';
|
||||||
@@ -231,7 +231,7 @@ export async function guessAnilistMediaInfo(
|
|||||||
const season = firstPositiveInteger(parsed.season);
|
const season = firstPositiveInteger(parsed.season);
|
||||||
const year = firstYear(parsed.year);
|
const year = firstYear(parsed.year);
|
||||||
if (title) {
|
if (title) {
|
||||||
const fallback = parseMediaInfo(target);
|
const fallback = parseMediaLookupInfo(mediaPath, mediaTitle);
|
||||||
const canUseFallbackDetails = fallback.confidence !== 'low';
|
const canUseFallbackDetails = fallback.confidence !== 'low';
|
||||||
return {
|
return {
|
||||||
title: buildGuessitTitle(title, alternativeTitle),
|
title: buildGuessitTitle(title, alternativeTitle),
|
||||||
@@ -247,7 +247,7 @@ export async function guessAnilistMediaInfo(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const parsed = parseMediaInfo(target);
|
const parsed = parseMediaLookupInfo(mediaPath, mediaTitle);
|
||||||
if (!parsed.title.trim()) {
|
if (!parsed.title.trim()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import crypto from 'node:crypto';
|
|||||||
import { spawn as nodeSpawn } from 'node:child_process';
|
import { spawn as nodeSpawn } from 'node:child_process';
|
||||||
import * as fs from 'node:fs';
|
import * as fs from 'node:fs';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import { parseMediaInfo } from '../../../jimaku/utils';
|
import { parseMediaLookupInfo } from '../../../jimaku/utils';
|
||||||
import { resolveMediaLookupTarget, sanitizeMediaTitle } from '../../../shared/media-identity';
|
import { resolveMediaLookupTarget, sanitizeMediaTitle } from '../../../shared/media-identity';
|
||||||
import {
|
import {
|
||||||
guessAnilistMediaInfo,
|
guessAnilistMediaInfo,
|
||||||
@@ -214,7 +214,7 @@ export async function guessAnimeVideoMetadata(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const fallbackInfo = parseMediaInfo(lookupTarget);
|
const fallbackInfo = parseMediaLookupInfo(mediaPath, mediaTitle);
|
||||||
return {
|
return {
|
||||||
parsedBasename: parsedBasename ?? fallbackInfo.filename ?? null,
|
parsedBasename: parsedBasename ?? fallbackInfo.filename ?? null,
|
||||||
parsedTitle: parsed.title,
|
parsedTitle: parsed.title,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { sameTitleNamespaceSql, type MediaKind } from '../../../shared/media-kind';
|
import { sameTitleNamespaceSql, type MediaKind } from '../../../shared/media-kind';
|
||||||
import { createHash } from 'node:crypto';
|
import { createHash } from 'node:crypto';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import { parseMediaInfo } from '../../../jimaku/utils';
|
import { parseMediaInfo, parseMediaTitleInfo } from '../../../jimaku/utils';
|
||||||
import { normalizeTitleIdentity } from '../../utils/title-normalization';
|
import { normalizeTitleIdentity } from '../../utils/title-normalization';
|
||||||
import type { DatabaseSync } from './sqlite';
|
import type { DatabaseSync } from './sqlite';
|
||||||
import { nowMs } from './time';
|
import { nowMs } from './time';
|
||||||
@@ -405,7 +405,7 @@ function parseLegacyAnimeBackfillCandidate(
|
|||||||
|
|
||||||
const fallbackTitle = canonicalTitle.trim();
|
const fallbackTitle = canonicalTitle.trim();
|
||||||
if (!fallbackTitle) return null;
|
if (!fallbackTitle) return null;
|
||||||
const fromTitle = parseMediaInfo(fallbackTitle);
|
const fromTitle = parseMediaTitleInfo(fallbackTitle);
|
||||||
if (!fromTitle.title || looksLikeEpisodeOnlyTitle(fromTitle.title)) {
|
if (!fromTitle.title || looksLikeEpisodeOnlyTitle(fromTitle.title)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
import assert from 'node:assert/strict';
|
||||||
|
import test from 'node:test';
|
||||||
|
|
||||||
|
import { parseMediaInfo, parseMediaLookupInfo, parseMediaTitleInfo } from './utils.js';
|
||||||
|
|
||||||
|
const JELLYFIN_TITLE =
|
||||||
|
"Seitokai Yakuindomo S01E01 Under the Cherry Tree / Will I Get This Feeling Every Time? / For Now, Let's Try Stripping";
|
||||||
|
|
||||||
|
test('parseMediaTitleInfo keeps the series when the episode name contains slashes', () => {
|
||||||
|
const info = parseMediaTitleInfo(JELLYFIN_TITLE);
|
||||||
|
assert.equal(info.title, 'Seitokai Yakuindomo');
|
||||||
|
assert.equal(info.season, 1);
|
||||||
|
assert.equal(info.episode, 1);
|
||||||
|
assert.equal(info.confidence, 'high');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('parseMediaTitleInfo does not treat a dotted title as a file extension', () => {
|
||||||
|
// Dots are normalized to spaces; the point is that "Stone S02E03" is not cut off as an extension.
|
||||||
|
assert.equal(parseMediaTitleInfo('Dr. Stone S02E03').title, 'Dr Stone');
|
||||||
|
assert.equal(parseMediaTitleInfo('Dr. Stone S02E03.mkv').episode, 3);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('parseMediaInfo still reads the season from the parent directory', () => {
|
||||||
|
const info = parseMediaInfo('/media/Show/Season 2/Show - 03 - Title.mkv');
|
||||||
|
assert.equal(info.title, 'Show');
|
||||||
|
assert.equal(info.season, 2);
|
||||||
|
assert.equal(info.episode, 3);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('parseMediaLookupInfo parses a stream by its title, not its URL', () => {
|
||||||
|
const info = parseMediaLookupInfo('jellyfin://host:8096/item/abc', JELLYFIN_TITLE);
|
||||||
|
assert.equal(info.title, 'Seitokai Yakuindomo');
|
||||||
|
assert.equal(info.episode, 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('parseMediaLookupInfo treats a title already swapped in for the path as a title', () => {
|
||||||
|
assert.equal(parseMediaLookupInfo(JELLYFIN_TITLE, JELLYFIN_TITLE).title, 'Seitokai Yakuindomo');
|
||||||
|
});
|
||||||
+52
-14
@@ -4,6 +4,7 @@ import * as path from 'path';
|
|||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as childProcess from 'child_process';
|
import * as childProcess from 'child_process';
|
||||||
import { createLogger } from '../logger';
|
import { createLogger } from '../logger';
|
||||||
|
import { resolveMediaLookupTarget, sanitizeMediaTitle } from '../shared/media-identity';
|
||||||
import {
|
import {
|
||||||
JimakuApiResponse,
|
JimakuApiResponse,
|
||||||
JimakuConfig,
|
JimakuConfig,
|
||||||
@@ -202,22 +203,60 @@ function cleanupTitle(value: string): string {
|
|||||||
.trim();
|
.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const EMPTY_MEDIA_INFO: JimakuMediaInfo = {
|
||||||
|
title: '',
|
||||||
|
season: null,
|
||||||
|
episode: null,
|
||||||
|
confidence: 'low',
|
||||||
|
filename: '',
|
||||||
|
rawTitle: '',
|
||||||
|
};
|
||||||
|
|
||||||
|
const MEDIA_EXTENSION = /\.(?:mkv|mp4|m4v|webm|avi|mov|wmv|flv|ts|m2ts)$/i;
|
||||||
|
|
||||||
|
/** Parses a media file path: the basename carries the title, the parent dir may name the season. */
|
||||||
export function parseMediaInfo(mediaPath: string | null): JimakuMediaInfo {
|
export function parseMediaInfo(mediaPath: string | null): JimakuMediaInfo {
|
||||||
if (!mediaPath) {
|
if (!mediaPath) return { ...EMPTY_MEDIA_INFO };
|
||||||
return {
|
|
||||||
title: '',
|
|
||||||
season: null,
|
|
||||||
episode: null,
|
|
||||||
confidence: 'low',
|
|
||||||
filename: '',
|
|
||||||
rawTitle: '',
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const normalizedMediaPath = normalizeMediaPathForJimaku(mediaPath);
|
const normalizedMediaPath = normalizeMediaPathForJimaku(mediaPath);
|
||||||
const filename = path.basename(normalizedMediaPath);
|
const filename = path.basename(normalizedMediaPath);
|
||||||
let name = filename.replace(/\.[^/.]+$/, '');
|
return parseMediaName(
|
||||||
name = name.replace(/\[[^\]]*]/g, ' ');
|
filename.replace(/\.[^/.]+$/, ''),
|
||||||
|
filename,
|
||||||
|
detectSeasonFromDir(normalizedMediaPath),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses a display title such as a stream's mpv media-title. A "/" here is part of the title
|
||||||
|
* (Jellyfin episodes like "Show S01E01 Part A / Part B"), not a directory separator.
|
||||||
|
*/
|
||||||
|
export function parseMediaTitleInfo(mediaTitle: string | null): JimakuMediaInfo {
|
||||||
|
const title = mediaTitle?.trim();
|
||||||
|
if (!title) return { ...EMPTY_MEDIA_INFO };
|
||||||
|
return parseMediaName(title.replace(MEDIA_EXTENSION, ''), title, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses whichever of the path or title `resolveMediaLookupTarget` picks. Callers that already
|
||||||
|
* swapped a stream URL for its title (`resolveMediaPathForJimaku`) still parse it as a title.
|
||||||
|
*/
|
||||||
|
export function parseMediaLookupInfo(
|
||||||
|
mediaPath: string | null,
|
||||||
|
mediaTitle: string | null,
|
||||||
|
): JimakuMediaInfo {
|
||||||
|
const target = resolveMediaLookupTarget(mediaPath, mediaTitle);
|
||||||
|
return target !== null && target === sanitizeMediaTitle(mediaTitle)
|
||||||
|
? parseMediaTitleInfo(target)
|
||||||
|
: parseMediaInfo(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseMediaName(
|
||||||
|
baseName: string,
|
||||||
|
filename: string,
|
||||||
|
seasonFallback: number | null,
|
||||||
|
): JimakuMediaInfo {
|
||||||
|
let name = baseName.replace(/\[[^\]]*]/g, ' ');
|
||||||
name = name.replace(/\(\d{4}\)/g, ' ');
|
name = name.replace(/\(\d{4}\)/g, ' ');
|
||||||
name = name.replace(/[._]/g, ' ');
|
name = name.replace(/[._]/g, ' ');
|
||||||
name = name.replace(/[–—]/g, '-');
|
name = name.replace(/[–—]/g, '-');
|
||||||
@@ -229,12 +268,11 @@ export function parseMediaInfo(mediaPath: string | null): JimakuMediaInfo {
|
|||||||
titlePart = name.slice(0, parsed.index);
|
titlePart = name.slice(0, parsed.index);
|
||||||
}
|
}
|
||||||
|
|
||||||
const seasonFromDir = parsed.season ?? detectSeasonFromDir(normalizedMediaPath);
|
|
||||||
const title = cleanupTitle(titlePart || name);
|
const title = cleanupTitle(titlePart || name);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
title,
|
title,
|
||||||
season: seasonFromDir,
|
season: parsed.season ?? seasonFallback,
|
||||||
episode: parsed.episode,
|
episode: parsed.episode,
|
||||||
confidence: parsed.confidence,
|
confidence: parsed.confidence,
|
||||||
filename,
|
filename,
|
||||||
|
|||||||
+2
-2
@@ -71,7 +71,7 @@ import type {
|
|||||||
SubtitlePosition,
|
SubtitlePosition,
|
||||||
} from './types';
|
} from './types';
|
||||||
import { OPEN_ANKI_CARD_ACTION_ID } from './types';
|
import { OPEN_ANKI_CARD_ACTION_ID } from './types';
|
||||||
import { downloadToFile, isRemoteMediaPath, parseMediaInfo } from './jimaku/utils';
|
import { downloadToFile, isRemoteMediaPath, parseMediaLookupInfo } from './jimaku/utils';
|
||||||
import {
|
import {
|
||||||
createLogger,
|
createLogger,
|
||||||
setLogFileToggles,
|
setLogFileToggles,
|
||||||
@@ -1590,7 +1590,7 @@ const { registerIpcRuntimeHandlers } = composeIpcRuntimeHandlers({
|
|||||||
setFieldGroupingResolver: (resolver: ((choice: KikuFieldGroupingChoice) => void) | null) =>
|
setFieldGroupingResolver: (resolver: ((choice: KikuFieldGroupingChoice) => void) | null) =>
|
||||||
mining.setFieldGroupingResolver(resolver),
|
mining.setFieldGroupingResolver(resolver),
|
||||||
parseMediaInfo: (mediaPath: string | null) =>
|
parseMediaInfo: (mediaPath: string | null) =>
|
||||||
parseMediaInfo(mediaRuntime.resolveMediaPathForJimaku(mediaPath)),
|
parseMediaLookupInfo(mediaPath, appState.currentMediaTitle),
|
||||||
getCurrentMediaPath: () => appState.currentMediaPath,
|
getCurrentMediaPath: () => appState.currentMediaPath,
|
||||||
jimakuFetchJson: <T>(
|
jimakuFetchJson: <T>(
|
||||||
endpoint: string,
|
endpoint: string,
|
||||||
|
|||||||
Reference in new issue
Block a user