From 87fd61307cc1017e9305fd6ce82334d3f98c2d45 Mon Sep 17 00:00:00 2001 From: dexter21767-dev Date: Mon, 15 Apr 2024 15:32:58 +0100 Subject: [PATCH] add trakt history import button --- package-lock.json | 188 +++++++++++++++++++++++++++++++- package.json | 1 + src/routes/Settings/Settings.js | 42 +++++++ 3 files changed, 228 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 76db0e04a..3900c638d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -36,6 +36,7 @@ "react-i18next": "^12.1.1", "react-is": "18.2.0", "spatial-navigation-polyfill": "github:Stremio/spatial-navigation#64871b1422466f5f45d24ebc8bbd315b2ebab6a6", + "stremio-history-sync": "github:stremio/stremio-history-sync", "stremio-translations": "github:Stremio/stremio-translations#b13b3e2653bd0dcf644d2a20ffa32074fe6532dd", "url": "0.11.0", "use-long-press": "^3.1.5" @@ -3878,6 +3879,17 @@ "node": ">= 4.0.0" } }, + "node_modules/atob": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/atob/-/atob-2.1.2.tgz", + "integrity": "sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg==", + "bin": { + "atob": "bin/atob.js" + }, + "engines": { + "node": ">= 4.5.0" + } + }, "node_modules/autoprefixer": { "version": "10.4.0", "dev": true, @@ -4308,6 +4320,17 @@ "node-int64": "^0.4.0" } }, + "node_modules/btoa": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/btoa/-/btoa-1.2.1.tgz", + "integrity": "sha512-SB4/MIGlsiVkMcHmT+pSmIPoNDoHg+7cMzmt3Uxt628MTz2487DKSqK/fuhFBrkuqrYv5UCEnACpF4dTFNKc/g==", + "bin": { + "btoa": "bin/btoa.js" + }, + "engines": { + "node": ">= 0.4.0" + } + }, "node_modules/buffer": { "version": "6.0.3", "funding": [ @@ -5554,6 +5577,25 @@ "node": ">= 0.8" } }, + "node_modules/encoding": { + "version": "0.1.13", + "resolved": "https://registry.npmjs.org/encoding/-/encoding-0.1.13.tgz", + "integrity": "sha512-ETBauow1T35Y/WZMkio9jiM0Z5xjHHmJ4XmjZOq1l/dXz3lr2sRn87nJy20RupqSh1F2m3HHPSp8ShIPQJrJ3A==", + "dependencies": { + "iconv-lite": "^0.6.2" + } + }, + "node_modules/encoding/node_modules/iconv-lite": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", + "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3.0.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/enhanced-resolve": { "version": "5.8.3", "dev": true, @@ -10223,6 +10265,23 @@ "dev": true, "license": "0BSD" }, + "node_modules/node-fetch": { + "version": "1.7.3", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-1.7.3.tgz", + "integrity": "sha512-NhZ4CsKx7cYm2vSrBAr2PvFOe6sWDf0UYLRqA6svUYg7+/TSfVAu49jYC4BvQ4Sms9SZgdqGBgroqfDhJdTyKQ==", + "dependencies": { + "encoding": "^0.1.11", + "is-stream": "^1.0.1" + } + }, + "node_modules/node-fetch/node_modules/is-stream": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz", + "integrity": "sha512-uQPm8kcs47jx38atAcWTVxyltQYoPT68y9aWYdV6yWXSyW8mzSat0TL6CiWdZeCdF3KrAvpVtnHbTv4RN+rqdQ==", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/node-forge": { "version": "1.3.1", "dev": true, @@ -10553,7 +10612,6 @@ }, "node_modules/pako": { "version": "1.0.11", - "dev": true, "license": "(MIT AND Zlib)" }, "node_modules/param-case": { @@ -12038,7 +12096,6 @@ }, "node_modules/safer-buffer": { "version": "2.1.2", - "dev": true, "license": "MIT" }, "node_modules/sax": { @@ -12469,12 +12526,133 @@ "node": ">= 0.6" } }, + "node_modules/stremio-addon-client": { + "version": "1.16.1", + "resolved": "https://registry.npmjs.org/stremio-addon-client/-/stremio-addon-client-1.16.1.tgz", + "integrity": "sha512-QUtIlUpOn1SwkZSC1zmTwv5ZxFUDe/f0xbAsGosy98COA/ajJztGAjp3vFX1QKU5x5/G7/U+OkgEVIL3kxzqYQ==", + "dependencies": { + "node-fetch": "^2.1.2", + "stremio-addon-linter": "^1.7.0", + "thunky": "^1.0.2", + "url": "^0.11.0" + } + }, + "node_modules/stremio-addon-client/node_modules/node-fetch": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", + "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==", + "dependencies": { + "whatwg-url": "^5.0.0" + }, + "engines": { + "node": "4.x || >=6.0.0" + }, + "peerDependencies": { + "encoding": "^0.1.0" + }, + "peerDependenciesMeta": { + "encoding": { + "optional": true + } + } + }, + "node_modules/stremio-addon-client/node_modules/tr46": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", + "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" + }, + "node_modules/stremio-addon-client/node_modules/webidl-conversions": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", + "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==" + }, + "node_modules/stremio-addon-client/node_modules/whatwg-url": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", + "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", + "dependencies": { + "tr46": "~0.0.3", + "webidl-conversions": "^3.0.0" + } + }, + "node_modules/stremio-addon-linter": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/stremio-addon-linter/-/stremio-addon-linter-1.7.0.tgz", + "integrity": "sha512-ck1L1Wp2qvAhvXLj+4Lq1XRn8K3r2gx1i/f+e1W6K0+Et/oIYYDmaIVoh3SvExiNbCBcbJjH9WWEeDYKoqaMqQ==", + "dependencies": { + "semver": "^5.5.0" + } + }, + "node_modules/stremio-addon-linter/node_modules/semver": { + "version": "5.7.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.2.tgz", + "integrity": "sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==", + "bin": { + "semver": "bin/semver" + } + }, + "node_modules/stremio-api-client": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/stremio-api-client/-/stremio-api-client-1.6.0.tgz", + "integrity": "sha512-hJTiAO+YSV8KO9uKnpPJowlrqOvtEtsQZVmu5dLyh4U5PGwRcgRXCeh3PfFNjqgnqtCGe99+GZtQ28wLKqM6xg==", + "dependencies": { + "events": "1.1.0", + "node-fetch": "2.2.0", + "stremio-addon-client": "^1.14.5", + "stremio-official-addons": "^1.5.0" + } + }, + "node_modules/stremio-api-client/node_modules/events": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/events/-/events-1.1.0.tgz", + "integrity": "sha512-bXhhA5cOCDO4JSjAeFQYx/NrQKQrRvh/HaMzkwhPpMcNxBBp3Qbz9R5RXFIhznG50VBBt5Uh09koi3Etc8YwNQ==", + "engines": { + "node": ">=0.4.x" + } + }, + "node_modules/stremio-api-client/node_modules/node-fetch": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.2.0.tgz", + "integrity": "sha512-OayFWziIxiHY8bCUyLX6sTpDH8Jsbp4FfYd1j1f7vZyfgkcOnAyM4oQR16f8a0s7Gl/viMGRey8eScYk4V4EZA==", + "engines": { + "node": "4.x || >=6.0.0" + } + }, + "node_modules/stremio-history-sync": { + "version": "1.0.0", + "resolved": "git+ssh://git@github.com/stremio/stremio-history-sync.git#7e0a58c9f576405b8b93d5d4cf987bcf50c8d5d5", + "license": "MIT", + "dependencies": { + "node-fetch": "^1.7.3", + "stremio-api-client": "^1.6.0", + "stremio-watched-bitfield": "^1.1.0", + "whatwg-fetch": "^3.6.2" + }, + "engines": { + "node": "14.x.x" + } + }, + "node_modules/stremio-official-addons": { + "version": "1.5.5", + "resolved": "https://registry.npmjs.org/stremio-official-addons/-/stremio-official-addons-1.5.5.tgz", + "integrity": "sha512-bzDZYJbnjji3n9zSkowpuZP2BLcDik40qT9Xib5t1ETxpBWCsPo3qhkRu1oBmNIclzwJr6zuqnN8EsxDc17lXg==" + }, "node_modules/stremio-translations": { "version": "1.44.7", "resolved": "git+ssh://git@github.com/Stremio/stremio-translations.git#b13b3e2653bd0dcf644d2a20ffa32074fe6532dd", "integrity": "sha512-OtRAM3j9ie89llgI379p4utCbgnNMswE+LtL/lyLRVLfm5B+jpBLp4ozpU25iQg0O4tvN+OHBjXZ870CCHtZMA==", "license": "MIT" }, + "node_modules/stremio-watched-bitfield": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/stremio-watched-bitfield/-/stremio-watched-bitfield-1.1.0.tgz", + "integrity": "sha512-Q1LFmxKchHzJYgmSwbgGeMq6D6CVQGkPFTmyy3dOtuc5f1jD254uHdG6Ouw6awZ73HDhMDjAhA5LJPBpGM/7IQ==", + "dependencies": { + "atob": "^2.1.1", + "btoa": "^1.2.1", + "pako": "^1.0.6" + } + }, "node_modules/string_decoder": { "version": "1.1.1", "dev": true, @@ -12935,7 +13113,6 @@ }, "node_modules/thunky": { "version": "1.1.0", - "dev": true, "license": "MIT" }, "node_modules/timm": { @@ -14077,6 +14254,11 @@ "iconv-lite": "0.4.24" } }, + "node_modules/whatwg-fetch": { + "version": "3.6.20", + "resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-3.6.20.tgz", + "integrity": "sha512-EqhiFU6daOA8kpjOWTL0olhVOF3i7OrFzSYiGsEMB8GcXS+RrzauAERX65xMeNWVqxA6HXH2m69Z9LaKKdisfg==" + }, "node_modules/whatwg-mimetype": { "version": "2.3.0", "dev": true, diff --git a/package.json b/package.json index bf4b1bd10..d56578973 100755 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "react-i18next": "^12.1.1", "react-is": "18.2.0", "spatial-navigation-polyfill": "github:Stremio/spatial-navigation#64871b1422466f5f45d24ebc8bbd315b2ebab6a6", + "stremio-history-sync": "github:stremio/stremio-history-sync", "stremio-translations": "github:Stremio/stremio-translations#b13b3e2653bd0dcf644d2a20ffa32074fe6532dd", "url": "0.11.0", "use-long-press": "^3.1.5" diff --git a/src/routes/Settings/Settings.js b/src/routes/Settings/Settings.js index 9dc6e3556..143335126 100644 --- a/src/routes/Settings/Settings.js +++ b/src/routes/Settings/Settings.js @@ -8,6 +8,7 @@ const { default: Icon } = require('@stremio/stremio-icons/react'); const { useRouteFocused } = require('stremio-router'); const { useServices } = require('stremio/services'); const { Button, Checkbox, MainNavBars, Multiselect, ColorInput, TextInput, ModalDialog, useProfile, useStreamingServer, useBinaryState, withCoreSuspender, useToast } = require('stremio/common'); +const historySync = require('stremio-history-sync'); const useProfileSettingsInputs = require('./useProfileSettingsInputs'); const useStreamingServerSettingsInputs = require('./useStreamingServerSettingsInputs'); const useDataExport = require('./useDataExport'); @@ -100,6 +101,38 @@ const Settings = () => { } }); } + }, [isTraktAuthenticated, profile]); + const traktImportOnClick = React.useCallback(() => { + if ((localStorage.getItem('lastTraktImport') || 0) > Date.now() - (24 * 60 * 60 * 1000)) { + toast.show({ + type: 'error', + title: 'You already used this action recently, try again later', + timeout: 25000 + }); + return; + } + localStorage.setItem('lastTraktImport', Date.now()); + toast.show({ + type: 'success', + title: 'Importing Trakt watched list...', + timeout: 25000 + }); + historySync.traktSync(profile.auth.key) + .then((res) => + toast.show({ + type: 'success', + title: `Success: ${res.length} items imported from trakt watched list. (${res.movies} movies & ${res.series} series)`, + timeout: 25000 + })) + .catch((e) => { + console.error(e); + localStorage.setItem('lastTraktImport', 0); + toast.show({ + type: 'error', + title: 'Trakt Import failed, please try again later', + timeout: 25000 + }); + }); }, [isTraktAuthenticated, profile.auth]); const subscribeCalendarOnClick = React.useCallback(() => { const url = `webcal://www.strem.io/calendar/${profile.auth.user._id}.ics`; @@ -325,6 +358,15 @@ const Settings = () => { { profile.auth !== null && profile.auth.user !== null && profile.auth.user.trakt !== null ? t('LOG_OUT') : t('SETTINGS_TRAKT_AUTHENTICATE') } + { + isTraktAuthenticated ? + + : null + }