Skip to content

Commit

Permalink
Merge branch 'cross-seed:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
hummingbirdy2 authored Sep 13, 2023
2 parents 52c674b + d168ac8 commit 956a617
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
6 changes: 3 additions & 3 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = /^(?<title>.+)[. ](?<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"];

Expand Down
26 changes: 17 additions & 9 deletions src/torznab.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -21,7 +21,6 @@ import {
reformatTitleForSearching,
stripExtension,
} from "./utils.js";
import { USER_AGENT } from "./constants.js";

interface TorznabParams {
t: "caps" | "search" | "tvsearch" | "movie";
Expand Down Expand Up @@ -463,26 +462,35 @@ 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]
);
}
throw new Error(
`request failed with code: ${response.status}`
);
}
return response;
return response.text();
})
.then((r) => r.text())
.then(xml2js.parseStringPromise)
.then(parseTorznabResults)
)
Expand Down

0 comments on commit 956a617

Please sign in to comment.