From e2e4744dc038f4e99ffe38a6001e80f12ce0a679 Mon Sep 17 00:00:00 2001 From: TheBeastLT Date: Sat, 18 Jun 2022 16:33:08 +0300 Subject: [PATCH] remove today from catalog addon genres --- catalogs/addon.js | 39 ++++++++++++++++++++------------------- catalogs/lib/cache.js | 2 +- catalogs/lib/manifest.js | 8 ++------ 3 files changed, 23 insertions(+), 26 deletions(-) diff --git a/catalogs/addon.js b/catalogs/addon.js index 3fa40c5..e531dd6 100644 --- a/catalogs/addon.js +++ b/catalogs/addon.js @@ -6,7 +6,6 @@ const { getMetas } = require('./lib/metadata'); const { cacheWrapCatalog, cacheWrapIds } = require('./lib/cache'); const repository = require('./lib/repository'); - const CACHE_MAX_AGE = process.env.CACHE_MAX_AGE || 4 * 60 * 60; // 4 hours in seconds const STALE_REVALIDATE_AGE = 4 * 60 * 60; // 4 hours const STALE_ERROR_AGE = 7 * 24 * 60 * 60; // 7 days @@ -22,7 +21,7 @@ const limiter = new Bottleneck({ builder.defineCatalogHandler((args) => { const offset = parseInt(args.extra.skip || '0', 10); - const genre = args.extra.genre || genres[5]; + const genre = args.extra.genre || 'default'; const catalog = manifest.catalogs.find(c => c.id === args.id); console.log(`Incoming catalog ${args.id} request with genre=${genre} and skip=${offset}`) if (!catalog) { @@ -44,7 +43,7 @@ async function getCursor(catalog, genre, offset) { if (offset === 0) { return undefined; } - const previousCacheKey = `${catalog.id}|${genre}|${offset - catalog.pageSize}`; + const previousCacheKey = `${catalog.id}|${genre}|${dateKey()}|${offset - catalog.pageSize}`; return cacheWrapCatalog(previousCacheKey, () => Promise.reject("cursor not found")) .then(metas => metas[metas.length - 1]) .then(meta => meta.id.replace('kitsu:', '')) @@ -54,7 +53,7 @@ async function getCatalog(catalog, genre, offset) { const cursor = await getCursor(catalog, genre, offset) const startDate = getStartDate(genre)?.toISOString(); const endDate = getEndDate(genre)?.toISOString(); - const cacheKey = `${catalog.id}|${genre}` + const cacheKey = `${catalog.id}|${genre}||${dateKey()}` return cacheWrapIds(cacheKey, () => repository.getIds(catalog.type, startDate, endDate)) .then(ids => ids.slice(ids.indexOf(cursor) + 1)) @@ -64,26 +63,28 @@ async function getCatalog(catalog, genre, offset) { function getStartDate(genre) { switch (genre) { - case genres[0]: return moment().utc().startOf('day'); - case genres[1]: return moment().utc().subtract(1, 'day').startOf('day'); - case genres[2]: return moment().utc().startOf('isoWeek'); - case genres[3]: return moment().utc().subtract(7, 'day').startOf('isoWeek'); - case genres[4]: return moment().utc().startOf('month'); - case genres[5]: return moment().utc().subtract(30, 'day').startOf('month'); - default: return undefined; + case genres[0]: return moment().utc().subtract(1, 'day').startOf('day'); + case genres[1]: return moment().utc().startOf('isoWeek'); + case genres[2]: return moment().utc().subtract(7, 'day').startOf('isoWeek'); + case genres[3]: return moment().utc().startOf('month'); + case genres[4]: return moment().utc().subtract(30, 'day').startOf('month'); + default: return moment().utc().subtract(30, 'day').startOf('day'); } } -function getEndDate( genre) { +function getEndDate(genre) { switch (genre) { - case genres[0]: return moment().utc(); - case genres[1]: return moment().utc().subtract(1, 'day').endOf('day'); - case genres[2]: return moment().utc().endOf('isoWeek'); - case genres[3]: return moment().utc().subtract(7, 'day').endOf('isoWeek'); - case genres[4]: return moment().utc().endOf('month'); - case genres[5]: return moment().utc().subtract(30, 'day').endOf('month'); - default: return undefined; + case genres[0]: return moment().utc().subtract(1, 'day').endOf('day'); + case genres[1]: return moment().utc().endOf('isoWeek'); + case genres[2]: return moment().utc().subtract(7, 'day').endOf('isoWeek'); + case genres[3]: return moment().utc().endOf('month'); + case genres[4]: return moment().utc().subtract(30, 'day').endOf('month'); + default: return moment().utc().subtract(1, 'day').endOf('day'); } } +function dateKey() { + return moment().format('YYYY-MM-DD') +} + module.exports = builder.getInterface(); diff --git a/catalogs/lib/cache.js b/catalogs/lib/cache.js index 3dcafb9..8672db3 100644 --- a/catalogs/lib/cache.js +++ b/catalogs/lib/cache.js @@ -1,7 +1,7 @@ const cacheManager = require('cache-manager'); const mangodbStore = require('cache-manager-mongodb'); -const CATALOG_TTL = process.env.STREAM_TTL || 12 * 60 * 60; // 12 hours +const CATALOG_TTL = process.env.STREAM_TTL || 24 * 60 * 60; // 24 hours const MONGO_URI = process.env.MONGODB_URI; diff --git a/catalogs/lib/manifest.js b/catalogs/lib/manifest.js index 2df15ff..d5ba60b 100644 --- a/catalogs/lib/manifest.js +++ b/catalogs/lib/manifest.js @@ -1,7 +1,6 @@ const { Type } = require('../../addon/lib/types'); const genres = [ - 'Today', 'Yesterday', 'This Week', 'Last Week', @@ -14,8 +13,8 @@ function createManifest() { return { id: 'com.stremio.torrentio.catalog.addon', version: '1.0.0', - name: 'Torrentio Catalogs', - description: 'Provides catalogs for movies/series/anime based on top seeded torrents', + name: 'Torrent Catalogs', + description: 'Provides catalogs for movies/series/anime based on top seeded torrents. Requires Kitsu addon for anime.', logo: `https://i.ibb.co/w4BnkC9/GwxAcDV.png`, background: `https://i.ibb.co/VtSfFP9/t8wVwcg.jpg`, types: [Type.MOVIE, Type.SERIES, Type.ANIME], @@ -25,7 +24,6 @@ function createManifest() { id: 'top-movies', type: Type.MOVIE, name: "Top seeded", - pageSize: 20, extra: [{ name: 'genre', options: genres }, { name: 'skip' }], genres: genres }, @@ -33,7 +31,6 @@ function createManifest() { id: 'top-series', type: Type.SERIES, name: "Top seeded", - pageSize: 20, extra: [{ name: 'genre', options: genres }, { name: 'skip' }], genres: genres }, @@ -41,7 +38,6 @@ function createManifest() { id: 'top-anime', type: Type.ANIME, name: "Top seeded", - pageSize: 20, extra: [{ name: 'genre', options: genres }, { name: 'skip' }], genres: genres }