Skip to content

Commit

Permalink
feat(option): add includeSingleEpisodes (cross-seed#493)
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 data based searches
(cross-seed#488)

usage noted in updated config templates.
  • Loading branch information
zakkarry authored Sep 27, 2023
2 parents 3835371 + 702749c commit e4fcaef
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 14 deletions.
7 changes: 6 additions & 1 deletion src/cmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,14 @@ function createCommandWithSharedOptions(name, description) {
)
.option(
"-e, --include-episodes",
"Include single-episode torrents in the search",
"Include all episode torrents in the search (including from season packs)",
fallback(fileConfig.includeEpisodes, false)
)
.option(
"--include-single-episodes",
"Include single episode torrents in the search",
fallback(fileConfig.includeSingleEpisodes, false)
)
.option(
"--no-include-non-videos",
"Don't include torrents which contain non-videos"
Expand Down
17 changes: 13 additions & 4 deletions src/config.template.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,24 @@ module.exports = {
outputDir: ".",

/**
* Whether to search for single episode torrents
* Whether to search for all episode torrents, including those from season packs. This option overrides includeSingleEpisodes.
*/
includeEpisodes: false,

/**
* Whether to include single episode torrents in the search (not from season packs).
* Like `includeEpisodes` but slightly more restrictive.
*/
includeSingleEpisodes: 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)
* This option does not override includeEpisodes or includeSingleEpisodes.
*
* To search for everything except episodes, use (includeEpisodes: false, includeSingleEpisodes: false, includeNonVideos: true)
* To search for everything including episodes, use (includeEpisodes: true, includeNonVideos: true)
* To search for everything except season pack episodes (data-based)
* use (includeEpisodes: false, includeSingleEpisodes: true, includeNonVideos: true)
*/
includeNonVideos: false,

Expand Down Expand Up @@ -217,7 +226,7 @@ module.exports = {
searchTimeout: undefined,

/**
* The number of searches to be done before it stop.
* The number of searches to be done before it stops.
* Combine this with "excludeRecentSearch" and "searchCadence" to smooth long-term API usage patterns.
* Default is no limit.
*/
Expand Down
17 changes: 13 additions & 4 deletions src/config.template.docker.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,24 @@ module.exports = {
outputDir: "/cross-seeds",

/**
* Whether to search for single episode torrents
* Whether to search for all episode torrents, including those from season packs. This option overrides includeSingleEpisodes.
*/
includeEpisodes: false,

/**
* Whether to include single episode torrents in the search (not from season packs).
* Like `includeEpisodes` but slightly more restrictive.
*/
includeSingleEpisodes: 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)
* This option does not override includeEpisodes or includeSingleEpisodes.
*
* To search for everything except episodes, use (includeEpisodes: false, includeSingleEpisodes: false, includeNonVideos: true)
* To search for everything including episodes, use (includeEpisodes: true, includeNonVideos: true)
* To search for everything except season pack episodes (data-based)
* use (includeEpisodes: false, includeSingleEpisodes: true, includeNonVideos: true)
*/
includeNonVideos: false,

Expand Down Expand Up @@ -221,7 +230,7 @@ module.exports = {
searchTimeout: undefined,

/**
* The number of searches to be done before stop.
* The number of searches to be done before it stops.
* Combine this with "excludeRecentSearch" and "searchCadence" to smooth long-term API usage patterns.
* Default is no limit.
*/
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;
includeSingleEpisodes?: boolean;
outputDir?: string;
rtorrentRpcUrl?: string;
includeNonVideos?: boolean;
Expand Down
15 changes: 10 additions & 5 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, includeSingleEpisodes } = 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);
const isSingleEpisodeTorrent = searchee.files.length === 1 && EP_REGEX.test(searchee.name);
const isSeasonPackEpisode = searchee.path && searchee.files.length === 1 && SEASON_REGEX.test(path.basename(path.dirname(searchee.path)));

if (!includeEpisodes && isSingleEpisodeTorrent) {
if (!includeEpisodes && !includeSingleEpisodes && isSingleEpisodeTorrent && !isSeasonPackEpisode) {
logReason("it is a single episode");
return false;
}

if (!includeEpisodes && isSeasonPackEpisode) {
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;
includeSingleEpisodes: boolean;
verbose: boolean;
includeNonVideos: boolean;
fuzzySizeThreshold: number;
Expand Down

0 comments on commit e4fcaef

Please sign in to comment.