- Shuffle
- Favorities (remote)
- Remove song for remote playlists (WIP)
This commit is contained in:
Shiny Nematoda 2022-09-23 10:14:22 +00:00
parent 04af1a227d
commit 8efa6a6439
No known key found for this signature in database
GPG key ID: 6506D50F5613A42D
10 changed files with 441 additions and 260 deletions

View file

@ -49,17 +49,57 @@ export async function getJsonHyp(path) {
export async function getJsonAuth(path, opts) {
const root = useStore().getItem('authapi') || 'pipedapi.kavin.rocks';
return await fetch('https://' + root + path, opts).then(res => res.json());
return await fetch('https://' + root + path, opts)
.then(res => res.json())
.catch(err => {
alert(err);
});
}
export async function useAuthCreatePlaylist(name) {
const auth = useStore().getItem('auth');
if (auth && name) {
return await getJsonAuth('/user/playlists/create', {
method: 'POST',
body: JSON.stringify({
name: `Playlist - ${name}`,
}),
headers: {
Authorization: auth,
'Content-Type': 'application/json',
},
});
}
}
export async function getAuthPlaylists() {
if (!!useStore().getItem('auth')) {
const auth = useStore().getItem('auth');
if (auth) {
const res = await getJsonAuth('/user/playlists', {
headers: {
Authorization: useStore().getItem('auth'),
Authorization: auth,
},
});
return res.filter(i => i.name.startsWith('Playlist - '));
}
}
export async function useAuthAddToPlaylist(id, path) {
const auth = useStore().getItem('auth');
if (auth && id && path) {
return getJsonAuth('/user/playlists/add', {
method: 'POST',
headers: {
Authorization: auth,
},
body: JSON.stringify({
playlistId: id,
videoId: new URL('https://example.com' + path).searchParams.get('v'),
}),
});
}
}