diff --git a/src/constants.ts b/src/constants.ts
index 100a97951..52d294a3e 100644
--- a/src/constants.ts
+++ b/src/constants.ts
@@ -12,6 +12,7 @@ export const SEASON_REGEX =
/^(?
.+?)[_.\s-]+(?S\d+)(?:[_.\s-]*?(?S?\d+))?(?=[_.\s](?!E\d+))/i;
export const MOVIE_REGEX =
/^(?.+?)[_.\s][[(]?(?\d{4})[)\]]?(?![pi])/i;
+export const RELEASE_GROUP_REGEX = /(?<=-)[\w ]+(?=(?:\.\w{1,5})?$)/i;
export const VIDEO_EXTENSIONS = [".mkv", ".mp4", ".avi"];
@@ -46,6 +47,7 @@ export enum Decision {
RATE_LIMITED = "RATE_LIMITED",
INFO_HASH_ALREADY_EXISTS = "INFO_HASH_ALREADY_EXISTS",
FILE_TREE_MISMATCH = "FILE_TREE_MISMATCH",
+ RELEASE_GROUP_MISMATCH = "RELEASE_GROUP_MISMATCH",
}
export enum MatchMode {
diff --git a/src/decide.ts b/src/decide.ts
index ac6779b02..a163cac1b 100644
--- a/src/decide.ts
+++ b/src/decide.ts
@@ -1,7 +1,12 @@
import { existsSync, statSync, writeFileSync } from "fs";
import path from "path";
import { appDir } from "./configuration.js";
-import { Decision, MatchMode, TORRENT_CACHE_FOLDER } from "./constants.js";
+import {
+ Decision,
+ MatchMode,
+ RELEASE_GROUP_REGEX,
+ TORRENT_CACHE_FOLDER,
+} from "./constants.js";
import { db } from "./db.js";
import { Label, logger } from "./logger.js";
import { Metafile } from "./parseTorrent.js";
@@ -30,6 +35,8 @@ const createReasonLogger =
}
let reason;
switch (decision) {
+ case Decision.MATCH_SIZE_ONLY:
+ return;
case Decision.MATCH:
return;
case Decision.SIZE_MISMATCH:
@@ -50,6 +57,9 @@ const createReasonLogger =
case Decision.FILE_TREE_MISMATCH:
reason = "it has a different file tree";
break;
+ case Decision.RELEASE_GROUP_MISMATCH:
+ reason = "it has a different release group";
+ break;
default:
reason = decision;
break;
@@ -97,8 +107,24 @@ function sizeDoesMatch(resultSize, searchee) {
return resultSize >= lowerBound && resultSize <= upperBound;
}
+function releaseGroupDoesMatch(
+ searcheeName: string,
+ candidateName: string,
+ matchMode: MatchMode
+) {
+ const searcheeMatch = searcheeName.match(RELEASE_GROUP_REGEX);
+ const candidateMatch = candidateName.match(RELEASE_GROUP_REGEX);
+
+ // if we are unsure, pass in risky mode but fail in safe mode
+ if (!searcheeMatch || !candidateMatch) {
+ return matchMode === MatchMode.RISKY;
+ }
+
+ return searcheeMatch[0].toLowerCase() === candidateMatch[0].toLowerCase();
+}
+
async function assessCandidateHelper(
- { link, size }: Candidate,
+ { link, size, name }: Candidate,
searchee: Searchee,
hashesToExclude: string[]
): Promise {
@@ -110,6 +136,9 @@ async function assessCandidateHelper(
if (!link) return { decision: Decision.NO_DOWNLOAD_LINK };
+ if (!releaseGroupDoesMatch(searchee.name, name, matchMode))
+ return { decision: Decision.RELEASE_GROUP_MISMATCH };
+
const result = await parseTorrentFromURL(link);
if (result.isErr()) {