remove today from catalog addon genres

This commit is contained in:
TheBeastLT
2022-06-18 16:33:08 +03:00
parent ae077dda8c
commit e2e4744dc0
3 changed files with 23 additions and 26 deletions

View File

@@ -6,7 +6,6 @@ const { getMetas } = require('./lib/metadata');
const { cacheWrapCatalog, cacheWrapIds } = require('./lib/cache'); const { cacheWrapCatalog, cacheWrapIds } = require('./lib/cache');
const repository = require('./lib/repository'); const repository = require('./lib/repository');
const CACHE_MAX_AGE = process.env.CACHE_MAX_AGE || 4 * 60 * 60; // 4 hours in seconds 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_REVALIDATE_AGE = 4 * 60 * 60; // 4 hours
const STALE_ERROR_AGE = 7 * 24 * 60 * 60; // 7 days const STALE_ERROR_AGE = 7 * 24 * 60 * 60; // 7 days
@@ -22,7 +21,7 @@ const limiter = new Bottleneck({
builder.defineCatalogHandler((args) => { builder.defineCatalogHandler((args) => {
const offset = parseInt(args.extra.skip || '0', 10); 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); const catalog = manifest.catalogs.find(c => c.id === args.id);
console.log(`Incoming catalog ${args.id} request with genre=${genre} and skip=${offset}`) console.log(`Incoming catalog ${args.id} request with genre=${genre} and skip=${offset}`)
if (!catalog) { if (!catalog) {
@@ -44,7 +43,7 @@ async function getCursor(catalog, genre, offset) {
if (offset === 0) { if (offset === 0) {
return undefined; 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")) return cacheWrapCatalog(previousCacheKey, () => Promise.reject("cursor not found"))
.then(metas => metas[metas.length - 1]) .then(metas => metas[metas.length - 1])
.then(meta => meta.id.replace('kitsu:', '')) .then(meta => meta.id.replace('kitsu:', ''))
@@ -54,7 +53,7 @@ async function getCatalog(catalog, genre, offset) {
const cursor = await getCursor(catalog, genre, offset) const cursor = await getCursor(catalog, genre, offset)
const startDate = getStartDate(genre)?.toISOString(); const startDate = getStartDate(genre)?.toISOString();
const endDate = getEndDate(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)) return cacheWrapIds(cacheKey, () => repository.getIds(catalog.type, startDate, endDate))
.then(ids => ids.slice(ids.indexOf(cursor) + 1)) .then(ids => ids.slice(ids.indexOf(cursor) + 1))
@@ -64,26 +63,28 @@ async function getCatalog(catalog, genre, offset) {
function getStartDate(genre) { function getStartDate(genre) {
switch (genre) { switch (genre) {
case genres[0]: return moment().utc().startOf('day'); case genres[0]: return moment().utc().subtract(1, 'day').startOf('day');
case genres[1]: return moment().utc().subtract(1, 'day').startOf('day'); case genres[1]: return moment().utc().startOf('isoWeek');
case genres[2]: return moment().utc().startOf('isoWeek'); case genres[2]: return moment().utc().subtract(7, 'day').startOf('isoWeek');
case genres[3]: return moment().utc().subtract(7, 'day').startOf('isoWeek'); case genres[3]: return moment().utc().startOf('month');
case genres[4]: return moment().utc().startOf('month'); case genres[4]: return moment().utc().subtract(30, 'day').startOf('month');
case genres[5]: return moment().utc().subtract(30, 'day').startOf('month'); default: return moment().utc().subtract(30, 'day').startOf('day');
default: return undefined;
} }
} }
function getEndDate( genre) { function getEndDate(genre) {
switch (genre) { switch (genre) {
case genres[0]: return moment().utc(); case genres[0]: return moment().utc().subtract(1, 'day').endOf('day');
case genres[1]: return moment().utc().subtract(1, 'day').endOf('day'); case genres[1]: return moment().utc().endOf('isoWeek');
case genres[2]: return moment().utc().endOf('isoWeek'); case genres[2]: return moment().utc().subtract(7, 'day').endOf('isoWeek');
case genres[3]: return moment().utc().subtract(7, 'day').endOf('isoWeek'); case genres[3]: return moment().utc().endOf('month');
case genres[4]: return moment().utc().endOf('month'); case genres[4]: return moment().utc().subtract(30, 'day').endOf('month');
case genres[5]: return moment().utc().subtract(30, 'day').endOf('month'); default: return moment().utc().subtract(1, 'day').endOf('day');
default: return undefined;
} }
} }
function dateKey() {
return moment().format('YYYY-MM-DD')
}
module.exports = builder.getInterface(); module.exports = builder.getInterface();

View File

@@ -1,7 +1,7 @@
const cacheManager = require('cache-manager'); const cacheManager = require('cache-manager');
const mangodbStore = require('cache-manager-mongodb'); 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; const MONGO_URI = process.env.MONGODB_URI;

View File

@@ -1,7 +1,6 @@
const { Type } = require('../../addon/lib/types'); const { Type } = require('../../addon/lib/types');
const genres = [ const genres = [
'Today',
'Yesterday', 'Yesterday',
'This Week', 'This Week',
'Last Week', 'Last Week',
@@ -14,8 +13,8 @@ function createManifest() {
return { return {
id: 'com.stremio.torrentio.catalog.addon', id: 'com.stremio.torrentio.catalog.addon',
version: '1.0.0', version: '1.0.0',
name: 'Torrentio Catalogs', name: 'Torrent Catalogs',
description: 'Provides catalogs for movies/series/anime based on top seeded torrents', 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`, logo: `https://i.ibb.co/w4BnkC9/GwxAcDV.png`,
background: `https://i.ibb.co/VtSfFP9/t8wVwcg.jpg`, background: `https://i.ibb.co/VtSfFP9/t8wVwcg.jpg`,
types: [Type.MOVIE, Type.SERIES, Type.ANIME], types: [Type.MOVIE, Type.SERIES, Type.ANIME],
@@ -25,7 +24,6 @@ function createManifest() {
id: 'top-movies', id: 'top-movies',
type: Type.MOVIE, type: Type.MOVIE,
name: "Top seeded", name: "Top seeded",
pageSize: 20,
extra: [{ name: 'genre', options: genres }, { name: 'skip' }], extra: [{ name: 'genre', options: genres }, { name: 'skip' }],
genres: genres genres: genres
}, },
@@ -33,7 +31,6 @@ function createManifest() {
id: 'top-series', id: 'top-series',
type: Type.SERIES, type: Type.SERIES,
name: "Top seeded", name: "Top seeded",
pageSize: 20,
extra: [{ name: 'genre', options: genres }, { name: 'skip' }], extra: [{ name: 'genre', options: genres }, { name: 'skip' }],
genres: genres genres: genres
}, },
@@ -41,7 +38,6 @@ function createManifest() {
id: 'top-anime', id: 'top-anime',
type: Type.ANIME, type: Type.ANIME,
name: "Top seeded", name: "Top seeded",
pageSize: 20,
extra: [{ name: 'genre', options: genres }, { name: 'skip' }], extra: [{ name: 'genre', options: genres }, { name: 'skip' }],
genres: genres genres: genres
} }