diff --git a/package-lock.json b/package-lock.json index d7d40e94f..5f935310f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "cross-seed", - "version": "5.4.3", + "version": "5.4.5", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "cross-seed", - "version": "5.4.3", + "version": "5.4.5", "license": "Apache-2.0", "dependencies": { "bencode": "^2.0.1", diff --git a/package.json b/package.json index 0b1979483..ee46be51a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cross-seed", - "version": "5.4.3", + "version": "5.4.5", "description": "Query Jackett for cross-seedable torrents", "scripts": { "test": "true", diff --git a/src/constants.ts b/src/constants.ts index 187c17a57..3f270b312 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -6,11 +6,11 @@ export const PROGRAM_NAME = packageDotJson.name; export const PROGRAM_VERSION = packageDotJson.version; export const USER_AGENT = `CrossSeed/${PROGRAM_VERSION}`; -export const EP_REGEX = /^(?.+)[. ](?<season>S\d+)(?<episode>E\d+)/i; +export const EP_REGEX = /^(?<title>.+?)[\s._](?<season>S\d+)?[_.\s]?(?<episode>E\d+(?:[-\s]?E?\d+)?)/i; export const SEASON_REGEX = - /^(?<title>.+)[. ](?<season>S\d+)(?:\s?-\s?(?<seasonmax>S?\d+))?(?!E\d+)/i; + /^(?<title>.+?)[_.\s](?<season>S\d+)(?:[.\-\s]*?(?<seasonmax>S?\d+))?(?=[_.\s](?!E\d+))/i; export const MOVIE_REGEX = - /^(?<title>.+)[. ][[(]?(?<year>\d{4})[)\]]?(?![pi])/i; + /^(?<title>.+?)[._\s][[(]?(?<year>\d{4})[)\]]?(?![pi])/i; export const VIDEO_EXTENSIONS = [".mkv", ".mp4", ".avi"]; diff --git a/src/torznab.ts b/src/torznab.ts index 27475f3dc..bed7aecec 100644 --- a/src/torznab.ts +++ b/src/torznab.ts @@ -1,7 +1,7 @@ import ms from "ms"; import fetch from "node-fetch"; import xml2js from "xml2js"; -import { EP_REGEX, SEASON_REGEX } from "./constants.js"; +import { EP_REGEX, SEASON_REGEX, USER_AGENT } from "./constants.js"; import { db } from "./db.js"; import { CrossSeedError } from "./errors.js"; import { @@ -21,7 +21,6 @@ import { reformatTitleForSearching, stripExtension, } from "./utils.js"; -import { USER_AGENT } from "./constants.js"; interface TorznabParams { t: "caps" | "search" | "tvsearch" | "movie"; @@ -463,16 +462,26 @@ async function makeRequests( }) .then((response) => { if (!response.ok) { - if (response.status === 429) { + const retryAfterSeconds = Number( + response.headers.get("Retry-After") + ); + + if (!Number.isNaN(retryAfterSeconds)) { updateIndexerStatus( - IndexerStatus.RATE_LIMITED, - Date.now() + ms("1 hour"), + response.status === 429 + ? IndexerStatus.RATE_LIMITED + : IndexerStatus.UNKNOWN_ERROR, + Date.now() + ms(`${retryAfterSeconds} seconds`), [indexers[i].id] ); } else { updateIndexerStatus( - IndexerStatus.UNKNOWN_ERROR, - Date.now() + ms("1 hour"), + response.status === 429 + ? IndexerStatus.RATE_LIMITED + : IndexerStatus.UNKNOWN_ERROR, + response.status === 429 + ? Date.now() + ms("1 hour") + : Date.now() + ms("10 minutes"), [indexers[i].id] ); } @@ -480,9 +489,8 @@ async function makeRequests( `request failed with code: ${response.status}` ); } - return response; + return response.text(); }) - .then((r) => r.text()) .then(xml2js.parseStringPromise) .then(parseTorznabResults) )