aqualink 2.18.1 → 2.19.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,129 +1,158 @@
1
- 'use strict'
2
-
3
- const YT_ID_REGEX = /(?:[?&]v=|youtu\.be\/|\/embed\/|\/shorts\/)([A-Za-z0-9_-]{11})/
4
-
5
- const _h = {
6
- str: (v, d = '') => typeof v === 'string' ? v : d,
7
- num: (v, d = 0) => Number.isFinite(v) ? v : d
8
- }
9
-
10
- class Track {
11
- constructor(data = {}, requester = null, node = null) {
12
- const info = data.info || {}
13
-
14
- this.track = data.track || data.encoded || null
15
- this.identifier = _h.str(info.identifier)
16
- this.isSeekable = Boolean(info.isSeekable)
17
- this.author = _h.str(info.author)
18
- this.position = _h.num(info.position)
19
- this.duration = _h.num(info.length)
20
- this.isStream = Boolean(info.isStream)
21
- this.title = _h.str(info.title)
22
- this.uri = _h.str(info.uri)
23
- this.sourceName = _h.str(info.sourceName)
24
- this.artworkUrl = _h.str(info.artworkUrl)
25
- this.pluginInfo = info.pluginInfo || data.pluginInfo || {}
26
-
27
- this.playlist = data.playlist || null
28
- this.node = node || data.node || null
29
- this.nodes = data.nodes || null
30
- this.requester = requester || null
31
- this._infoCache = null
32
- }
33
-
34
- get info() {
35
- return this._infoCache ||= Object.freeze({
36
- identifier: this.identifier,
37
- isSeekable: this.isSeekable,
38
- position: this.position,
39
- author: this.author,
40
- length: this.duration,
41
- isStream: this.isStream,
42
- title: this.title,
43
- uri: this.uri,
44
- sourceName: this.sourceName,
45
- artworkUrl: this.artworkUrl || this._computeArtwork()
46
- })
47
- }
48
-
49
- get length() {
50
- return this.duration
51
- }
52
-
53
- get thumbnail() {
54
- return this.artworkUrl || this._computeArtwork()
55
- }
56
-
57
- async resolve(aqua, opts = {}) {
58
- if (typeof this.track === 'string' && this.track) return this
59
- if (!aqua?.resolve) return null
60
-
61
- const platform = opts.platform || aqua?.options?.defaultSearchPlatform || 'ytsearch'
62
- const node = opts.node || this.node || this.nodes
63
-
64
- let query = this.uri
65
- if (!query) {
66
- if (this.title) {
67
- query = this.author ? `${this.author} - ${this.title}`.trim() : this.title.trim()
68
- } else if (this.identifier && this.sourceName?.toLowerCase().includes('youtube')) {
69
- query = this.identifier
70
- }
71
- }
72
- if (!query) return null
73
-
74
- const payload = { query, source: platform, requester: this.requester }
75
- if (node) payload.node = node
76
-
77
- let result
78
- try {
79
- result = await aqua.resolve(payload)
80
- } catch {
81
- return null
82
- }
83
-
84
- const found = result?.tracks?.[0]
85
- if (!found) return null
86
-
87
- const fi = found.info || {}
88
-
89
- this.track = typeof found.track === 'string' ? found.track : (found.encoded || this.track)
90
- this.identifier = fi.identifier ?? this.identifier
91
- this.title = fi.title ?? this.title
92
- this.author = fi.author ?? this.author
93
- this.uri = fi.uri ?? this.uri
94
- this.sourceName = fi.sourceName ?? this.sourceName
95
- this.artworkUrl = fi.artworkUrl ?? this.artworkUrl
96
- this.pluginInfo = fi.pluginInfo ?? found.pluginInfo ?? this.pluginInfo
97
- this.isSeekable = fi.isSeekable ?? this.isSeekable
98
- this.isStream = fi.isStream ?? this.isStream
99
- this.position = _h.num(fi.position, this.position)
100
- this.duration = _h.num(fi.length, this.duration)
101
- this.playlist = found.playlist ?? this.playlist
102
- this._infoCache = null
103
-
104
- return this
105
- }
106
-
107
- isValid() {
108
- return Boolean(
109
- (typeof this.track === 'string' && this.track) ||
110
- (typeof this.uri === 'string' && this.uri)
111
- )
112
- }
113
-
114
- dispose() {
115
- this._infoCache = this.requester = this.node = this.nodes = this.playlist = this.track = null
116
- this.identifier = this.author = this.title = this.uri = this.sourceName = this.artworkUrl = ''
117
- }
118
-
119
- _computeArtwork() {
120
- if (this.artworkUrl) return this.artworkUrl
121
- const id = this.identifier || (this.uri && YT_ID_REGEX.exec(this.uri)?.[1])
122
- if (id && this.sourceName?.includes('youtube')) {
123
- return `https://i.ytimg.com/vi/${id}/hqdefault.jpg`
124
- }
125
- return null
126
- }
127
- }
128
-
129
- module.exports = Track
1
+ const YT_ID_REGEX =
2
+ /(?:[?&]v=|youtu\.be\/|\/embed\/|\/shorts\/)([A-Za-z0-9_-]{11})/
3
+
4
+ const _h = {
5
+ str: (v, d = '') => (typeof v === 'string' ? v : d),
6
+ num: (v, d = 0) => (Number.isFinite(v) ? v : d)
7
+ }
8
+
9
+ class Track {
10
+ constructor(data = {}, requester = null, node = null) {
11
+ const info = data.info || {}
12
+
13
+ this.track = data.track || data.encoded || null
14
+ this.identifier = _h.str(info.identifier)
15
+ this.isSeekable = Boolean(info.isSeekable)
16
+ this.author = _h.str(info.author)
17
+ this.position = _h.num(info.position)
18
+ this.duration = _h.num(info.length)
19
+ this.isStream = Boolean(info.isStream)
20
+ this.title = _h.str(info.title)
21
+ this.uri = _h.str(info.uri)
22
+ this.sourceName = _h.str(info.sourceName)
23
+ this.artworkUrl = _h.str(info.artworkUrl)
24
+ this.pluginInfo = info.pluginInfo || data.pluginInfo || {}
25
+
26
+ this.playlist = data.playlist || null
27
+ this.node = node || data.node || null
28
+ this.nodes = data.nodes || null
29
+ this.requester = requester || null
30
+ this._infoCache = null
31
+ this._artworkCache = undefined // undefined = not computed, null = computed but no artwork
32
+ }
33
+
34
+ get info() {
35
+ if (this._infoCache) return this._infoCache
36
+ this._infoCache = Object.freeze({
37
+ identifier: this.identifier,
38
+ isSeekable: this.isSeekable,
39
+ position: this.position,
40
+ author: this.author,
41
+ length: this.duration,
42
+ isStream: this.isStream,
43
+ title: this.title,
44
+ uri: this.uri,
45
+ sourceName: this.sourceName,
46
+ artworkUrl: this.artworkUrl || this._computeArtwork()
47
+ })
48
+ return this._infoCache
49
+ }
50
+
51
+ get length() {
52
+ return this.duration
53
+ }
54
+
55
+ get thumbnail() {
56
+ if (this.artworkUrl) return this.artworkUrl
57
+ if (this._artworkCache !== undefined) return this._artworkCache
58
+ this._artworkCache = this._computeArtwork()
59
+ return this._artworkCache
60
+ }
61
+
62
+ async resolve(aqua, opts = {}) {
63
+ if (typeof this.track === 'string' && this.track) return this
64
+ if (!aqua?.resolve) return null
65
+
66
+ const platform =
67
+ opts.platform || aqua?.options?.defaultSearchPlatform || 'ytsearch'
68
+ const node = opts.node || this.node || this.nodes
69
+
70
+ let query = this.uri
71
+ if (!query) {
72
+ if (this.title) {
73
+ query = this.author
74
+ ? `${this.author} - ${this.title}`.trim()
75
+ : this.title.trim()
76
+ } else if (
77
+ this.identifier &&
78
+ this.sourceName?.toLowerCase().includes('youtube')
79
+ ) {
80
+ query = this.identifier
81
+ }
82
+ }
83
+ if (!query) return null
84
+
85
+ const payload = { query, source: platform, requester: this.requester }
86
+ if (node) payload.node = node
87
+
88
+ let result
89
+ try {
90
+ result = await aqua.resolve(payload)
91
+ } catch {
92
+ return null
93
+ }
94
+
95
+ const found = result?.tracks?.[0]
96
+ if (!found) return null
97
+
98
+ const fi = found.info || {}
99
+
100
+ this.track =
101
+ typeof found.track === 'string'
102
+ ? found.track
103
+ : found.encoded || this.track
104
+ this.identifier = fi.identifier ?? this.identifier
105
+ this.title = fi.title ?? this.title
106
+ this.author = fi.author ?? this.author
107
+ this.uri = fi.uri ?? this.uri
108
+ this.sourceName = fi.sourceName ?? this.sourceName
109
+ this.artworkUrl = fi.artworkUrl ?? this.artworkUrl
110
+ this.pluginInfo = fi.pluginInfo ?? found.pluginInfo ?? this.pluginInfo
111
+ this.isSeekable = fi.isSeekable ?? this.isSeekable
112
+ this.isStream = fi.isStream ?? this.isStream
113
+ this.position = _h.num(fi.position, this.position)
114
+ this.duration = _h.num(fi.length, this.duration)
115
+ this.playlist = found.playlist ?? this.playlist
116
+ this._infoCache = null
117
+
118
+ return this
119
+ }
120
+
121
+ isValid() {
122
+ return Boolean(
123
+ (typeof this.track === 'string' && this.track) ||
124
+ (typeof this.uri === 'string' && this.uri)
125
+ )
126
+ }
127
+
128
+ dispose() {
129
+ this._infoCache =
130
+ this.requester =
131
+ this.node =
132
+ this.nodes =
133
+ this.playlist =
134
+ this.track =
135
+ null
136
+ this.identifier =
137
+ this.author =
138
+ this.title =
139
+ this.uri =
140
+ this.sourceName =
141
+ this.artworkUrl =
142
+ ''
143
+ }
144
+
145
+ _computeArtwork() {
146
+ if (this.artworkUrl) return this.artworkUrl
147
+ if (this._artworkCache !== undefined) return this._artworkCache
148
+ const id = this.identifier || (this.uri && YT_ID_REGEX.exec(this.uri)?.[1])
149
+ if (id && this.sourceName?.includes('youtube')) {
150
+ this._artworkCache = `https://i.ytimg.com/vi/${id}/hqdefault.jpg`
151
+ return this._artworkCache
152
+ }
153
+ this._artworkCache = null
154
+ return null
155
+ }
156
+ }
157
+
158
+ module.exports = Track
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aqualink",
3
- "version": "2.18.1",
3
+ "version": "2.19.1",
4
4
  "description": "An Lavalink/Nodelink client, focused in pure performance and features",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",