diff --git a/components/Preview/components/Torrents/components/TorrentsTable/components/Actions/index.tsx b/components/Preview/components/Torrents/components/TorrentsTable/components/Actions/index.tsx index 11e8685..da04261 100644 --- a/components/Preview/components/Torrents/components/TorrentsTable/components/Actions/index.tsx +++ b/components/Preview/components/Torrents/components/TorrentsTable/components/Actions/index.tsx @@ -8,7 +8,7 @@ import ButtonsGroup from '@/components/ui/buttons-group'; import { Quality } from '@/data/parsers/yts/models'; import { useM3UUrl } from '@/hooks/useM3UStreamUrl'; import { useStreamUrl } from '@/hooks/useStreamUrl'; -import { cn, detectSafari, getMagnetHash, isStandaloneApp, torrentKey } from '@/lib/utils'; +import { cn, detectSafari, getMagnetHash, isStandaloneApp, seasonFromEpisodes, torrentKey } from '@/lib/utils'; import usePinnedTorrents from '../../../../usePinnedTorrents'; import useUnplayable from '../../../../useUnplayable'; @@ -82,10 +82,16 @@ const Actions: FC = ({ torrent, title, provider, show }) => { type: show.type, name: show.title, imdb_id: show.imdb_id ?? '', + tmdb_id: show.id?.toString() ?? '', year: new Date(show.release).getFullYear().toString(), runtime: show.runtime?.toString() ?? '' }); + if (show.type === 'tv') { + const season = seasonFromEpisodes(torrent.episodes) ?? show.airing?.season; + if (season != null) params.set('season', season.toString()); + } + if (isSafari) { const link = window.open(`${M3UUrl}?${params}`, '_blank'); return setTimeout(() => { diff --git a/lib/utils.ts b/lib/utils.ts index 87a2376..7eaaad5 100644 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -55,6 +55,13 @@ export const getMagnetHash = (link: string) => { export const torrentKey = (torrent: Torrent) => torrent.download || getMagnetHash(torrent.magnet) || torrent.hash || torrent.id; +export const seasonFromEpisodes = (episodes?: string): number | undefined => { + if (!episodes) return undefined; + if (/^S\d+\s*[-–—]\s*\d+/i.test(episodes)) return undefined; + const [, season] = episodes.match(/^S(\d+)/i) || []; + return season ? Number(season) : undefined; +}; + export const formatBytes = (bytes?: number) => { if (bytes == null || !isFinite(bytes)) return '';