-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathhttp.js
62 lines (52 loc) · 1.45 KB
/
http.js
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
import { debugLog, makeRequest, encodeTrack } from '../utils.js'
async function loadFrom(uri) {
debugLog('loadtracks', 4, { type: 1, loadType: 'track', sourceName: type, query: uri })
const data = await makeRequest(uri, { method: 'HEAD' })
if (data.error) {
debugLog('loadtracks', 4, { type: 3, loadType: 'track', sourceName: type, query: uri, message: 'Not possible to connect to the URL.', })
return {
loadType: 'error',
data: {
message: 'Not possible to connect to the URL.',
severity: 'fault',
cause: 'Unknown'
}
}
}
if (!data.headers || !data.headers['content-type']?.startsWith('audio/')) {
debugLog('loadtracks', 4, { type: 2, loadType: 'error', sourceName: type, query: uri, message: 'Url is not a playable stream.' })
return {
loadType: 'error',
data: {
message: 'URL is not a playable stream.',
severity: 'common',
cause: 'Invalid URL'
}
}
}
const track = {
identifier: 'unknown',
isSeekable: false,
author: 'unknown',
length: -1,
isStream: false,
position: 0,
title: 'unknown',
uri,
artworkUrl: null,
isrc: null,
sourceName: 'http'
}
debugLog('loadtracks', 4, { type: 2, loadType: 'track', sourceName: type, track, query: uri })
return {
loadType: 'track',
data: {
encoded: encodeTrack(track),
info: track,
pluginInfo: {}
}
}
}
export default {
loadFrom
}