Skip to content

Commit

Permalink
Updated some logic also now works for auto episodes
Browse files Browse the repository at this point in the history
  • Loading branch information
aliyss committed Aug 28, 2023
1 parent 2f1f082 commit dec44c2
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 30 deletions.
7 changes: 4 additions & 3 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/addon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [] });
Expand Down
6 changes: 4 additions & 2 deletions src/utils/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
66 changes: 42 additions & 24 deletions src/utils/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
};

Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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();

Expand All @@ -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);
}
}

0 comments on commit dec44c2

Please sign in to comment.