Skip to content

Commit

Permalink
Development (#29)
Browse files Browse the repository at this point in the history
* findQuality

* fix title

* format
  • Loading branch information
tsaridas authored Jan 26, 2024
1 parent a99ee38 commit 5ffa3f9
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 42 deletions.
37 changes: 11 additions & 26 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,15 @@ const helper = {
return bytes.toFixed(1) + " " + units[i];
},

isObject: (s) => {
return (s !== null && typeof s === 'object');
},

episodeTag: (season, episode) => {
return `S${('0' + season).slice(-2)}E${('0' + episode).slice(-2)}`;
},

simpleName: (name) => {

name = name.replace(/\.|_|-|–|\(|\)|\[|\]|:|,/g, ' ');
name = name.replace(/\s+/g, ' ');
name = name.replace(/'/g, '');
name = name.replace(/\\\\/g, '\\').replace(/\\\\'|\\'|\\\\"|\\"/g, '');

return name;
},

Expand All @@ -73,34 +67,25 @@ const helper = {
normalizeTitle: (title) => {
let name = null;
const title_list = title.split("\n");
name = title_list[0].replace(/\[.*?\]/g, '');
name = name.replace(/\(.*?\)/g, '');
title_list.forEach(element => {
let ending = null
if (element.includes("👤")) {
ending = helper.sanitizeStats(element)
if (!ending.includes("⚙️")) {
// If not, add it to the end
ending += " ⚙️ rarbg";
name = helper.sanitizeStats(element)
if (!name.includes("⚙️")) {
name += " ⚙️ rarbg";
}
const match = name.match(/👤 (\d+)/);
if (match) {
const digit = match[1];
if (!name.match(/👤 \d+\/\d+/)) {
name = name.replace(/👤 (\d+)/, `👤 ${digit}/${Math.round(digit * 0.6)}`).toLowerCase();
}
}
name += "\n" + ending
return name
}

});
return name
},

sanitizeStats: (inputString) => {
const match = inputString.match(/👤 (\d+)/);
if (match) {
const digit = match[1];
if (!inputString.match(/👤 \d+\/\d+/)) {
inputString = inputString.replace(/👤 (\d+)/, `👤 ${digit}/${Math.round(digit * 0.6)}`).toLowerCase();
}
}
return inputString;
},

extraTag: (name, searchQuery) => {
const parsedName = videoNameParser(name + '.mp4');
let extraTag = helper.simpleName(name);
Expand Down
47 changes: 31 additions & 16 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ function streamFromParsed(tor, parsedTorrent, streamInfo, cb) {
} else {
stream.fileIdx = null;
}
let title = tor.title || parsedTorrent.name;
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}`;

title += (title.indexOf('\n') > -1 ? '\r\n' : '\r\n\r\n') + subtitle;
Expand Down Expand Up @@ -206,15 +206,16 @@ function streamFromParsed(tor, parsedTorrent, streamInfo, cb) {
cb(stream);
}

async function addResults(req, streams, source, signal) {
async function addResults(info, streams, source, signal) {

const [url, name] = source.split("||").length === 2 ? source.split("||") : [null, null];
if (!url && !name) {
console.error("Additional Sources not configured correctly.")
return;
}

try {
const streamUrl = url + req.params.type + '/' + req.params.id + '.json'
const streamUrl = url + info.type + '/' + info.imdbId + '.json'
config.debug && console.log('Additional source url is :', streamUrl)
const response = await axios.get(streamUrl, {
headers: {
Expand All @@ -228,27 +229,39 @@ async function addResults(req, streams, source, signal) {
});
const responseBody = response.data;
if (!responseBody || !responseBody.streams || responseBody.streams.length === 0) {
throw new Error(`Could not get addition source stream with status code: ${response.status}`)
throw new Error(`Could not any additional streams: ${response.status}`)
}

config.debug && console.log('Got ' + responseBody.streams.length + ' from additional source.')
const regex = /👤 (\d+) /
responseBody.streams.forEach(torrent => {
torrent.name = torrent.name.replace(name, config.addonName)

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])
}
torrent.title = helper.normalizeTitle(torrent.title);
if (torrent.behaviorHints && torrent.behaviorHints.bingeGroup) {
torrent.behaviorHints.bingeGroup = "Jackett|" + helper.findQuality(torrent.behaviorHints.bingeGroup)
torrent.seeders = parseInt(seedersMatch[1]);
} else {
torrent.seeders = 5;
}
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;
const quality = helper.findQuality(torrent.behaviorHints.bingeGroup);
torrent.behaviorHints = {
bingieGroup: "Jackett|" + quality,
}


streams.push(torrent);
config.debug && console.log('Adding addition source stream: ', torrent)
})
} catch (error) {
console.error('Error finding addition source streams: ', error.message)
config.debug && console.error('Error finding addition source streams: ', error.message)
}
}

Expand Down Expand Up @@ -278,11 +291,7 @@ addon.get('/stream/:type/:id.json', async (req, res) => {

extractVideoInf(req, streamInfo);

if (config.additionalSources) {
config.additionalSources.forEach(source => {
addResults(req, streams, source, signal);
});
}


try {
await getConemataInfo(streamInfo, signal);
Expand All @@ -291,6 +300,12 @@ addon.get('/stream/:type/:id.json', async (req, res) => {
return respond(res, { streams: [] });
}

if (config.additionalSources) {
config.additionalSources.forEach(source => {
addResults(streamInfo, streams, source, signal);
});
}

console.log(`Q / imdbiID: ${streamInfo.imdbId} / title: ${streamInfo.name} / type: ${streamInfo.type} / year: ${streamInfo.year}` +
(streamInfo.season && streamInfo.episode ? ` / season: ${streamInfo.season} / episode: ${streamInfo.episode}` : '') +
'.');
Expand Down

0 comments on commit 5ffa3f9

Please sign in to comment.