From 2f1f0828ded70f9203576c08e6f10159eedf00f9 Mon Sep 17 00:00:00 2001 From: aliyss Date: Mon, 28 Aug 2023 22:34:32 +0200 Subject: [PATCH] Added Updating in case User starts the video - Will wait for episode runtime and then mark as watched. --- src/addon.ts | 30 +++++++++++++++++++++++------- src/manifest.ts | 3 ++- src/utils/stremio.ts | 5 +++-- src/utils/sync.ts | 1 + 4 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/addon.ts b/src/addon.ts index 54334d7..1c18ad7 100644 --- a/src/addon.ts +++ b/src/addon.ts @@ -10,24 +10,26 @@ import { SimklAPIClient } from "./utils/simkl"; import { backfillFromStremioToSimkl } from "./utils/sync"; const builder = new addonBuilder(manifest); +const stremioClient = new StremioAPIClient(); +const simklClient = new SimklAPIClient(); (async () => { - const stremioClient = await new StremioAPIClient().init(); - const simklClient = await new SimklAPIClient().init(); + await stremioClient.init(); + await simklClient.init(); await backfillFromStremioToSimkl(stremioClient, simklClient); })(); builder.defineCatalogHandler(async (args) => { - console.log(args); + // console.log(args, "catalog"); let metas: MetaPreview[] = []; return { metas }; }); -builder.defineMetaHandler(async ({ id, type }) => { - console.log(id, type); +builder.defineMetaHandler(async (args) => { + // console.log(args, "meta"); let meta: MetaDetail = null as unknown as MetaDetail; @@ -35,13 +37,27 @@ builder.defineMetaHandler(async ({ id, type }) => { }); builder.defineSubtitlesHandler(async (args) => { - console.log(args); + // console.log(args, "subtitles"); + + let info = await StremioAPIClient.getCinemetaMeta( + args.id.split(":")[0], + args.type, + ); + + let timeout = 0; + if (info?.meta.runtime) { + timeout = parseInt(info.meta.runtime.split(" ")[0]) * 60 * 1000; + } + + setTimeout(async function () { + await backfillFromStremioToSimkl(stremioClient, simklClient); + }, timeout); return Promise.resolve({ subtitles: [] }); }); builder.defineStreamHandler(async ({ id, type }) => { - console.log(id, type, "here"); + // console.log(id, type, "stream"); let streams: Stream[] = []; diff --git a/src/manifest.ts b/src/manifest.ts index de9488d..3b22fb9 100644 --- a/src/manifest.ts +++ b/src/manifest.ts @@ -10,12 +10,13 @@ const manifest: manifest = { logo: "https://avatars.githubusercontent.com/u/9755912?s=200&v=4", background: "", catalogs: [], + // @ts-ignore resources: ["catalog", "meta", "stream", "subtitles"], types: ["series", "movie"], behaviorHints: { // @ts-ignore configurable: true, - configurationRequired: true, + configurationRequired: false, }, }; diff --git a/src/utils/stremio.ts b/src/utils/stremio.ts index 37c7fe6..caad6dd 100644 --- a/src/utils/stremio.ts +++ b/src/utils/stremio.ts @@ -111,10 +111,10 @@ export class StremioAPIClient { return this.library; } - static async getCinemetaMeta(id: string) { + static async getCinemetaMeta(id: string, type = "series") { try { const { data } = await axios.get( - `https://v3-cinemeta.strem.io/meta/series/${id}.json`, + `https://v3-cinemeta.strem.io/meta/${type}/${id}.json`, { headers: { "Content-Type": "application/json", @@ -132,6 +132,7 @@ export interface StremioCinemataMetaSeriesData { meta: { id: string; videos: { season: number; number: number }[]; + runtime: string; }; } diff --git a/src/utils/sync.ts b/src/utils/sync.ts index 60cd34d..4d8abe8 100644 --- a/src/utils/sync.ts +++ b/src/utils/sync.ts @@ -113,6 +113,7 @@ export async function backfillFromStremioToSimkl( simklClient: SimklAPIClient, ) { if (!simklSettings.backfill_shows && !simklSettings.backfill_movies) { + console.log("Skipping Backup"); return; }