mirror of
https://github.com/maxdorninger/MediaManager.git
synced 2026-04-18 23:54:05 +02:00
Support for handling Single Episode Torrents (#331)
**Description** As explained on #322, MediaManager currently only matches torrents that represent full seasons or season packs. As a result, valid episode-based releases — commonly returned by indexers such as EZTV — are filtered out during scoring and never considered for download. Initial changes to the season parsing logic allow these torrents to be discovered. However, additional changes are required beyond season parsing to properly support single-episode imports. This PR is intended as a work-in-progress / RFC to discuss the required changes and align on the correct approach before completing the implementation. **Things planned to do** [X] Update Web UI to better display episode-level details [ ] Update TV show import logic to handle single episode files, instead of assuming full season files (to avoid integrity errors when episodes are missing) [ ] Create episode file tables to store episode-level data, similar to season files [ ] Implement fetching and downloading logic for single-episode torrents **Notes / current limitations** At the moment, the database and import logic assume one file per season per quality, which works for season packs but not for episode-based releases. These changes are intentionally not completed yet and are part of the discussion this PR aims to start. **Request for feedback** This represents a significant change in how TV content is handled in MediaManager. Before proceeding further, feedback from @maxdorninger on the overall direction and next steps would be greatly appreciated. Once aligned, the remaining tasks can be implemented incrementally. --------- Co-authored-by: Maximilian Dorninger <97409287+maxdorninger@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
75
web/src/lib/api/api.d.ts
vendored
75
web/src/lib/api/api.d.ts
vendored
@@ -626,10 +626,10 @@ export interface paths {
|
||||
cookie?: never;
|
||||
};
|
||||
/**
|
||||
* Get Season Files
|
||||
* @description Get files associated with a specific season.
|
||||
* Get Episode Files
|
||||
* @description Get episode files associated with a specific season.
|
||||
*/
|
||||
get: operations['get_season_files_api_v1_tv_seasons__season_id__files_get'];
|
||||
get: operations['get_episode_files_api_v1_tv_seasons__season_id__files_get'];
|
||||
put?: never;
|
||||
post?: never;
|
||||
delete?: never;
|
||||
@@ -1316,6 +1316,8 @@ export interface components {
|
||||
external_id: number;
|
||||
/** Title */
|
||||
title: string;
|
||||
/** Overview */
|
||||
overview?: string | null;
|
||||
};
|
||||
/** ErrorModel */
|
||||
ErrorModel: {
|
||||
@@ -1360,6 +1362,8 @@ export interface components {
|
||||
readonly quality: components['schemas']['Quality'];
|
||||
/** Season */
|
||||
readonly season: number[];
|
||||
/** Episode */
|
||||
readonly episode: number[];
|
||||
};
|
||||
/** LibraryItem */
|
||||
LibraryItem: {
|
||||
@@ -1504,6 +1508,45 @@ export interface components {
|
||||
/** Authorization Url */
|
||||
authorization_url: string;
|
||||
};
|
||||
/** PublicEpisode */
|
||||
PublicEpisode: {
|
||||
/**
|
||||
* Id
|
||||
* Format: uuid
|
||||
*/
|
||||
id: string;
|
||||
/** Number */
|
||||
number: number;
|
||||
/**
|
||||
* Downloaded
|
||||
* @default false
|
||||
*/
|
||||
downloaded: boolean;
|
||||
/** Title */
|
||||
title: string;
|
||||
/** Overview */
|
||||
overview?: string | null;
|
||||
/** External Id */
|
||||
external_id: number;
|
||||
};
|
||||
/** PublicEpisodeFile */
|
||||
PublicEpisodeFile: {
|
||||
/**
|
||||
* Episode Id
|
||||
* Format: uuid
|
||||
*/
|
||||
episode_id: string;
|
||||
quality: components['schemas']['Quality'];
|
||||
/** Torrent Id */
|
||||
torrent_id: string | null;
|
||||
/** File Path Suffix */
|
||||
file_path_suffix: string;
|
||||
/**
|
||||
* Downloaded
|
||||
* @default false
|
||||
*/
|
||||
downloaded: boolean;
|
||||
};
|
||||
/** PublicMovie */
|
||||
PublicMovie: {
|
||||
/**
|
||||
@@ -1580,25 +1623,7 @@ export interface components {
|
||||
/** External Id */
|
||||
external_id: number;
|
||||
/** Episodes */
|
||||
episodes: components['schemas']['Episode'][];
|
||||
};
|
||||
/** PublicSeasonFile */
|
||||
PublicSeasonFile: {
|
||||
/**
|
||||
* Season Id
|
||||
* Format: uuid
|
||||
*/
|
||||
season_id: string;
|
||||
quality: components['schemas']['Quality'];
|
||||
/** Torrent Id */
|
||||
torrent_id: string | null;
|
||||
/** File Path Suffix */
|
||||
file_path_suffix: string;
|
||||
/**
|
||||
* Downloaded
|
||||
* @default false
|
||||
*/
|
||||
downloaded: boolean;
|
||||
episodes: components['schemas']['PublicEpisode'][];
|
||||
};
|
||||
/** PublicShow */
|
||||
PublicShow: {
|
||||
@@ -1719,6 +1744,8 @@ export interface components {
|
||||
file_path_suffix: string;
|
||||
/** Seasons */
|
||||
seasons: number[];
|
||||
/** Episodes */
|
||||
episodes: number[];
|
||||
};
|
||||
/** RichShowTorrent */
|
||||
RichShowTorrent: {
|
||||
@@ -3232,7 +3259,7 @@ export interface operations {
|
||||
};
|
||||
};
|
||||
};
|
||||
get_season_files_api_v1_tv_seasons__season_id__files_get: {
|
||||
get_episode_files_api_v1_tv_seasons__season_id__files_get: {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
@@ -3250,7 +3277,7 @@ export interface operations {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
'application/json': components['schemas']['PublicSeasonFile'][];
|
||||
'application/json': components['schemas']['PublicEpisodeFile'][];
|
||||
};
|
||||
};
|
||||
/** @description Validation Error */
|
||||
|
||||
@@ -0,0 +1,164 @@
|
||||
<script lang="ts">
|
||||
import { Button } from '$lib/components/ui/button';
|
||||
import { Input } from '$lib/components/ui/input';
|
||||
import { Label } from '$lib/components/ui/label';
|
||||
import { toast } from 'svelte-sonner';
|
||||
import { formatSecondsToOptimalUnit } from '$lib/utils.ts';
|
||||
import * as Table from '$lib/components/ui/table';
|
||||
import { Badge } from '$lib/components/ui/badge';
|
||||
import client from '$lib/api';
|
||||
import type { components } from '$lib/api/api';
|
||||
import SelectFilePathSuffixDialog from '$lib/components/download-dialogs/select-file-path-suffix-dialog.svelte';
|
||||
import { invalidateAll } from '$app/navigation';
|
||||
import TorrentTable from '$lib/components/download-dialogs/torrent-table.svelte';
|
||||
import DownloadDialogWrapper from '$lib/components/download-dialogs/download-dialog-wrapper.svelte';
|
||||
import { getFullyQualifiedMediaName } from '$lib/utils';
|
||||
|
||||
let { show }: { show: components['schemas']['Show'] } = $props();
|
||||
|
||||
let dialogueState = $state(false);
|
||||
let torrentsError: string | null = $state(null);
|
||||
let queryOverride: string = $state('');
|
||||
let filePathSuffix: string = $state('');
|
||||
|
||||
let torrentsPromise: any = $state();
|
||||
let torrentsData: any[] | null = $state(null);
|
||||
let isLoading: boolean = $state(false);
|
||||
|
||||
const tableColumnHeadings = [
|
||||
{ name: 'Size', id: 'size' },
|
||||
{ name: 'Usenet', id: 'usenet' },
|
||||
{ name: 'Seeders', id: 'seeders' },
|
||||
{ name: 'Age', id: 'age' },
|
||||
{ name: 'Score', id: 'score' },
|
||||
{ name: 'Indexer', id: 'indexer' },
|
||||
{ name: 'Indexer Flags', id: 'flags' },
|
||||
{ name: 'Seasons', id: 'season' }
|
||||
];
|
||||
|
||||
async function downloadTorrent(result_id: string) {
|
||||
torrentsError = null;
|
||||
|
||||
const { response } = await client.POST('/api/v1/tv/torrents', {
|
||||
params: {
|
||||
query: {
|
||||
show_id: show.id!,
|
||||
public_indexer_result_id: result_id,
|
||||
override_file_path_suffix: filePathSuffix === '' ? undefined : filePathSuffix
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (response.status === 409) {
|
||||
const errorMessage = `There already is a File using the Filepath Suffix '${filePathSuffix}'. Try again with a different Filepath Suffix.`;
|
||||
console.warn(errorMessage);
|
||||
torrentsError = errorMessage;
|
||||
if (dialogueState) toast.info(errorMessage);
|
||||
} else if (!response.ok) {
|
||||
const errorMessage = `Failed to download torrent for show ${show.id}: ${response.statusText}`;
|
||||
console.error(errorMessage);
|
||||
torrentsError = errorMessage;
|
||||
toast.error(errorMessage);
|
||||
} else {
|
||||
toast.success('Torrent download started successfully!');
|
||||
}
|
||||
|
||||
await invalidateAll();
|
||||
}
|
||||
|
||||
async function search() {
|
||||
if (!queryOverride || queryOverride.trim() === '') {
|
||||
toast.error('Please enter a custom query.');
|
||||
return;
|
||||
}
|
||||
|
||||
isLoading = true;
|
||||
torrentsError = null;
|
||||
torrentsData = null;
|
||||
|
||||
torrentsPromise = client
|
||||
.GET('/api/v1/tv/torrents', {
|
||||
params: {
|
||||
query: {
|
||||
show_id: show.id!,
|
||||
search_query_override: queryOverride
|
||||
}
|
||||
}
|
||||
})
|
||||
.then((data) => data?.data)
|
||||
.finally(() => (isLoading = false));
|
||||
|
||||
toast.info('Searching for torrents...');
|
||||
|
||||
torrentsData = await torrentsPromise;
|
||||
|
||||
if (!torrentsData || torrentsData.length === 0) {
|
||||
toast.info('No torrents found.');
|
||||
} else {
|
||||
toast.success(`Found ${torrentsData.length} torrents.`);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<DownloadDialogWrapper
|
||||
bind:open={dialogueState}
|
||||
triggerText="Custom Download"
|
||||
title="Custom Torrent Download"
|
||||
description="Search and download torrents using a fully custom query string."
|
||||
>
|
||||
<div class="grid w-full items-center gap-1.5">
|
||||
<Label for="query-override">Enter a custom query</Label>
|
||||
|
||||
<div class="flex w-full max-w-sm items-center space-x-2">
|
||||
<Input
|
||||
bind:value={queryOverride}
|
||||
id="query-override"
|
||||
type="text"
|
||||
placeholder={`e.g. ${getFullyQualifiedMediaName(show)} S01 1080p BluRay`}
|
||||
/>
|
||||
<Button disabled={isLoading} class="w-fit" onclick={search}>Search</Button>
|
||||
</div>
|
||||
|
||||
<p class="text-sm text-muted-foreground">
|
||||
The custom query completely overrides the default search logic. Make sure the torrent title
|
||||
matches the episodes you want imported.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{#if torrentsError}
|
||||
<div class="my-2 w-full text-center text-red-500">
|
||||
An error occurred: {torrentsError}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<TorrentTable {torrentsPromise} columns={tableColumnHeadings}>
|
||||
{#snippet rowSnippet(torrent)}
|
||||
<Table.Cell class="font-medium">{torrent.title}</Table.Cell>
|
||||
<Table.Cell>{(torrent.size / 1024 / 1024 / 1024).toFixed(2)}GB</Table.Cell>
|
||||
<Table.Cell>{torrent.usenet}</Table.Cell>
|
||||
<Table.Cell>{torrent.usenet ? 'N/A' : torrent.seeders}</Table.Cell>
|
||||
<Table.Cell>
|
||||
{torrent.age ? formatSecondsToOptimalUnit(torrent.age) : torrent.usenet ? 'N/A' : ''}
|
||||
</Table.Cell>
|
||||
<Table.Cell>{torrent.score}</Table.Cell>
|
||||
<Table.Cell>{torrent.indexer ?? 'unknown'}</Table.Cell>
|
||||
<Table.Cell>
|
||||
{#if torrent.flags}
|
||||
{#each torrent.flags as flag (flag)}
|
||||
<Badge variant="outline">{flag}</Badge>
|
||||
{/each}
|
||||
{/if}
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
{torrent.season ?? '-'}
|
||||
</Table.Cell>
|
||||
<Table.Cell class="text-right">
|
||||
<SelectFilePathSuffixDialog
|
||||
bind:filePathSuffix
|
||||
media={show}
|
||||
callback={() => downloadTorrent(torrent.id)}
|
||||
/>
|
||||
</Table.Cell>
|
||||
{/snippet}
|
||||
</TorrentTable>
|
||||
</DownloadDialogWrapper>
|
||||
@@ -0,0 +1,188 @@
|
||||
<script lang="ts">
|
||||
import { Button } from '$lib/components/ui/button';
|
||||
import { toast } from 'svelte-sonner';
|
||||
import { formatSecondsToOptimalUnit } from '$lib/utils';
|
||||
import * as Table from '$lib/components/ui/table';
|
||||
import { Badge } from '$lib/components/ui/badge';
|
||||
import client from '$lib/api';
|
||||
import type { components } from '$lib/api/api';
|
||||
import SelectFilePathSuffixDialog from '$lib/components/download-dialogs/select-file-path-suffix-dialog.svelte';
|
||||
import { invalidateAll } from '$app/navigation';
|
||||
import TorrentTable from '$lib/components/download-dialogs/torrent-table.svelte';
|
||||
import DownloadDialogWrapper from '$lib/components/download-dialogs/download-dialog-wrapper.svelte';
|
||||
|
||||
let {
|
||||
show,
|
||||
selectedEpisodeNumbers,
|
||||
triggerText = 'Download Episodes'
|
||||
}: {
|
||||
show: components['schemas']['Show'];
|
||||
selectedEpisodeNumbers: { seasonNumber: number; episodeNumber: number }[];
|
||||
triggerText?: string;
|
||||
} = $props();
|
||||
|
||||
let dialogueState = $state(false);
|
||||
let torrentsPromise: any = $state();
|
||||
let torrentsError: string | null = $state(null);
|
||||
let isLoading: boolean = $state(false);
|
||||
let filePathSuffix: string = $state('');
|
||||
|
||||
const tableColumnHeadings = [
|
||||
{ name: 'Size', id: 'size' },
|
||||
{ name: 'Usenet', id: 'usenet' },
|
||||
{ name: 'Seeders', id: 'seeders' },
|
||||
{ name: 'Age', id: 'age' },
|
||||
{ name: 'Score', id: 'score' },
|
||||
{ name: 'Indexer', id: 'indexer' },
|
||||
{ name: 'Indexer Flags', id: 'flags' }
|
||||
];
|
||||
|
||||
function torrentMatchesSelectedEpisodes(
|
||||
torrentTitle: string,
|
||||
selectedEpisodes: { seasonNumber: number; episodeNumber: number }[]
|
||||
) {
|
||||
const normalizedTitle = torrentTitle.toLowerCase();
|
||||
|
||||
return selectedEpisodes.some((ep) => {
|
||||
const s = String(ep.seasonNumber).padStart(2, '0');
|
||||
const e = String(ep.episodeNumber).padStart(2, '0');
|
||||
|
||||
const patterns = [
|
||||
`s${s}e${e}`,
|
||||
`${s}x${e}`,
|
||||
`season ${ep.seasonNumber} episode ${ep.episodeNumber}`
|
||||
];
|
||||
|
||||
return patterns.some((pattern) => normalizedTitle.includes(pattern));
|
||||
});
|
||||
}
|
||||
|
||||
async function search() {
|
||||
if (!selectedEpisodeNumbers || selectedEpisodeNumbers.length === 0) {
|
||||
toast.error('No episodes selected.');
|
||||
return;
|
||||
}
|
||||
|
||||
isLoading = true;
|
||||
torrentsError = null;
|
||||
|
||||
torrentsPromise = Promise.all(
|
||||
selectedEpisodeNumbers.map((ep) =>
|
||||
client
|
||||
.GET('/api/v1/tv/torrents', {
|
||||
params: {
|
||||
query: {
|
||||
show_id: show.id!,
|
||||
season_number: ep.seasonNumber,
|
||||
episode_number: ep.episodeNumber
|
||||
}
|
||||
}
|
||||
})
|
||||
.then((r) => r?.data ?? [])
|
||||
)
|
||||
)
|
||||
.then((results) => results.flat())
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
.then((allTorrents: any[]) =>
|
||||
allTorrents.filter((torrent) =>
|
||||
torrentMatchesSelectedEpisodes(torrent.title, selectedEpisodeNumbers)
|
||||
)
|
||||
)
|
||||
.finally(() => (isLoading = false));
|
||||
|
||||
try {
|
||||
await torrentsPromise;
|
||||
} catch (error: any) {
|
||||
console.error(error);
|
||||
torrentsError = error.message || 'An error occurred while searching for torrents.';
|
||||
toast.error(torrentsError);
|
||||
}
|
||||
}
|
||||
|
||||
async function downloadTorrent(result_id: string) {
|
||||
const { response } = await client.POST('/api/v1/tv/torrents', {
|
||||
params: {
|
||||
query: {
|
||||
show_id: show.id!,
|
||||
public_indexer_result_id: result_id,
|
||||
override_file_path_suffix: filePathSuffix === '' ? undefined : filePathSuffix
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
toast.error('Download failed.');
|
||||
} else {
|
||||
toast.success('Download started.');
|
||||
}
|
||||
|
||||
await invalidateAll();
|
||||
}
|
||||
</script>
|
||||
|
||||
<DownloadDialogWrapper
|
||||
bind:open={dialogueState}
|
||||
{triggerText}
|
||||
title="Download Selected Episodes"
|
||||
description="Search and download torrents for selected episodes."
|
||||
>
|
||||
<div class="flex flex-col gap-3">
|
||||
<p class="text-sm text-muted-foreground">
|
||||
Selected episodes:
|
||||
<strong>
|
||||
{selectedEpisodeNumbers.length > 0
|
||||
? selectedEpisodeNumbers
|
||||
.map(
|
||||
(e) =>
|
||||
`S${String(e.seasonNumber).padStart(2, '0')}E${String(e.episodeNumber).padStart(2, '0')}`
|
||||
)
|
||||
.join(', ')
|
||||
: 'None'}
|
||||
</strong>
|
||||
</p>
|
||||
|
||||
<Button
|
||||
class="w-fit"
|
||||
disabled={isLoading || selectedEpisodeNumbers.length === 0}
|
||||
onclick={search}
|
||||
>
|
||||
Search Torrents
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{#if torrentsError}
|
||||
<div class="my-2 w-full text-center text-red-500">
|
||||
An error occurred: {torrentsError}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<TorrentTable {torrentsPromise} columns={tableColumnHeadings}>
|
||||
{#snippet rowSnippet(torrent)}
|
||||
<Table.Cell>{torrent.title}</Table.Cell>
|
||||
<Table.Cell>
|
||||
{(torrent.size / 1024 / 1024 / 1024).toFixed(2)}GB
|
||||
</Table.Cell>
|
||||
<Table.Cell>{torrent.usenet}</Table.Cell>
|
||||
<Table.Cell>{torrent.usenet ? 'N/A' : torrent.seeders}</Table.Cell>
|
||||
<Table.Cell>
|
||||
{torrent.age ? formatSecondsToOptimalUnit(torrent.age) : torrent.usenet ? 'N/A' : ''}
|
||||
</Table.Cell>
|
||||
<Table.Cell>{torrent.score}</Table.Cell>
|
||||
<Table.Cell>{torrent.indexer ?? 'unknown'}</Table.Cell>
|
||||
<Table.Cell>
|
||||
{#if torrent.flags}
|
||||
{#each torrent.flags as flag (flag)}
|
||||
<Badge variant="outline">{flag}</Badge>
|
||||
{/each}
|
||||
{/if}
|
||||
</Table.Cell>
|
||||
<Table.Cell class="text-right">
|
||||
<SelectFilePathSuffixDialog
|
||||
bind:filePathSuffix
|
||||
media={show}
|
||||
callback={() => downloadTorrent(torrent.id)}
|
||||
/>
|
||||
</Table.Cell>
|
||||
{/snippet}
|
||||
</TorrentTable>
|
||||
</DownloadDialogWrapper>
|
||||
@@ -0,0 +1,189 @@
|
||||
<script lang="ts">
|
||||
import { Button } from '$lib/components/ui/button';
|
||||
import { toast } from 'svelte-sonner';
|
||||
import { formatSecondsToOptimalUnit } from '$lib/utils.ts';
|
||||
import * as Table from '$lib/components/ui/table';
|
||||
import { Badge } from '$lib/components/ui/badge';
|
||||
import client from '$lib/api';
|
||||
import type { components } from '$lib/api/api';
|
||||
import SelectFilePathSuffixDialog from '$lib/components/download-dialogs/select-file-path-suffix-dialog.svelte';
|
||||
import { invalidateAll } from '$app/navigation';
|
||||
import TorrentTable from '$lib/components/download-dialogs/torrent-table.svelte';
|
||||
import DownloadDialogWrapper from '$lib/components/download-dialogs/download-dialog-wrapper.svelte';
|
||||
|
||||
let {
|
||||
show,
|
||||
selectedSeasonNumbers,
|
||||
triggerText = 'Download Selected Seasons'
|
||||
}: {
|
||||
show: components['schemas']['Show'];
|
||||
selectedSeasonNumbers: number[];
|
||||
triggerText?: string;
|
||||
} = $props();
|
||||
|
||||
let dialogueState = $state(false);
|
||||
let torrentsError: string | null = $state(null);
|
||||
let filePathSuffix: string = $state('');
|
||||
let torrentsPromise: any = $state();
|
||||
let isLoading: boolean = $state(false);
|
||||
|
||||
const tableColumnHeadings = [
|
||||
{ name: 'Size', id: 'size' },
|
||||
{ name: 'Usenet', id: 'usenet' },
|
||||
{ name: 'Seeders', id: 'seeders' },
|
||||
{ name: 'Age', id: 'age' },
|
||||
{ name: 'Score', id: 'score' },
|
||||
{ name: 'Indexer', id: 'indexer' },
|
||||
{ name: 'Indexer Flags', id: 'flags' },
|
||||
{ name: 'Seasons', id: 'season' }
|
||||
];
|
||||
|
||||
async function downloadTorrent(result_id: string) {
|
||||
torrentsError = null;
|
||||
|
||||
const { response } = await client.POST('/api/v1/tv/torrents', {
|
||||
params: {
|
||||
query: {
|
||||
show_id: show.id!,
|
||||
public_indexer_result_id: result_id,
|
||||
override_file_path_suffix: filePathSuffix === '' ? undefined : filePathSuffix
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (response.status === 409) {
|
||||
const errorMessage = `Filepath Suffix '${filePathSuffix}' already exists.`;
|
||||
torrentsError = errorMessage;
|
||||
toast.error(errorMessage);
|
||||
} else if (!response.ok) {
|
||||
const errorMessage = `Failed to download torrent: ${response.statusText}`;
|
||||
torrentsError = errorMessage;
|
||||
toast.error(errorMessage);
|
||||
} else {
|
||||
toast.success('Torrent download started successfully!');
|
||||
}
|
||||
|
||||
await invalidateAll();
|
||||
}
|
||||
|
||||
function isEpisodeRelease(title: string) {
|
||||
const lower = title.toLowerCase();
|
||||
|
||||
const episodePatterns = [
|
||||
/s\d{1,2}e\d{1,2}/i,
|
||||
/\d{1,2}x\d{1,2}/i,
|
||||
/\be\d{1,2}\b/i,
|
||||
/e\d{1,2}-e?\d{1,2}/i,
|
||||
/vol\.?\s?\d+/i
|
||||
];
|
||||
|
||||
return episodePatterns.some((regex) => regex.test(lower));
|
||||
}
|
||||
|
||||
async function search() {
|
||||
if (!selectedSeasonNumbers || selectedSeasonNumbers.length === 0) {
|
||||
toast.error('No seasons selected.');
|
||||
return;
|
||||
}
|
||||
|
||||
isLoading = true;
|
||||
torrentsError = null;
|
||||
|
||||
toast.info(`Searching torrents for seasons: ${selectedSeasonNumbers.join(', ')}`);
|
||||
|
||||
torrentsPromise = Promise.all(
|
||||
selectedSeasonNumbers.map((seasonNumber) =>
|
||||
client
|
||||
.GET('/api/v1/tv/torrents', {
|
||||
params: {
|
||||
query: {
|
||||
show_id: show.id!,
|
||||
season_number: seasonNumber
|
||||
}
|
||||
}
|
||||
})
|
||||
.then((data) => data?.data ?? [])
|
||||
)
|
||||
)
|
||||
.then((results) => results.flat())
|
||||
.then((allTorrents) => allTorrents.filter((torrent) => !isEpisodeRelease(torrent.title)))
|
||||
.finally(() => (isLoading = false));
|
||||
|
||||
try {
|
||||
await torrentsPromise;
|
||||
} catch (error: any) {
|
||||
console.error(error);
|
||||
torrentsError = error.message || 'An error occurred while searching for torrents.';
|
||||
toast.error(torrentsError);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<DownloadDialogWrapper
|
||||
bind:open={dialogueState}
|
||||
{triggerText}
|
||||
title="Download Selected Seasons"
|
||||
description="Search and download torrents for the selected seasons."
|
||||
>
|
||||
<div class="flex flex-col gap-3">
|
||||
<p class="text-sm text-muted-foreground">
|
||||
Selected seasons:
|
||||
<strong>
|
||||
{selectedSeasonNumbers.length > 0
|
||||
? selectedSeasonNumbers
|
||||
.slice()
|
||||
.sort((a, b) => a - b)
|
||||
.map((n) => `S${String(n).padStart(2, '0')}`)
|
||||
.join(', ')
|
||||
: 'None'}
|
||||
</strong>
|
||||
</p>
|
||||
|
||||
<Button
|
||||
class="w-fit"
|
||||
disabled={isLoading || selectedSeasonNumbers.length === 0}
|
||||
onclick={search}
|
||||
>
|
||||
Search Torrents
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{#if torrentsError}
|
||||
<div class="my-2 w-full text-center text-red-500">
|
||||
An error occurred: {torrentsError}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<TorrentTable {torrentsPromise} columns={tableColumnHeadings}>
|
||||
{#snippet rowSnippet(torrent)}
|
||||
<Table.Cell class="font-medium">{torrent.title}</Table.Cell>
|
||||
<Table.Cell>
|
||||
{(torrent.size / 1024 / 1024 / 1024).toFixed(2)}GB
|
||||
</Table.Cell>
|
||||
<Table.Cell>{torrent.usenet}</Table.Cell>
|
||||
<Table.Cell>{torrent.usenet ? 'N/A' : torrent.seeders}</Table.Cell>
|
||||
<Table.Cell>
|
||||
{torrent.age ? formatSecondsToOptimalUnit(torrent.age) : torrent.usenet ? 'N/A' : ''}
|
||||
</Table.Cell>
|
||||
<Table.Cell>{torrent.score}</Table.Cell>
|
||||
<Table.Cell>{torrent.indexer ?? 'unknown'}</Table.Cell>
|
||||
<Table.Cell>
|
||||
{#if torrent.flags}
|
||||
{#each torrent.flags as flag (flag)}
|
||||
<Badge variant="outline">{flag}</Badge>
|
||||
{/each}
|
||||
{/if}
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
{torrent.season ?? '-'}
|
||||
</Table.Cell>
|
||||
<Table.Cell class="text-right">
|
||||
<SelectFilePathSuffixDialog
|
||||
bind:filePathSuffix
|
||||
media={show}
|
||||
callback={() => downloadTorrent(torrent.id)}
|
||||
/>
|
||||
</Table.Cell>
|
||||
{/snippet}
|
||||
</TorrentTable>
|
||||
</DownloadDialogWrapper>
|
||||
@@ -1,6 +1,7 @@
|
||||
<script lang="ts">
|
||||
import {
|
||||
convertTorrentSeasonRangeToIntegerRange,
|
||||
convertTorrentEpisodeRangeToIntegerRange,
|
||||
getTorrentQualityString,
|
||||
getTorrentStatusString
|
||||
} from '$lib/utils.js';
|
||||
@@ -59,6 +60,7 @@
|
||||
<Table.Head>Name</Table.Head>
|
||||
{#if isShow}
|
||||
<Table.Head>Seasons</Table.Head>
|
||||
<Table.Head>Episodes</Table.Head>
|
||||
{/if}
|
||||
<Table.Head>Download Status</Table.Head>
|
||||
<Table.Head>Quality</Table.Head>
|
||||
@@ -97,6 +99,11 @@
|
||||
(torrent as components['schemas']['RichSeasonTorrent']).seasons!
|
||||
)}
|
||||
</Table.Cell>
|
||||
<Table.Cell>
|
||||
{convertTorrentEpisodeRangeToIntegerRange(
|
||||
(torrent as components['schemas']['RichSeasonTorrent']).episodes!
|
||||
)}
|
||||
</Table.Cell>
|
||||
{/if}
|
||||
<Table.Cell>
|
||||
{getTorrentStatusString(torrent.status)}
|
||||
|
||||
@@ -51,6 +51,17 @@ export function convertTorrentSeasonRangeToIntegerRange(seasons: number[]): stri
|
||||
}
|
||||
}
|
||||
|
||||
export function convertTorrentEpisodeRangeToIntegerRange(episodes: number[]): string {
|
||||
if (episodes.length === 1) return episodes[0]?.toString() || 'unknown';
|
||||
else if (episodes.length > 1) {
|
||||
const lastEpisode = episodes.at(-1);
|
||||
return episodes[0]?.toString() + '-' + (lastEpisode?.toString() || 'unknown');
|
||||
} else {
|
||||
console.log('Error parsing episode range: ' + episodes);
|
||||
return 'Error parsing episode range: ' + episodes;
|
||||
}
|
||||
}
|
||||
|
||||
export async function handleLogout() {
|
||||
await client.POST('/api/v1/auth/cookie/logout');
|
||||
await goto(resolve('/login', {}));
|
||||
|
||||
Reference in New Issue
Block a user