split profile into pieces
This commit is contained in:
1 parent
1b1a9e3cce
commit
11aef3e3aa
1 file changed
+46
-9
+46
-9
@@ -28,15 +28,52 @@ const PLAYLEY_SERVER = `http://${config.ROKU_DEV_TARGET}:8888`;
|
|||||||
const PLAYLIST_DESCRIPTION = "[Automatically imported from Youtube using profile-sync script]"
|
const PLAYLIST_DESCRIPTION = "[Automatically imported from Youtube using profile-sync script]"
|
||||||
|
|
||||||
async function importInvidiousProfile(invidiousInstance, token, profile) {
|
async function importInvidiousProfile(invidiousInstance, token, profile) {
|
||||||
console.log(`Importing Invidious profile`)
|
const pieces = splitProfile(profile);
|
||||||
await fetch(`${invidiousInstance}/api/v1/auth/import/invidious`, {
|
console.log(`Importing Invidious profile (${pieces.length} items)`)
|
||||||
headers: {
|
for (let i = 0; i < pieces.length; i++) {
|
||||||
"Authorization": `Bearer ${token}`,
|
const piece = pieces[i];
|
||||||
'Content-Type': 'application/json'
|
console.log(`Importing "${piece.name}" (${i + 1}/${pieces.length})`)
|
||||||
},
|
|
||||||
method: "POST",
|
await fetch(`${invidiousInstance}/api/v1/auth/import/invidious`, {
|
||||||
body: JSON.stringify(profile)
|
headers: {
|
||||||
})
|
"Authorization": `Bearer ${token}`,
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify(piece.profile)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function splitProfile(profile) {
|
||||||
|
const pieces = []
|
||||||
|
if (profile.subscriptions) {
|
||||||
|
pieces.push({
|
||||||
|
name: "Subscriptions",
|
||||||
|
profile: {
|
||||||
|
subscriptions: profile.subscriptions
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if (profile.watch_history) {
|
||||||
|
pieces.push({
|
||||||
|
name: "Watch History",
|
||||||
|
profile: {
|
||||||
|
watch_history: profile.watch_history
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if (profile.playlists) {
|
||||||
|
profile.playlists.forEach(playlist => {
|
||||||
|
pieces.push({
|
||||||
|
name: `Playlist: ${playlist.title}`,
|
||||||
|
profile: {
|
||||||
|
playlists: [playlist]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return pieces;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function generatePlaylist(sourceUrl, playlistName, browser = undefined, limit = 100) {
|
async function generatePlaylist(sourceUrl, playlistName, browser = undefined, limit = 100) {
|
||||||
|
|||||||
Reference in new issue
Block a user