Skip to content

Commit

Permalink
feat(option): add includeSeasonPackEpisodes
Browse files Browse the repository at this point in the history
addresses the feature request for individual episodes in season packs being included/excluded in searches

cross-seed#488

fix(includeSeasonPackEpsiodes): added `--no-include-season-pack-episodes`

missed an option in cmd.ts, added for consistency
  • Loading branch information
zakkarry authored and mmgoodnow committed Sep 25, 2023
1 parent 3835371 commit c03e331
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 12 deletions.
6 changes: 6 additions & 0 deletions src/cmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,17 @@ function createCommandWithSharedOptions(name, description) {
"Include single-episode torrents in the search",
fallback(fileConfig.includeEpisodes, false)
)
.option(
"--include-season-pack-episodes",
"Include episodes from a season pack in the search",
fallback(fileConfig.includeSeasonPackEpisodes, false)
)
.option(
"--no-include-non-videos",
"Don't include torrents which contain non-videos"
)
.option("--no-include-episodes", "Don't include episode torrents")
.option("--no-include-season-pack-episodes", "Don't include episodes from a season pack")
.requiredOption(
"--fuzzy-size-threshold <decimal>",
"The size difference allowed to be considered a match.",
Expand Down
16 changes: 13 additions & 3 deletions src/config.template.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,25 @@ module.exports = {
outputDir: ".",

/**
*
* To search for everything except individual episodes, use (includeEpisodes: false, includeSeasonPackEpisodes: false, includeNonVideos: true)
* To search for all episodes, use (includeEpisodes: true, includeSeasonPackEpisodes: true, includeNonVideos: true)
* To search for season pack episodes, but exclude single episode torrents, use (includeEpisodes: false, includeSeasonPackEpisodes: true, includeNonVideos: true)
*
* Whether to search for single episode torrents
*/
includeEpisodes: false,

/**
* Whether to search for single episodes from a season pack during
* data based searches.
*/
includeSeasonPackEpisodes: false,

/**
* Include torrents which contain non-video files
* This option does not override includeEpisodes.
* To search for everything except episodes, use (includeEpisodes: false, includeNonVideos: true)
* To search for everything including episodes, use (includeEpisodes: true, includeNonVideos: true)
* This option does not override includeEpisodes or
* includeSeasonPackEpisodes.
*/
includeNonVideos: false,

Expand Down
16 changes: 13 additions & 3 deletions src/config.template.docker.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,25 @@ module.exports = {
outputDir: "/cross-seeds",

/**
*
* To search for everything except individual episodes, use (includeEpisodes: false, includeSeasonPackEpisodes: false, includeNonVideos: true)
* To search for all episodes, use (includeEpisodes: true, includeSeasonPackEpisodes: true, includeNonVideos: true)
* To search for season pack episodes, but exclude single episode torrents, use (includeEpisodes: false, includeSeasonPackEpisodes: true, includeNonVideos: true)
*
* Whether to search for single episode torrents
*/
includeEpisodes: false,

/**
* Whether to search for single episodes from a season pack during
* data based searches.
*/
includeSeasonPackEpisodes: false,

/**
* Include torrents which contain non-video files
* This option does not override includeEpisodes.
* To search for everything except episodes, use (includeEpisodes: false, includeNonVideos: true)
* To search for everything including episodes, use (includeEpisodes: true, includeNonVideos: true)
* This option does not override includeEpisodes or
* includeSeasonPackEpisodes.
*/
includeNonVideos: false,

Expand Down
1 change: 1 addition & 0 deletions src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface FileConfig {
configVersion?: number;
delay?: number;
includeEpisodes?: boolean;
includeSeasonPackEpisodes?: boolean;
outputDir?: string;
rtorrentRpcUrl?: string;
includeNonVideos?: boolean;
Expand Down
17 changes: 11 additions & 6 deletions src/preFilter.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import ms from "ms";
import { extname } from "path";
import { EP_REGEX, VIDEO_EXTENSIONS } from "./constants.js";
import { EP_REGEX, SEASON_REGEX, VIDEO_EXTENSIONS } from "./constants.js";
import { db } from "./db.js";
import { getEnabledIndexers } from "./indexers.js";
import { Label, logger } from "./logger.js";
import { getRuntimeConfig } from "./runtimeConfig.js";
import { Searchee } from "./searchee.js";
import { humanReadable, nMsAgo } from "./utils.js";
import path from "path";

export function filterByContent(searchee: Searchee): boolean {
const { includeEpisodes, includeNonVideos } = getRuntimeConfig();
const { includeEpisodes, includeNonVideos, includeSeasonPackEpisodes } = getRuntimeConfig();

function logReason(reason): void {
logger.verbose({
Expand All @@ -18,14 +19,18 @@ export function filterByContent(searchee: Searchee): boolean {
});
}

const isSingleEpisodeTorrent =
searchee.files.length === 1 && EP_REGEX.test(searchee.files[0].name);

if (!includeEpisodes && isSingleEpisodeTorrent) {
const isSingleEpisodeTorrent = searchee.files.length === 1 && EP_REGEX.test(searchee.name);
const isSeasonPack = typeof searchee.path !== 'undefined' ? SEASON_REGEX.test(path.dirname(searchee.path).split(path.sep).reverse()[0]): false;
if (!includeEpisodes && isSingleEpisodeTorrent && !isSeasonPack) {
logReason("it is a single episode");
return false;
}

if (!includeSeasonPackEpisodes && (searchee.files.length === 1 && isSeasonPack)) {
logReason("it is a season pack episode");
return false;
}
const allFilesAreVideos = searchee.files.every((file) =>
VIDEO_EXTENSIONS.includes(extname(file.name))
);
Expand Down
1 change: 1 addition & 0 deletions src/runtimeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface RuntimeConfig {
torrentDir: string;
outputDir: string;
includeEpisodes: boolean;
includeSeasonPackEpisodes: boolean;
verbose: boolean;
includeNonVideos: boolean;
fuzzySizeThreshold: number;
Expand Down

0 comments on commit c03e331

Please sign in to comment.