-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enhanced results handling for Debrid services, Issue #22 fix, Correct…
…ly limit max results option (#25) * Fixed All-Debrid for season files and corrected maximum results implementation * Implement max results option in the search * Issue #22 fix * Fix for #22 fix * Correctly limit max results option * Fix for #22 fix * Enhanced results handling for Debrid services --------- Co-authored-by: Aran Leite <hyoretsu@gmail.com> Co-authored-by: aymene <aymene@Macbook-Pro-de-Aymene.local>
- Loading branch information
1 parent
c0afc83
commit a574322
Showing
7 changed files
with
308 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
node_modules | ||
pnpm-lock.yaml | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export async function getAvailabilityAD(magnet, debridApi) { | ||
const url = `https://api.alldebrid.com/v4/magnet/instant?agent=jackett&apikey=${debridApi}&magnets[]=${magnet}`; | ||
const response = await fetch(url); | ||
const json = await response.json(); | ||
if (json.status === "error") { | ||
return "error"; | ||
} | ||
const instant = json.data.magnets[0].instant; | ||
if (instant === true) { | ||
return true; | ||
} | ||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export async function getAvailabilityRD(hash, debridApi) { | ||
const url = `https://api.real-debrid.com/rest/1.0/torrents/instantAvailability/${hash}` | ||
const headers = { | ||
Authorization: `Bearer ${debridApi}`, | ||
}; | ||
const response = await fetch(url, { method: "GET", headers }); | ||
const json = await response.json(); | ||
const length = json[hash].length; | ||
if (length === 0) { | ||
return false; | ||
} | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,159 +1,14 @@ | ||
import { getMovieRDLink } from "../helpers/getMovieRDLink.js"; | ||
import { getMovieADLink } from "../helpers/getMovieADLink.js"; | ||
import { selectBiggestFileSeasonTorrent } from "../helpers/selectBiggestFileSeasonTorrent.js"; | ||
import { toHumanReadable } from "../helpers/toHumanReadable.js"; | ||
import getTorrentInfo from "./utils/getTorrentInfo.js"; | ||
import processXML from "./utils/processXML.js"; | ||
import jackettSearch from "./utils/jackettSearch.js"; | ||
|
||
async function getItemsFromUrl(url) { | ||
const res = await fetch(url); | ||
|
||
const items = await processXML(await res.text()); | ||
|
||
return items; | ||
} | ||
|
||
export default async function jackettSearch(debridApi, jackettHost, jackettApiKey, addonType, maxResults, searchQuery) { | ||
try { | ||
const { episode, name, season, type } = searchQuery; | ||
const isSeries = type === "series"; | ||
const torrentAddon = addonType === "torrent"; | ||
|
||
console.log("Searching on Jackett..."); | ||
console.log(`Will return ${!torrentAddon ? "Debrid link" : "Torrents"}.`); | ||
|
||
let searchUrl = `${jackettHost}/api/v2.0/indexers/all/results/torznab/api?apikey=${jackettApiKey}&cat=${ | ||
isSeries ? 5000 : 2000 | ||
}&q=${encodeURIComponent(name)}${isSeries ? `+S${season}E${episode}` : ""}`; | ||
|
||
const results = []; | ||
|
||
let items = await getItemsFromUrl(searchUrl); | ||
for (const [index, item] of items.entries()) { | ||
if (torrentAddon && index >= 5) { | ||
break; | ||
} | ||
|
||
console.log("Getting torrent info..."); | ||
const torrentInfo = await getTorrentInfo(item.link); | ||
console.log(`Torrent info: ${item.title}`); | ||
|
||
if (!torrentAddon) { | ||
if (addonType === "realdebrid") { | ||
console.log("Getting RD link..."); | ||
|
||
const downloadLink = await getMovieRDLink(torrentInfo.magnetLink, debridApi); | ||
results.push({ | ||
name: "Jackett Debrid", | ||
title: `${item.title}\r\n📁${toHumanReadable(item.size)}`, | ||
url: downloadLink, | ||
}); | ||
|
||
break; | ||
} else if (addonType === "alldebrid") { | ||
console.log("Getting AD link..."); | ||
|
||
const downloadLink = await getMovieADLink(torrentInfo.magnetLink, debridApi); | ||
if (downloadLink === "blocked") { | ||
console.log("Error: AllDebrid blocked for this IP. Please check your email."); | ||
return [{ name: "AllDebrid blocked", title: "Please check your email", url: "#" }]; | ||
} | ||
results.push({ | ||
name: "Jackett Debrid", | ||
title: `${item.title}\r\n📁${toHumanReadable(item.size)}`, | ||
url: downloadLink, | ||
}); | ||
|
||
break; | ||
} | ||
} | ||
|
||
torrentInfo.seeders = item.seeders; | ||
torrentInfo.title = `${item.title}\r\n👤${item.seeders} 📁${toHumanReadable(item.size)}`; | ||
if (!isSeries) { | ||
delete torrentInfo.fileIdx; | ||
} | ||
|
||
results.push(torrentInfo); | ||
console.log(`Added torrent to results: ${item.title}`); | ||
} | ||
|
||
// Try again without episode | ||
if (isSeries && results.length === 0) { | ||
if (torrentAddon) { | ||
console.log("No results found with season/episode. Trying without..."); | ||
console.log("Searching on Jackett..."); | ||
} | ||
|
||
searchUrl = `${jackettHost}/api/v2.0/indexers/all/results/torznab/api?apikey=${jackettApiKey}&cat=5000&q=${encodeURIComponent( | ||
searchQuery.name, | ||
)}+S${searchQuery.season}`; | ||
|
||
items = await getItemsFromUrl(searchUrl); | ||
for (const item of items) { | ||
const torrentInfo = await getTorrentInfo(item.link); | ||
|
||
if (!torrentAddon) { | ||
if (addonType === "realdebrid") { | ||
const url = await getMovieRDLink( | ||
torrentInfo.magnetLink, | ||
debridApi, | ||
`S${searchQuery.season}E${searchQuery.episode}`, | ||
); | ||
|
||
results.push({ | ||
name: "Jackett Debrid", | ||
title: `${item.title}\r\n📁${toHumanReadable(item.size)}`, | ||
url, | ||
}); | ||
|
||
break; | ||
|
||
} else if (addonType === "alldebrid") { | ||
const url = await getMovieADLink( | ||
torrentInfo.magnetLink, | ||
debridApi, | ||
`S${searchQuery.season}E${searchQuery.episode}`, | ||
); | ||
|
||
results.push({ | ||
name: "Jackett Debrid", | ||
title: `${item.title}\r\n📁${toHumanReadable(item.size)}`, | ||
url, | ||
}); | ||
|
||
break; | ||
} | ||
} | ||
|
||
console.log("Getting torrent info..."); | ||
console.log(`Torrent info: ${item.title}`); | ||
|
||
torrentInfo.seeders = item.seeders; | ||
torrentInfo.title = `${item.title}\r\n👤${item.seeders} 📁${toHumanReadable(item.size)}`; | ||
|
||
console.log("Determining episode file..."); | ||
torrentInfo.fileIdx = parseInt( | ||
selectBiggestFileSeasonTorrent(torrentInfo.files, `S${searchQuery.season}E${searchQuery.episode}`), | ||
10, | ||
); | ||
console.log("Episode file determined."); | ||
|
||
results.push(torrentInfo); | ||
console.log(`Added torrent to results: ${item.title}`); | ||
} | ||
} | ||
|
||
export default async function fetchResults(debridApi, jackettHost, jackettApiKey, addonType, maxResults, searchQuery) { | ||
let results = await jackettSearch(debridApi, jackettHost, jackettApiKey, addonType, maxResults, searchQuery); | ||
if (results.length === 0) { | ||
results = await jackettSearch(debridApi, jackettHost, jackettApiKey, addonType, 1, searchQuery); | ||
if (results.length === 0) { | ||
console.log("No results found."); | ||
|
||
results.push({ name: "Jackett", title: "No results found", url: "#" }); | ||
results = [{ name: "Jackett", title: "No results found", url: "#" }] | ||
} | ||
|
||
return results; | ||
} catch (e) { | ||
console.error(e); | ||
|
||
return [{ name: "Jackett", title: "No results found", url: "#" }]; | ||
} | ||
} | ||
|
||
return results; | ||
} |
Oops, something went wrong.