Skip to content

Commit

Permalink
Fix jackett cache
Browse files Browse the repository at this point in the history
  • Loading branch information
arvida42 committed Mar 21, 2024
1 parent 26efed5 commit 9fb1ac9
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/lib/jackett.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@ export const CATEGORY = {
export async function searchMovieTorrents({indexer, name, year}){

indexer = indexer || 'all';
let items = await cache.get(`jackettItems:2:movie:${indexer}:${name}:${year}`);
const cacheKey = `jackettItems:2:movie:${indexer}:${name}:${year}`;
let items = await cache.get(cacheKey);

if(!items){
const res = await jackettApi(
`/api/v2.0/indexers/${indexer}/results/torznab/api`,
{t: 'movie',q: name, year: year}
);
items = res?.rss?.channel?.item || [];
cache.set(`jackettItems:movie:${indexer}:${name}:${year}`, items, {ttl: items.length > 0 ? 3600*36 : 60});
cache.set(cacheKey, items, {ttl: items.length > 0 ? 3600*36 : 60});
}

return normalizeItems(items);
Expand All @@ -30,15 +31,16 @@ export async function searchMovieTorrents({indexer, name, year}){
export async function searchSeasonTorrents({indexer, name, year, season}){

indexer = indexer || 'all';
let items = await cache.get(`jackettItems:2:season:${indexer}:${name}:${year}:${season}`);
const cacheKey = `jackettItems:2:season:${indexer}:${name}:${year}:${season}`;
let items = await cache.get(cacheKey);

if(!items){
const res = await jackettApi(
`/api/v2.0/indexers/${indexer}/results/torznab/api`,
{t: 'tvsearch',q: `${name} S${numberPad(season)}`}
);
items = res?.rss?.channel?.item || [];
cache.set(`jackettItems:season:${indexer}:${name}:${year}:${season}`, items, {ttl: items.length > 0 ? 3600*36 : 60});
cache.set(cacheKey, items, {ttl: items.length > 0 ? 3600*36 : 60});
}

return normalizeItems(items);
Expand All @@ -48,15 +50,16 @@ export async function searchSeasonTorrents({indexer, name, year, season}){
export async function searchEpisodeTorrents({indexer, name, year, season, episode}){

indexer = indexer || 'all';
let items = await cache.get(`jackettItems:2:episode:${indexer}:${name}:${year}:${season}:${episode}`);
const cacheKey = `jackettItems:2:episode:${indexer}:${name}:${year}:${season}:${episode}`;
let items = await cache.get(cacheKey);

if(!items){
const res = await jackettApi(
`/api/v2.0/indexers/${indexer}/results/torznab/api`,
{t: 'tvsearch',q: `${name} S${numberPad(season)}E${numberPad(episode)}`}
);
items = res?.rss?.channel?.item || [];
cache.set(`jackettItems:episode:${indexer}:${name}:${year}:${season}:${episode}`, items, {ttl: items.length > 0 ? 3600*36 : 60});
cache.set(cacheKey, items, {ttl: items.length > 0 ? 3600*36 : 60});
}

return normalizeItems(items);
Expand Down

0 comments on commit 9fb1ac9

Please sign in to comment.