Skip to content

Commit

Permalink
fix url for search (#34)
Browse files Browse the repository at this point in the history
* add debug
  • Loading branch information
tsaridas authored Jan 27, 2024
1 parent bb57bca commit 5dc3572
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const defaultConfig = {

"addonName": process.env.ADDON_NAME || "Jackett",

"parseTorrentFiles": process.env.PARSE_TORRENT_FILES || false,
"dontParseTorrentFiles": process.env.DONT_PARSE_TORRENT_FILES || false,

"interval": parseInt(process.env.INTERVAL) || 500,

Expand Down
22 changes: 17 additions & 5 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ const helper = {
return quality
},

normalizeTitle: (title) => {
normalizeTitle: (torrent, info) => {
let name = '👤 11/2 💾 2 gb ⚙️ therarbg';
const title_list = title.split("\n");
let found = false;
const title_list = torrent.title.split("\n");
title_list.forEach(element => {
if (element.includes("👤")) {
name = element;
Expand All @@ -77,13 +78,24 @@ const helper = {
if (match) {
const digit = match[1];
if (!name.match(/👤 \d+\/\d+/)) {
name = name.replace(/👤 (\d+)/, `👤 ${Math.round(digit / 1.2)}/${Math.round(digit * 0.6)}`).toLowerCase();
const seeds = Math.round(digit / 1.1);
const leechers = Math.round(digit * 0.6);
name = name.replace(/👤 (\d+)/, `👤 ${seeds}/${leechers}`).toLowerCase();
torrent.title = info.name + ' ' + (info.season && info.episode ? ` ${helper.episodeTag(info.season, info.episode)}` : info.year) + '\n';
torrent.title += '\r\n' + name;
torrent.seeders = seeds;
found = true;
return;
}
}
return name

}
});
return name
if (!found) {
torrent.title = info.name + ' ' + (info.season && info.episode ? ` ${helper.episodeTag(info.season, info.episode)}` : info.year) + '\n';
torrent.title += '\r\n' + name;
torrent.seeders = 11;
}
},

extraTag: (name, searchQuery) => {
Expand Down
49 changes: 19 additions & 30 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ function streamFromParsed(tor, parsedTorrent, streamInfo, cb) {
stream.fileIdx = null;
}
let title = streamInfo.name + ' ' + (streamInfo.season && streamInfo.episode ? ` ${helper.episodeTag(streamInfo.season, streamInfo.episode)}` : streamInfo.year);
const subtitle = `👤 ${tor.seeders}/${tor.peers} 💾 ${helper.toHomanReadable(tor.size)} ⚙️ ${tor.from}`;
const subtitle = `👤 ${tor.seeders}/${tor.peers} 💾 ${helper.toHomanReadable(tor.size)} ⚙️ ${tor.from}`;

title += (title.indexOf('\n') > -1 ? '\r\n' : '\r\n\r\n') + subtitle;
const quality = helper.findQuality(tor.extraTag)
Expand All @@ -201,11 +201,11 @@ function streamFromParsed(tor, parsedTorrent, streamInfo, cb) {
stream.tag = quality
stream.type = streamInfo.type;
stream.infoHash = infoHash;
stream.seeders = tor.seeders;
stream.sources = trackers.map(x => { return "tracker:" + x; }).concat(["dht:" + infoHash]);
stream.title = title;
stream.seeders = tor.seeders;
stream.behaviorHints = {
bingieGroup: "Jackett|" + quality,
bingieGroup: "Jackett|" + quality + "|" + infoHash,
}
cb(stream);
}
Expand All @@ -228,7 +228,7 @@ async function addResults(info, streams, source, signal) {
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "en-US,en;q=0.9,el;q=0.8"
},
timeout: 3000,
timeout: config.responseTimeout,
signal: signal
});
const responseBody = response.data;
Expand All @@ -237,35 +237,24 @@ async function addResults(info, streams, source, signal) {
}

config.debug && console.log('Received ' + responseBody.streams.length + ' streams from ' + name)
const regex = /👤 (\d+) /

responseBody.streams.forEach(torrent => {
const newStream = {}
const quality = helper.findQuality(torrent.title);
torrent.name = torrent.name.replace(name, config.addonName);
torrent.tag = quality;
torrent.type = info.type;
torrent.infoHash = torrent.infoHash.toLowerCase();

const seedersMatch = torrent.title.match(regex)
if (seedersMatch && seedersMatch[1]) {
torrent.seeders = parseInt(seedersMatch[1]);
if (torrent.seeders < config.minimumSeeds) {
return;
}
} else {
console.error("Couldn't find seeders for : ", torrent.name);
}
newStream.fileIdx = torrent.fileIdx;
newStream.name = torrent.name.replace(name, config.addonName);
newStream.tag = quality;
newStream.type = info.type;
newStream.infoHash = torrent.infoHash.toLowerCase();
newStream.sources = global.TRACKERS.map(x => { return "tracker:" + x; }).concat(["dht:" + torrent.infoHash]);

torrent.sources = global.TRACKERS.map(x => { return "tracker:" + x; }).concat(["dht:" + torrent.infoHash]);
const stats = helper.normalizeTitle(torrent.title)
torrent.title = info.name + ' ' + (info.season && info.episode ? ` ${helper.episodeTag(info.season, info.episode)}` : info.year) + '\n';
torrent.title += '\r\n' + stats;
helper.normalizeTitle(torrent, info)

torrent.behaviorHints = {
bingieGroup: "Jackett|" + quality,
newStream.behaviorHints = {
bingieGroup: "Jackett|" + quality + "|" + newStream.infoHash,
}


streams.push(torrent);
streams.push(newStream);
config.debug && console.log('Adding addition source stream: ', torrent)
})
} catch (error) {
Expand Down Expand Up @@ -358,17 +347,17 @@ addon.get('/stream/:type/:id.json', async (req, res) => {
};

const processLinks = async (task) => {
if (requestSent) { // Check the flag before processing each task
if (requestSent) {
return;
}
inProgressCount++;
try {
config.debug && console.log("Processing link: ", task.link);
const response = await axios.get(task.link, {
timeout: 5000, // Set a timeout for the request in milliseconds
timeout: 5000, // we don't want to overdo it here and neither set something in config. Request should timeout anyway.
maxRedirects: 0, // Equivalent to 'redirect: 'manual'' in fetch
validateStatus: null,
cancelToken: signal.token, // Assuming 'signal' is an AbortController instance
cancelToken: signal.token,
responseType: 'arraybuffer', // Specify the response type as 'arraybuffer'
});

Expand Down
5 changes: 3 additions & 2 deletions src/jackett.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const search = async (query, signal, cb, end) => {
// Issue is that when they return a magnet we don't know which file to choose.
searchQuery += '%20' + helper.episodeTag(query.season, query.episode);
} else {
searchQuery += '%20' + (config.searchByYear ? query.year : '');
searchQuery += (config.searchByYear ? '%20' + query.year : '');
}
}

Expand Down Expand Up @@ -137,7 +137,7 @@ const search = async (query, signal, cb, end) => {
return;
}

if (!config.parseTorrentFiles && (!newObj.magneturl || (newObj.link && !newObj.link.startsWith("magnet:")))) {
if (config.dontParseTorrentFiles && (!newObj.magneturl || (newObj.link && !newObj.link.startsWith("magnet:")))) {
return;
}

Expand All @@ -162,6 +162,7 @@ const search = async (query, signal, cb, end) => {
newObj.extraTag = helper.extraTag(newObj.title, query.name);

if (helper.insertIntoSortedArray(sortedReults, newObj, 'seeders', config.maximumResults)) {
config.debug && console.log(newObj);
tempResults.push(newObj);
}
}
Expand Down

0 comments on commit 5dc3572

Please sign in to comment.