magmastream 2.9.2-dev.7 → 2.9.2-dev.9
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.
package/dist/index.d.ts
CHANGED
|
@@ -3477,6 +3477,12 @@ declare abstract class TrackUtils {
|
|
|
3477
3477
|
* @returns Whether the search result is valid.
|
|
3478
3478
|
*/
|
|
3479
3479
|
static isErrorOrEmptySearchResult(result: SearchResult): result is ErrorOrEmptySearchResult;
|
|
3480
|
+
/**
|
|
3481
|
+
* Revives a track.
|
|
3482
|
+
* @param track The track to revive.
|
|
3483
|
+
* @returns The revived track.
|
|
3484
|
+
*/
|
|
3485
|
+
static revive(track: Track): Track;
|
|
3480
3486
|
}
|
|
3481
3487
|
declare abstract class AutoPlayUtils {
|
|
3482
3488
|
private static manager;
|
|
@@ -240,14 +240,15 @@ class JsonQueue {
|
|
|
240
240
|
* @returns The current track.
|
|
241
241
|
*/
|
|
242
242
|
async getCurrent() {
|
|
243
|
-
|
|
243
|
+
const track = await this.readJSON(this.currentPath);
|
|
244
|
+
return track ? Utils_1.TrackUtils.revive(track) : null;
|
|
244
245
|
}
|
|
245
246
|
/**
|
|
246
247
|
* @returns The previous tracks.
|
|
247
248
|
*/
|
|
248
249
|
async getPrevious() {
|
|
249
250
|
const data = await this.readJSON(this.previousPath);
|
|
250
|
-
return Array.isArray(data) ? data : [];
|
|
251
|
+
return Array.isArray(data) ? data.map(Utils_1.TrackUtils.revive) : [];
|
|
251
252
|
}
|
|
252
253
|
/**
|
|
253
254
|
* @returns The tracks in the queue from start to end.
|
|
@@ -523,15 +524,17 @@ class JsonQueue {
|
|
|
523
524
|
await fs_1.promises.unlink(filePath);
|
|
524
525
|
}
|
|
525
526
|
catch (err) {
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
527
|
+
if (err.code !== "ENOENT") {
|
|
528
|
+
const error = err instanceof MagmastreamError_1.MagmaStreamError
|
|
529
|
+
? err
|
|
530
|
+
: new MagmastreamError_1.MagmaStreamError({
|
|
531
|
+
code: Enums_1.MagmaStreamErrorCode.QUEUE_JSON_ERROR,
|
|
532
|
+
message: `Failed to delete file: ${filePath}`,
|
|
533
|
+
cause: err,
|
|
534
|
+
});
|
|
535
|
+
console.error(error);
|
|
536
|
+
this.manager.emit(Enums_1.ManagerEventTypes.Debug, `[JSONQUEUE] Failed to delete file: ${filePath}`);
|
|
537
|
+
}
|
|
535
538
|
}
|
|
536
539
|
}
|
|
537
540
|
/**
|
|
@@ -545,7 +548,7 @@ class JsonQueue {
|
|
|
545
548
|
*/
|
|
546
549
|
async getQueue() {
|
|
547
550
|
const data = await this.readJSON(this.queuePath);
|
|
548
|
-
return Array.isArray(data) ? data : [];
|
|
551
|
+
return Array.isArray(data) ? data.map(Utils_1.TrackUtils.revive) : [];
|
|
549
552
|
}
|
|
550
553
|
/**
|
|
551
554
|
* @returns The previous path.
|
|
@@ -569,14 +572,16 @@ class JsonQueue {
|
|
|
569
572
|
return JSON.parse(raw);
|
|
570
573
|
}
|
|
571
574
|
catch (err) {
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
575
|
+
if (err.code !== "ENOENT") {
|
|
576
|
+
const error = err instanceof MagmastreamError_1.MagmaStreamError
|
|
577
|
+
? err
|
|
578
|
+
: new MagmastreamError_1.MagmaStreamError({
|
|
579
|
+
code: Enums_1.MagmaStreamErrorCode.QUEUE_JSON_ERROR,
|
|
580
|
+
message: `Failed to read file: ${filePath}`,
|
|
581
|
+
cause: err,
|
|
582
|
+
});
|
|
583
|
+
console.error(error);
|
|
584
|
+
}
|
|
580
585
|
return null;
|
|
581
586
|
}
|
|
582
587
|
}
|
package/dist/structures/Utils.js
CHANGED
|
@@ -168,6 +168,20 @@ class TrackUtils {
|
|
|
168
168
|
static isErrorOrEmptySearchResult(result) {
|
|
169
169
|
return result.loadType === Enums_1.LoadTypes.Empty || result.loadType === Enums_1.LoadTypes.Error;
|
|
170
170
|
}
|
|
171
|
+
/**
|
|
172
|
+
* Revives a track.
|
|
173
|
+
* @param track The track to revive.
|
|
174
|
+
* @returns The revived track.
|
|
175
|
+
*/
|
|
176
|
+
static revive(track) {
|
|
177
|
+
if (!track)
|
|
178
|
+
return track;
|
|
179
|
+
track.displayThumbnail = function (size = "default") {
|
|
180
|
+
const finalSize = SIZES.find((s) => s === size) ?? "default";
|
|
181
|
+
return this.uri.includes("youtube") ? `https://img.youtube.com/vi/${this.identifier}/${finalSize}.jpg` : null;
|
|
182
|
+
}.bind(track);
|
|
183
|
+
return track;
|
|
184
|
+
}
|
|
171
185
|
}
|
|
172
186
|
exports.TrackUtils = TrackUtils;
|
|
173
187
|
class AutoPlayUtils {
|