Merge pull request #665 from Androz2091/develop

This commit is contained in:
Androz 2021-08-08 08:51:52 +02:00 committed by GitHub
commit 32193fa739
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 37 additions and 9 deletions

3
.gitignore vendored
View file

@ -12,4 +12,5 @@ yarn*.log
# example # example
example/test example/test
example/music-bot/node_modules example/music-bot/node_modules
example/music-bot/package-lock.json example/music-bot/package-lock.json
example/music-bot/.env

View file

@ -1,3 +1,3 @@
module.exports = { module.exports = {
token: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" token: process.env.DISCORD_TOKEN
}; };

View file

@ -1,7 +1,7 @@
require("dotenv").config();
const { Client, GuildMember } = require("discord.js"); const { Client, GuildMember } = require("discord.js");
const config = require("./config"); const config = require("./config");
const { Player, QueryType, QueueRepeatMode } = require("discord-player"); const { Player, QueryType, QueueRepeatMode } = require("discord-player");
const client = new Client({ const client = new Client({
intents: ["GUILD_VOICE_STATES", "GUILD_MESSAGES", "GUILDS"] intents: ["GUILD_VOICE_STATES", "GUILD_MESSAGES", "GUILDS"]
}); });

View file

@ -10,7 +10,8 @@
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@discordjs/opus": "^0.5.3", "@discordjs/opus": "^0.5.3",
"discord-player": "^5.0.0-dev.39f503a.1625470163", "discord-player": "^5.0.0",
"discord.js": "^13.0.1" "discord.js": "^13.0.1",
"dotenv": "^10.0.0"
} }
} }

View file

