Выбор случайного трека из предл., а не первый
This commit is contained in:
parent
d4a082fb3f
commit
f863b2147c
3 changed files with 10 additions and 40 deletions
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "discord-player-play-dl",
|
"name": "discord-player-play-dl",
|
||||||
"version": "5.3.3",
|
"version": "5.3.4",
|
||||||
"description": "Complete framework to facilitate music commands using discord.js and play-dl",
|
"description": "Complete framework to facilitate music commands using discord.js and play-dl",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
|
@ -65,8 +65,7 @@
|
||||||
"play-dl": "^1.9.5",
|
"play-dl": "^1.9.5",
|
||||||
"spotify-url-info": "^3.1.2",
|
"spotify-url-info": "^3.1.2",
|
||||||
"tiny-typed-emitter": "^2.1.0",
|
"tiny-typed-emitter": "^2.1.0",
|
||||||
"tslib": "^2.4.0",
|
"tslib": "^2.4.0"
|
||||||
"youtube-sr": "^4.3.0"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@discordjs/ts-docgen": "^0.4.1",
|
"@discordjs/ts-docgen": "^0.4.1",
|
||||||
|
|
|
@ -5,7 +5,6 @@ import Track from "./Track";
|
||||||
import { PlayerOptions, PlayerProgressbarOptions, PlayOptions, QueueFilters, QueueRepeatMode, TrackSource } from "../types/types";
|
import { PlayerOptions, PlayerProgressbarOptions, PlayOptions, QueueFilters, QueueRepeatMode, TrackSource } from "../types/types";
|
||||||
import { AudioResource, StreamType } from "@discordjs/voice";
|
import { AudioResource, StreamType } from "@discordjs/voice";
|
||||||
import play from "play-dl";
|
import play from "play-dl";
|
||||||
import YouTube from "youtube-sr";
|
|
||||||
import { Util } from "../utils/Util";
|
import { Util } from "../utils/Util";
|
||||||
import AudioFilters from "../utils/AudioFilters";
|
import AudioFilters from "../utils/AudioFilters";
|
||||||
import { PlayerError, ErrorStatusCode } from "./PlayerError";
|
import { PlayerError, ErrorStatusCode } from "./PlayerError";
|
||||||
|
@ -692,44 +691,21 @@ class Queue<T = unknown> {
|
||||||
if (this.options.leaveOnEnd) this.destroy();
|
if (this.options.leaveOnEnd) this.destroy();
|
||||||
return void this.player.emit("queueEnd", this);
|
return void this.player.emit("queueEnd", this);
|
||||||
}
|
}
|
||||||
// const info = await play.video_info(track.url).catch(Util.noop);
|
const info = await play.video_info(track.url).catch(Util.noop);
|
||||||
// if (!info) {
|
|
||||||
// if (this.options.leaveOnEnd) this.destroy();
|
|
||||||
// return void this.player.emit("queueEnd", this);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// const related = await play.video_info(info.related_videos[1]);
|
|
||||||
// const nextTrack = new Track(this.player, {
|
|
||||||
// title: related.video_details.title,
|
|
||||||
// url: related.video_details.url,
|
|
||||||
// duration: related.video_details.durationRaw ? Util.buildTimeCode(Util.parseMS(related.video_details.durationInSec * 1000)) : "0:00",
|
|
||||||
// description: "",
|
|
||||||
// thumbnail: Util.last(related.video_details.thumbnails).url,
|
|
||||||
// views: related.video_details.views,
|
|
||||||
// author: related.video_details.channel.name,
|
|
||||||
// requestedBy: track.requestedBy,
|
|
||||||
// source: "youtube"
|
|
||||||
// });
|
|
||||||
let info = await YouTube.getVideo(track.url)
|
|
||||||
.then((x) => x.videos[0])
|
|
||||||
.catch(Util.noop);
|
|
||||||
if (!info)
|
|
||||||
info = await YouTube.search(track.author)
|
|
||||||
.then((x) => x[0])
|
|
||||||
.catch(Util.noop);
|
|
||||||
if (!info) {
|
if (!info) {
|
||||||
if (this.options.leaveOnEnd) this.destroy();
|
if (this.options.leaveOnEnd) this.destroy();
|
||||||
return void this.player.emit("queueEnd", this);
|
return void this.player.emit("queueEnd", this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const related = await play.video_info(info.related_videos[Math.floor(Math.random() * info.related_videos.length + 1)]);
|
||||||
const nextTrack = new Track(this.player, {
|
const nextTrack = new Track(this.player, {
|
||||||
title: info.title,
|
title: related.video_details.title,
|
||||||
url: `https://www.youtube.com/watch?v=${info.id}`,
|
url: related.video_details.url,
|
||||||
duration: info.durationFormatted ? Util.buildTimeCode(Util.parseMS(info.duration * 1000)) : "0:00",
|
duration: related.video_details.durationRaw ? Util.buildTimeCode(Util.parseMS(related.video_details.durationInSec * 1000)) : "0:00",
|
||||||
description: "",
|
description: "",
|
||||||
thumbnail: typeof info.thumbnail === "string" ? info.thumbnail : info.thumbnail.url,
|
thumbnail: Util.last(related.video_details.thumbnails).url,
|
||||||
views: info.views,
|
views: related.video_details.views,
|
||||||
author: info.channel.name,
|
author: related.video_details.channel.name,
|
||||||
requestedBy: track.requestedBy,
|
requestedBy: track.requestedBy,
|
||||||
source: "youtube"
|
source: "youtube"
|
||||||
});
|
});
|
||||||
|
|
|
@ -1511,8 +1511,3 @@
|
||||||
"integrity" "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q=="
|
"integrity" "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q=="
|
||||||
"resolved" "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz"
|
"resolved" "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz"
|
||||||
"version" "0.1.0"
|
"version" "0.1.0"
|
||||||
|
|
||||||
"youtube-sr@^4.3.0":
|
|
||||||
"integrity" "sha512-cRMOeJZi/DYIRqru0R9UsBLwkj4tQvekldnCj4MZOT+ijlfesrllbUDXqKuA2RbYA4ByJlFf9wxZ1ndvuCJ5Ow=="
|
|
||||||
"resolved" "https://registry.npmjs.org/youtube-sr/-/youtube-sr-4.3.0.tgz"
|
|
||||||
"version" "4.3.0"
|
|
||||||
|
|
Loading…
Reference in a new issue