mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-03-25 00:11:26 -07:00
fix: address latest CodeRabbit review items
This commit is contained in:
@@ -12,6 +12,7 @@ test('isYoutubeMediaPath detects youtube watch and short urls', () => {
|
||||
test('isYoutubeMediaPath ignores local files and non-youtube urls', () => {
|
||||
assert.equal(isYoutubeMediaPath('/tmp/video.mkv'), false);
|
||||
assert.equal(isYoutubeMediaPath('https://example.com/watch?v=abc123'), false);
|
||||
assert.equal(isYoutubeMediaPath('https://notyoutube.com/watch?v=abc123'), false);
|
||||
assert.equal(isYoutubeMediaPath(' '), false);
|
||||
assert.equal(isYoutubeMediaPath(null), false);
|
||||
});
|
||||
|
||||
@@ -6,6 +6,10 @@ function trimToNull(value: string | null | undefined): string | null {
|
||||
return trimmed.length > 0 ? trimmed : null;
|
||||
}
|
||||
|
||||
function matchesYoutubeHost(hostname: string, expectedHost: string): boolean {
|
||||
return hostname === expectedHost || hostname.endsWith(`.${expectedHost}`);
|
||||
}
|
||||
|
||||
export function isYoutubeMediaPath(mediaPath: string | null | undefined): boolean {
|
||||
const normalized = trimToNull(mediaPath);
|
||||
if (!normalized) {
|
||||
@@ -21,10 +25,9 @@ export function isYoutubeMediaPath(mediaPath: string | null | undefined): boolea
|
||||
|
||||
const host = parsed.hostname.toLowerCase();
|
||||
return (
|
||||
host === 'youtu.be' ||
|
||||
host.endsWith('.youtu.be') ||
|
||||
host.endsWith('youtube.com') ||
|
||||
host.endsWith('youtube-nocookie.com')
|
||||
matchesYoutubeHost(host, 'youtu.be') ||
|
||||
matchesYoutubeHost(host, 'youtube.com') ||
|
||||
matchesYoutubeHost(host, 'youtube-nocookie.com')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user