From dec44c2469a449663939270019b8601b1f9652ae Mon Sep 17 00:00:00 2001 From: aliyss Date: Mon, 28 Aug 2023 23:04:24 +0200 Subject: [PATCH] Updated some logic also now works for auto episodes --- README.org | 7 +++-- src/addon.ts | 2 +- src/utils/environment.ts | 6 ++-- src/utils/sync.ts | 66 +++++++++++++++++++++++++--------------- 4 files changed, 51 insertions(+), 30 deletions(-) diff --git a/README.org b/README.org index 0596478..2048f09 100644 --- a/README.org +++ b/README.org @@ -54,9 +54,10 @@ STREMIO_AUTHKEY= # Not Necessary will be done automatically SIMKL_CLIENTID= # Now Necessary, due to the CLIENTID hitting it's rate limit SIMKL_ACCESSTOKEN= # Not Necessary will be done automatically -# If these are enabled it will at minimum sync the watch history -SIMKL_BACKFILL_SHOWS=true # Option if it should sync shows to simkl on boot -SIMKL_BACKFILL_MOVIES=true # Option if it should sync movies to simkl on boot +SIMKL_BACKFILL_LISTSHOWS=true # Option if it should sync shows to simkl list on boot +SIMKL_BACKFILL_LISTMOVIES=true # Option if it should sync movies to simkl list on boot +SIMKL_BACKFILL_WATCHHISTORYSHOWS=true # Option if it should sync shows to simkl history on boot +SIMKL_BACKFILL_WATCHHISTORYMOVIES=true # Option if it should sync movies to simkl history on boot # If this is enabled it will add shows and movies to the list, but also move them around on simkl using stremio as the leader. SIMKL_BACKFILL_MODIFYLIST=false diff --git a/src/addon.ts b/src/addon.ts index 1c18ad7..fc837bd 100644 --- a/src/addon.ts +++ b/src/addon.ts @@ -50,7 +50,7 @@ builder.defineSubtitlesHandler(async (args) => { } setTimeout(async function () { - await backfillFromStremioToSimkl(stremioClient, simklClient); + await backfillFromStremioToSimkl(stremioClient, simklClient, true); }, timeout); return Promise.resolve({ subtitles: [] }); diff --git a/src/utils/environment.ts b/src/utils/environment.ts index 9b7a281..106f9b2 100644 --- a/src/utils/environment.ts +++ b/src/utils/environment.ts @@ -13,9 +13,11 @@ STREMIO_AUTHKEY= SIMKL_CLIENTID=${SIMKL_CLIENTID} SIMKL_ACCESSTOKEN= -SIMKL_BACKFILL_SHOWS=true -SIMKL_BACKFILL_MOVIES=true +SIMKL_BACKFILL_LISTSHOWS=false +SIMKL_BACKFILL_LISTMOVIES=false SIMKL_BACKFILL_MODIFYLIST=false +SIMKL_BACKFILL_WATCHHISTORYSHOWS=true +SIMKL_BACKFILL_WATCHHISTORYMOVIES=true SIMKL_BACKFILL_LASTEPISODEFILL=false `; try { diff --git a/src/utils/sync.ts b/src/utils/sync.ts index 4d8abe8..82f4d53 100644 --- a/src/utils/sync.ts +++ b/src/utils/sync.ts @@ -9,8 +9,12 @@ import { SimklAPIClient, SimklLibraryObject } from "./simkl"; import { StremioAPIClient, StremioLibraryObject } from "./stremio"; const simklSettings = { - backfill_shows: getEnvValue("SIMKL_BACKFILL_SHOWS") === "true", - backfill_movies: getEnvValue("SIMKL_BACKFILL_MOVIES") === "true", + backfill_listshows: getEnvValue("SIMKL_BACKFILL_LISTSHOWS") === "true", + backfill_listmovies: getEnvValue("SIMKL_BACKFILL_LISTMOVIES") === "true", + backfill_watchhistoryshows: + getEnvValue("SIMKL_BACKFILL_WATCHHISTORYSHOWS") === "true", + backfill_watchhistorymovies: + getEnvValue("SIMKL_BACKFILL_WATCHHISTORYMOVIES") === "true", backfill_modifylist: getEnvValue("SIMKL_BACKFILL_MODIFYLIST") === "true", }; @@ -54,7 +58,7 @@ function stremioToSimklListSyncLogic( if (!value.stremio) { return; } - if (simklSettings.backfill_movies && value.stremio.type === "movie") { + if (simklSettings.backfill_listmovies && value.stremio.type === "movie") { if (!value.simkl) { return true; } @@ -65,7 +69,7 @@ function stremioToSimklListSyncLogic( return true; } } - if (simklSettings.backfill_shows && value.stremio.type === "series") { + if (simklSettings.backfill_listshows && value.stremio.type === "series") { if (!value.simkl) { return true; } @@ -81,7 +85,10 @@ function stremioToSimklWatchHistorySyncLogic( if (!value.stremio) { return; } - if (simklSettings.backfill_movies && value.stremio.type === "movie") { + if ( + simklSettings.backfill_watchhistorymovies && + value.stremio.type === "movie" + ) { if (!value.simkl) { return true; } @@ -90,7 +97,10 @@ function stremioToSimklWatchHistorySyncLogic( } return true; } - if (simklSettings.backfill_shows && value.stremio.type === "series") { + if ( + simklSettings.backfill_watchhistoryshows && + value.stremio.type === "series" + ) { if (!value.simkl) { return true; } @@ -111,12 +121,8 @@ function stremioToSimklWatchHistorySyncLogic( export async function backfillFromStremioToSimkl( stremioClient: StremioAPIClient, simklClient: SimklAPIClient, + force = false, ) { - if (!simklSettings.backfill_shows && !simklSettings.backfill_movies) { - console.log("Skipping Backup"); - return; - } - const stremioLibrary = await stremioClient.getLibrary(); const simklLibrary = await simklClient.getLibrary(); @@ -125,20 +131,32 @@ export async function backfillFromStremioToSimkl( convertSimklLibraryToSimklLibraryObjectArray(simklLibrary), ); - let backfillToList = convertFromStremioLibraryToSimklList( - groupedLibrary, - stremioToSimklListSyncLogic, - ); - - await simklClient.updateMoviesList(backfillToList.movies); - await simklClient.updateShowsList(backfillToList.shows); - - let backfillToWatchHistory = - await convertFromStremioLibraryToSimklWatchHistory( + if ( + simklSettings.backfill_listshows || + simklSettings.backfill_listmovies || + force + ) { + let backfillToList = convertFromStremioLibraryToSimklList( groupedLibrary, - stremioToSimklWatchHistorySyncLogic, + stremioToSimklListSyncLogic, ); - await simklClient.updateMoviesHistory(backfillToWatchHistory.movies); - await simklClient.updateShowsHistory(backfillToWatchHistory.shows); + await simklClient.updateMoviesList(backfillToList.movies); + await simklClient.updateShowsList(backfillToList.shows); + } + + if ( + simklSettings.backfill_watchhistoryshows || + simklSettings.backfill_watchhistorymovies || + force + ) { + let backfillToWatchHistory = + await convertFromStremioLibraryToSimklWatchHistory( + groupedLibrary, + stremioToSimklWatchHistorySyncLogic, + ); + + await simklClient.updateMoviesHistory(backfillToWatchHistory.movies); + await simklClient.updateShowsHistory(backfillToWatchHistory.shows); + } }