1
0
Fork 0
mirror of https://github.com/sussy-code/smov.git synced 2024-12-20 14:37:43 +01:00

Finish data migration

This commit is contained in:
James Hawkins 2022-04-25 19:56:29 +01:00
parent 95f623922a
commit 008c91b0fe
4 changed files with 59 additions and 123 deletions

View file

@ -1,45 +1,13 @@
import { versionedStoreBuilder } from 'utils/storage'; import { versionedStoreBuilder } from 'utils/storage';
/*
version 0
{
[{scraperid}]: {
movie: {
[{movie-id}]: {
full: {
currentlyAt: number,
totalDuration: number,
updatedAt: number, // unix timestamp in ms
meta: FullMetaObject, // no idea whats in here
}
}
},
show: {
[{show-id}]: {
[{season}-{episode}]: {
currentlyAt: number,
totalDuration: number,
updatedAt: number, // unix timestamp in ms
show: {
episode: string,
season: string,
},
meta: FullMetaObject, // no idea whats in here
}
}
}
}
}
*/
export const BookmarkStore = versionedStoreBuilder() export const BookmarkStore = versionedStoreBuilder()
.setKey('mw-bookmarks') .setKey('mw-bookmarks')
.addVersion({ .addVersion({
version: 0, version: 0,
create() { create() {
return { return {
bookmarks: [] bookmarks: []
}
} }
}) }
.build() })
.build()

View file

