-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplaylist-api-test.js
More file actions
72 lines (69 loc) · 2.09 KB
/
playlist-api-test.js
File metadata and controls
72 lines (69 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import https from 'https'
const args = process.argv.slice(2)
// test parser
const token = args[0] || process.env.INVIDIOUS_TOKEN
async function testPlaylistApi(playlist) {
const req = https.request('https://[placeholder]/api/v1/auth/playlists', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'User-Agent': 'ft-to-inv-bot/1.0 (+https://ft-to-inv-bot.riki-pedia.org/)',
Accept: 'application/json',
Cookie: `SID=${token}`,
},
})
req.write(JSON.stringify(playlist))
const response = await new Promise((resolve, reject) => {
req.on('response', res => {
let data = ''
res.on('data', chunk => {
data += chunk
})
res.on('end', () => {
resolve({ statusCode: res.statusCode, body: data })
})
})
req.on('error', err => {
reject(err)
})
req.end()
})
console.log('Response:', response)
const id = JSON.parse(response.body).playlistId ?? 'unknown'
console.log('Created playlist with ID:', id)
console.log('adding videos...')
for (const videoId of playlist.videos) {
const addVideoReq = https.request(`https://[placeholder]/api/v1/auth/playlists/${id}/videos`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'User-Agent': 'ft-to-inv-bot/1.0 (+https://ft-to-inv-bot.riki-pedia.org/)',
Accept: 'application/json',
Cookie: `SID=${token}`,
},
})
addVideoReq.write(JSON.stringify({ videoId }))
const addVideoResponse = await new Promise((resolve, reject) => {
addVideoReq.on('response', res => {
let data = ''
res.on('data', chunk => {
data += chunk
})
res.on('end', () => {
resolve({ statusCode: res.statusCode, body: data })
})
})
addVideoReq.on('error', err => {
reject(err)
})
addVideoReq.end()
})
console.log(`Added video ${videoId}:`, addVideoResponse)
}
}
testPlaylistApi({
title: 'Test Playlist',
description: 'A simple test playlist',
privacy: 'private',
videos: ['QZfH7cFp3Ys', 'dQw4w9WgXcQ'],
})