Skip to content

Commit

Permalink
Added Updating in case User starts the video
Browse files Browse the repository at this point in the history
- Will wait for episode runtime and then mark as watched.
  • Loading branch information
aliyss committed Aug 28, 2023
1 parent 42e9adb commit 2f1f082
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
30 changes: 23 additions & 7 deletions src/addon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,54 @@ 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;

return { meta };
});

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[] = [];

Expand Down
3 changes: 2 additions & 1 deletion src/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
};

Expand Down
5 changes: 3 additions & 2 deletions src/utils/stremio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<StremioCinemataMetaSeriesData>(
`https://v3-cinemeta.strem.io/meta/series/${id}.json`,
`https://v3-cinemeta.strem.io/meta/${type}/${id}.json`,
{
headers: {
"Content-Type": "application/json",
Expand All @@ -132,6 +132,7 @@ export interface StremioCinemataMetaSeriesData {
meta: {
id: string;
videos: { season: number; number: number }[];
runtime: string;
};
}

Expand Down
1 change: 1 addition & 0 deletions src/utils/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export async function backfillFromStremioToSimkl(
simklClient: SimklAPIClient,
) {
if (!simklSettings.backfill_shows && !simklSettings.backfill_movies) {
console.log("Skipping Backup");
return;
}

Expand Down

0 comments on commit 2f1f082

Please sign in to comment.