@ -14,7 +14,7 @@ interface WatchedStoreItem extends MWMediaMeta {
percentage: number; percentage: number;
} }
interface WatchedStoreData { export interface WatchedStoreData {
items: WatchedStoreItem[]; items: WatchedStoreItem[];
} }
@ -38,7 +38,7 @@ export function getWatchedFromPortable(
} }
const WatchedContext = createContext<WatchedStoreDataWrapper>({ const WatchedContext = createContext<WatchedStoreDataWrapper>({
updateProgress: () => {}, updateProgress: () => { },
getFilteredWatched: () => [], getFilteredWatched: () => [],
watched: { watched: {
items: [], items: [],

View file

@ -1,50 +1,6 @@
import { MWMediaType } from "providers";
import { versionedStoreBuilder } from "utils/storage"; import { versionedStoreBuilder } from "utils/storage";
import { WatchedStoreData } from "./context";
/*
version 0
{
[{scraperid}]: {
movie: {
[{movie-id}]: {
full: {
currentlyAt: number,
totalDuration: number,
updatedAt: number, // unix timestamp in ms
meta: FullMetaObject, // no idea whats in here
}
}
},
show: {
[{show-id}]: {
[{season}-{episode}]: {
currentlyAt: number,
totalDuration: number,
updatedAt: number, // unix timestamp in ms
show: {
episode: string,
season: string,
},
meta: FullMetaObject, // no idea whats in here
}
}
}
}
}
*/
/*
item = {
mediaId: media.mediaId,
mediaType: media.mediaType,
providerId: media.providerId,
title: media.title,
year: media.year,
percentage: 0,
progress: 0,
episodeId: media.episodeId,
seasonId: media.seasonId,
};
*/
export const VideoProgressStore = versionedStoreBuilder() export const VideoProgressStore = versionedStoreBuilder()
.setKey("video-progress") .setKey("video-progress")
@ -54,46 +10,58 @@ export const VideoProgressStore = versionedStoreBuilder()
.addVersion({ .addVersion({
version: 1, version: 1,
migrate(data: any) { migrate(data: any) {
const output: any = { items: [] as any }; const output: WatchedStoreData = { items: [] };
if (!data || data.constructor !== Object)
return output;
Object.keys(data).forEach((scraperId) => { Object.keys(data).forEach((scraperId) => {
if (scraperId === "--version") return; if (scraperId === "--version") return;
if (scraperId === "save") return; if (scraperId === "save") return;
if (data[scraperId].movie) { if (data[scraperId].movie && data[scraperId].movie.constructor === Object) {
Object.keys(data[scraperId].movie).forEach((movieId) => { Object.keys(data[scraperId].movie).forEach((movieId) => {
output.items.push({ try {
mediaId: movieId.includes("player.php") ? movieId.split("player.php%3Fimdb%3D")[1] : movieId, output.items.push({
mediaType: "movie", mediaId: movieId.includes("player.php") ? movieId.split("player.php%3Fimdb%3D")[1] : movieId,
providerId: scraperId, mediaType: MWMediaType.MOVIE,
title: data[scraperId].movie[movieId].full.meta.title, providerId: scraperId,
year: data[scraperId].movie[movieId].full.meta.year, title: data[scraperId].movie[movieId].full.meta.title,
progress: data[scraperId].movie[movieId].full.currentlyAt, year: data[scraperId].movie[movieId].full.meta.year,
percentage: Math.round((data[scraperId].movie[movieId].full.currentlyAt / data[scraperId].movie[movieId].full.totalDuration) * 100) progress: data[scraperId].movie[movieId].full.currentlyAt,
}); percentage: Math.round((data[scraperId].movie[movieId].full.currentlyAt / data[scraperId].movie[movieId].full.totalDuration) * 100)
});
} catch (err) {
console.error(`Failed to migrate movie: ${scraperId}/${movieId}`, data[scraperId].movie[movieId]);
}
}); });
} }
if (data[scraperId].show) { if (data[scraperId].show && data[scraperId].show.constructor === Object) {
Object.keys(data[scraperId].show).forEach((showId) => { Object.keys(data[scraperId].show).forEach((showId) => {
if (data[scraperId].show[showId].constructor !== Object)
return;
Object.keys(data[scraperId].show[showId]).forEach((episodeId) => { Object.keys(data[scraperId].show[showId]).forEach((episodeId) => {
output.items.push({ try {
mediaId: showId, output.items.push({
mediaType: "series", mediaId: showId,
providerId: scraperId, mediaType: MWMediaType.SERIES,
title: data[scraperId].show[showId][episodeId].meta.title, providerId: scraperId,
year: data[scraperId].show[showId][episodeId].meta.year, title: data[scraperId].show[showId][episodeId].meta.title,
percentage: Math.round((data[scraperId].show[showId][episodeId].currentlyAt / data[scraperId].show[showId][episodeId].totalDuration) * 100), year: data[scraperId].show[showId][episodeId].meta.year,
progress: data[scraperId].show[showId][episodeId].currentlyAt, percentage: Math.round((data[scraperId].show[showId][episodeId].currentlyAt / data[scraperId].show[showId][episodeId].totalDuration) * 100),
episodeId: data[scraperId].show[showId][episodeId].show.episode, progress: data[scraperId].show[showId][episodeId].currentlyAt,
seasonId: data[scraperId].show[showId][episodeId].show.season, episodeId: data[scraperId].show[showId][episodeId].show.episode,
}); seasonId: data[scraperId].show[showId][episodeId].show.season,
});
} catch (err) {
console.error(`Failed to migrate series: ${scraperId}/${showId}/${episodeId}`, data[scraperId].show[showId][episodeId]);
}
}); });
}); });
} }
}); });
console.log(output);
return output; return output;
}, },
create() { create() {

View file

@ -157,19 +157,19 @@ export function versionedStoreBuilder(): any {
version, // version number version, // version number
update: migrate update: migrate
? (data: any) => { ? (data: any) => {
// update function, and increment version // update function, and increment version
migrate(data); const newData = migrate(data);
data["--version"] = version; // eslint-disable-line no-param-reassign newData["--version"] = version; // eslint-disable-line no-param-reassign
return data; return newData;
} }
: undefined, : undefined,
init: create init: create
? () => { ? () => {
// return an initial object // return an initial object
const data = create(); const data = create();
data["--version"] = version; data["--version"] = version;
return data; return data;
} }
: undefined, : undefined,
}; };
return this; return this;