@ -1,6 +1,6 @@
{ {
"name": "discord-player", "name": "discord-player",
"version": "5.0.0", "version": "5.0.1",
"description": "Complete framework to facilitate music commands using discord.js", "description": "Complete framework to facilitate music commands using discord.js",
"main": "dist/index.js", "main": "dist/index.js",
"types": "dist/index.d.ts", "types": "dist/index.d.ts",
@ -26,7 +26,7 @@
}, },
"funding": "https://github.com/Androz2091/discord-player?sponsor=1", "funding": "https://github.com/Androz2091/discord-player?sponsor=1",
"contributors": [ "contributors": [
"Snowflake107" "DevAndromeda <devandromeda@snowflakedev.org>"
], ],
"repository": { "repository": {
"type": "git", "type": "git",

View file

@ -9,6 +9,7 @@ import YouTube from "youtube-sr";
import { Util } from "./utils/Util"; import { Util } from "./utils/Util";
import Spotify from "spotify-url-info"; import Spotify from "spotify-url-info";
import { PlayerError, ErrorStatusCode } from "./Structures/PlayerError"; import { PlayerError, ErrorStatusCode } from "./Structures/PlayerError";
import { getInfo as ytdlGetInfo } from "ytdl-core";
// eslint-disable-next-line @typescript-eslint/ban-ts-comment // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore // @ts-ignore
import { Client as SoundCloud } from "soundcloud-scraper"; import { Client as SoundCloud } from "soundcloud-scraper";
@ -220,6 +221,25 @@ class Player extends EventEmitter<PlayerEvents> {
const qt = options.searchEngine === QueryType.AUTO ? QueryResolver.resolve(query) : options.searchEngine; const qt = options.searchEngine === QueryType.AUTO ? QueryResolver.resolve(query) : options.searchEngine;
switch (qt) { switch (qt) {
case QueryType.YOUTUBE_VIDEO: {
const info = await ytdlGetInfo(query).catch(Util.noop);
if (!info) return { playlist: null, tracks: [] };
const track = new Track(this, {
title: info.videoDetails.title,
description: info.videoDetails.description,
author: info.videoDetails.author?.name,
url: info.videoDetails.video_url,
requestedBy: options.requestedBy as User,
thumbnail: Util.last(info.videoDetails.thumbnails)?.url,
views: parseInt(info.videoDetails.viewCount.replace(/[^0-9]/g, "")) || 0,
duration: Util.buildTimeCode(Util.parseMS(parseInt(info.videoDetails.lengthSeconds) * 1000)),
source: "youtube",
raw: info
});
return { playlist: null, tracks: [track] };
}
case QueryType.YOUTUBE_SEARCH: { case QueryType.YOUTUBE_SEARCH: {
const videos = await YouTube.search(query, { const videos = await YouTube.search(query, {
type: "video" type: "video"
@ -237,6 +257,7 @@ class Player extends EventEmitter<PlayerEvents> {
thumbnail: m.thumbnail?.displayThumbnailURL("maxresdefault"), thumbnail: m.thumbnail?.displayThumbnailURL("maxresdefault"),
views: m.views, views: m.views,
duration: m.durationFormatted, duration: m.durationFormatted,
source: "youtube",
raw: m raw: m
}); });
}); });

View file

@ -6,7 +6,10 @@ export { PlayerError, ErrorStatusCode } from "./Structures/PlayerError";
export { QueryResolver } from "./utils/QueryResolver"; export { QueryResolver } from "./utils/QueryResolver";
export { Queue } from "./Structures/Queue"; export { Queue } from "./Structures/Queue";
export { Track } from "./Structures/Track"; export { Track } from "./Structures/Track";
export { Util } from "./utils/Util";
export { VoiceUtils } from "./VoiceInterface/VoiceUtils"; export { VoiceUtils } from "./VoiceInterface/VoiceUtils";
export { VoiceEvents, StreamDispatcher } from "./VoiceInterface/StreamDispatcher"; export { VoiceEvents, StreamDispatcher } from "./VoiceInterface/StreamDispatcher";
export { Util } from "./utils/Util";
export * from "./types/types"; export * from "./types/types";
// eslint-disable-next-line @typescript-eslint/no-var-requires
export const version: string = require(`${__dirname}/../package.json`).version;

View file

@ -216,6 +216,7 @@ export interface ExtractorModelData {
* - ARBITRARY * - ARBITRARY
* - REVERBNATION * - REVERBNATION
* - YOUTUBE_SEARCH * - YOUTUBE_SEARCH
* - YOUTUBE_VIDEO
* - SOUNDCLOUD_SEARCH * - SOUNDCLOUD_SEARCH
* @typedef {string} QueryType * @typedef {string} QueryType
*/ */
@ -234,6 +235,7 @@ export enum QueryType {
ARBITRARY = "arbitrary", ARBITRARY = "arbitrary",
REVERBNATION = "reverbnation", REVERBNATION = "reverbnation",
YOUTUBE_SEARCH = "youtube_search", YOUTUBE_SEARCH = "youtube_search",
YOUTUBE_VIDEO = "youtube_video",
SOUNDCLOUD_SEARCH = "soundcloud_search" SOUNDCLOUD_SEARCH = "soundcloud_search"
} }

View file

@ -31,7 +31,7 @@ class QueryResolver {
if (SoundcloudValidateURL(query, "track")) return QueryType.SOUNDCLOUD_TRACK; if (SoundcloudValidateURL(query, "track")) return QueryType.SOUNDCLOUD_TRACK;
if (SoundcloudValidateURL(query, "playlist") || query.includes("/sets/")) return QueryType.SOUNDCLOUD_PLAYLIST; if (SoundcloudValidateURL(query, "playlist") || query.includes("/sets/")) return QueryType.SOUNDCLOUD_PLAYLIST;
if (YouTube.isPlaylist(query)) return QueryType.YOUTUBE_PLAYLIST; if (YouTube.isPlaylist(query)) return QueryType.YOUTUBE_PLAYLIST;
if (validateID(query) || validateURL(query)) return QueryType.YOUTUBE_SEARCH; if (validateID(query) || validateURL(query)) return QueryType.YOUTUBE_VIDEO;
if (spotifySongRegex.test(query)) return QueryType.SPOTIFY_SONG; if (spotifySongRegex.test(query)) return QueryType.SPOTIFY_SONG;
if (spotifyPlaylistRegex.test(query)) return QueryType.SPOTIFY_PLAYLIST; if (spotifyPlaylistRegex.test(query)) return QueryType.SPOTIFY_PLAYLIST;
if (spotifyAlbumRegex.test(query)) return QueryType.SPOTIFY_ALBUM; if (spotifyAlbumRegex.test(query)) return QueryType.SPOTIFY_ALBUM;