Skip to content

Commit

Permalink
search by year (#33)
Browse files Browse the repository at this point in the history
* search by year

* searchbyname

* DONT_PARSE_TORRENT_FILES
  • Loading branch information
tsaridas authored Jan 27, 2024
1 parent 6ec7f9e commit b5baf07
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ The below options can be set as an evironment variable.
| `ADDON_NAME` | 'Jackett' | `MyJacketAddon` | The name of the addon that will show in stremio. |
| `JACKETT_RTIMEOUT` | 8000 | `20000` | Jackett http read timeout in millisecond. Don't set these higher than the RESPONSE_TIMEOUT. |
| `JACKETT_OTIMEOUT` | 3000 | `20000` | Jackett http open timeout in millisecond. This is how long it takes to open a tcp connection to jackett. Increase if your jackett server is far away from the addon.|
| `PARSE_TORRENT_FILES` | false | `true` | Parsing torrent files ( not magnets) takes time and is slow. This is disabled by default. **If enabled you will see more results depending on your indexer**. |
| `DONT_PARSE_TORRENT_FILES` | false | `true` | Parsing torrent files ( not magnets) takes time and is slow. This is disabled by default. **If enabled you will see less results depending on your indexer**. |
| `DOWNLOAD_TORRENT_QUEUE` | 10 | `100` | Because external http downloads go through Jackett doing many downloads at the same time might cause some DDOS so I setup a queue for this. |
| `RESPONSE_TIMEOUT` | 8000 | `12000` | This will timeout any queries to jackett after this given value in millisecond. The higher the most result you will get from slow indexers. |
| `PORT` | 7000 | `8888` | The port which the Addon service will run on. |
Expand All @@ -54,6 +54,7 @@ The below options can be set as an evironment variable.
| `MAX_SIZE` | 5GB | `5GB` | Maximum size of the results we want to receive. Value is in Bytes. Default is 10GB. Supported formats: B/KB/MB/GB/TB . |
| `DEBUG` | false | `true` | Spams your terminal with info. |
| `SEARCH_BY_TYPE` | false | `true` | By enabled this, it will search by movie or tvshow instead of default free search. |
| `SEARCH_BY_YEAR` | false | `true` | By enabled this, it will add year of the movie in the search. I added this because you get better results with some types but might get wrong movie for others like sequels that have the same name but different year. |
| `INTERVAL` | 500 | `100` | How often to check in miliseconds if we should return results based on user's timeout. |
| `ADD_BEST_TRACKERS` | false | `true` | We download a list of best trackers from [Best Trackers](https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_best.txt) and add them to all torrents found |
| `ADD_RUSSIAN_TRACKERS` | false | `true` | We add some Russian trackers. Check trackers.js for more info.|
Expand Down
2 changes: 2 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const defaultConfig = {

"debug": process.env.DEBUG || false,

"searchByYear": process.env.SEARCH_BY_YEAR || false,

"searchByType": process.env.SEARCH_BY_TYPE || false,

"responseTimeout": parseInt(process.env.RESPONSE_TIMEOUT) || 8000,
Expand Down
6 changes: 3 additions & 3 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,19 @@ const helper = {
},

normalizeTitle: (title) => {
let name = '👤 11/2 💾 2 gb ⚙️ rarbg';
let name = '👤 11/2 💾 2 gb ⚙️ therarbg';
const title_list = title.split("\n");
title_list.forEach(element => {
if (element.includes("👤")) {
name = element;
if (!name.includes("⚙️")) {
name += " ⚙️ rarbg";
name += " ⚙️ therarbg";
}
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 = name.replace(/👤 (\d+)/, `👤 ${Math.round(digit / 1.2)}/${Math.round(digit * 0.6)}`).toLowerCase();
}
}
return name
Expand Down
12 changes: 8 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ function streamFromParsed(tor, parsedTorrent, streamInfo, cb) {
} else {
let regEx = null;
if (streamInfo.type === 'movie') {
regEx = new RegExp(`${streamInfo.name.split(' ').join('.*')}.*${streamInfo.year}.*`, 'i');
regEx = new RegExp(`${streamInfo.name.split(' ').join('.*')}.*${config.searchByYear && streamInfo.year ? streamInfo.year : ''}.*`, 'i');
} else {
regEx = new RegExp(`${streamInfo.name.split(' ').join('.*')}.*${helper.episodeTag(streamInfo.season, streamInfo.episode)}.*`, 'i');
}
Expand Down Expand Up @@ -197,7 +197,7 @@ function streamFromParsed(tor, parsedTorrent, streamInfo, cb) {
}
}

stream.name = config.addonName + " " + quality;
stream.name = config.addonName + "\n" + quality;
stream.tag = quality
stream.type = streamInfo.type;
stream.infoHash = infoHash;
Expand Down Expand Up @@ -236,7 +236,7 @@ async function addResults(info, streams, source, signal) {
throw new Error(`Could not any additional streams: ${response.status}`)
}

config.debug && console.log('Received ' + responseBody.streams.length + ' streams from an additional source.')
config.debug && console.log('Received ' + responseBody.streams.length + ' streams from ' + name)
const regex = /👤 (\d+) /
responseBody.streams.forEach(torrent => {
const quality = helper.findQuality(torrent.title);
Expand All @@ -248,9 +248,13 @@ async function addResults(info, streams, source, signal) {
const seedersMatch = torrent.title.match(regex)
if (seedersMatch && seedersMatch[1]) {
torrent.seeders = parseInt(seedersMatch[1]);
if (torrent.seeders < config.minimumSeeds) {
return;
}
} else {
torrent.seeders = 5;
console.error("Couldn't find seeders for : ", torrent.name);
}

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';
Expand Down
4 changes: 2 additions & 2 deletions src/jackett.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const search = async (query, signal, cb, end) => {
if (query.season && query.episode) {
searchQuery = '&t=' + searchType + '&q=' + simpleName + '&season=' + query.season + '&ep=' + query.episode;
} else {
const year = (query.year) ? '&year=' + query.year : '';
const year = (config.searchByYear && query.year) ? '&year=' + query.year : '';
searchQuery = '&t=' + searchType + '&q=' + simpleName + year;
}
} else {
Expand All @@ -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' + query.year;
searchQuery += '%20' + (config.searchByYear ? query.year : '');
}
}

Expand Down

0 comments on commit b5baf07

Please sign in to comment.