File size: 2,205 Bytes
762fa11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
export const guessSeasonEpisode = (name) => {
    const str = name.replace(/\W/g, " ").toLowerCase();
    const seasonMatch = [...str.matchAll(/[s](?<season>\d+)/g)];
    const episodeMatch = str.match(/[e](?<episode>\d+)/);
    if (seasonMatch.length === 0 && str.includes("complete")) {
        return { completeSeries: true };
    }
    else if (seasonMatch.length === 1 && !episodeMatch) {
        const season = Number(seasonMatch[0].groups?.season) || 0;
        return { seasons: [season] };
    }
    else if (seasonMatch.length > 1) {
        const firstSeason = Number(seasonMatch[0].groups?.season) || 0;
        const lastSeason = Number(seasonMatch[seasonMatch.length - 1].groups?.season) || 0;
        const seasons = [];
        for (let i = firstSeason; i <= lastSeason; i++)
            seasons.push(i);
        return { seasons };
    }
    else if (seasonMatch[0] || episodeMatch) {
        const season = Number(seasonMatch[0]?.groups?.season) || undefined;
        const episode = Number(episodeMatch?.groups?.episode) || undefined;
        return { season, episode };
    }
    else {
        const seasonEpisodeMatch = str.match(/(?<season>\d+)x(?<episode>\d+)/);
        const season = Number(seasonEpisodeMatch?.groups?.season) || undefined;
        const episode = Number(seasonEpisodeMatch?.groups?.episode) || undefined;
        return { season, episode };
    }
};
export const isTorrentNameMatch = (name, season, episode) => {
    const guess = guessSeasonEpisode(name);
    if (guess.completeSeries)
        return true;
    if (guess.seasons?.includes(season))
        return true;
    if (guess.season === season && guess.episode === episode)
        return true;
    if (season === 0) {
        if (name.toLowerCase().includes("special"))
            return true;
        if (guess.season === undefined && guess.seasons === undefined)
            return true;
    }
    return false;
};
export const isFileNameMatch = (name, season, episode) => {
    const guess = guessSeasonEpisode(name);
    if (guess.season === season && guess.episode === episode)
        return true;
    if (season === 0)
        return true;
    return false;
};
//# sourceMappingURL=shows.js.map