Skip to content

Commit

Permalink
Merge branch 'main' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
XzFirzal committed Sep 8, 2021
2 parents d805f69 + 861913c commit 9d80601
Show file tree
Hide file tree
Showing 31 changed files with 611 additions and 123 deletions.
2 changes: 1 addition & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const fs_1 = require("fs");
/**
* The current installed version of the package
*/
exports.version = JSON.parse(fs_1.readFileSync("package.json", "utf-8")).version;
exports.version = JSON.parse(fs_1.readFileSync(require.resolve("../package.json"), "utf-8")).version;
__exportStar(require("./audio/AudioManager"), exports);
__exportStar(require("./audio/AudioPlayer"), exports);
__exportStar(require("./audio/AudioPlayerImpl"), exports);
Expand Down
46 changes: 22 additions & 24 deletions dist/queue/QueueManager.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.QueueManager = void 0;
const youtube_sr_1 = __importDefault(require("youtube-sr"));
exports.QueueManager = exports.VIDEO_URL = exports.PLAYLIST_URL = void 0;
const Track_1 = require("./Track");
const QueueHandler_1 = require("./QueueHandler");
const tiny_typed_emitter_1 = require("tiny-typed-emitter");
const AudioManager_1 = require("../audio/AudioManager");
const validation_1 = require("../validation");
const youtube_scrapper_1 = require("youtube-scrapper");
/**
* A RegExp instance to identify youtube playlist url
*/
exports.PLAYLIST_URL = /^(http|https)?:\/\/(www.)?youtube.com\/playlist\?list=((PL|UU|LL|RD|OL)[a-zA-Z0-9-_]{16,41})$/;
/**
* A RegExp instance to identify youtube video url
*/
// eslint-disable-next-line no-useless-escape
exports.VIDEO_URL = /^(http|https)?:\/\/?((?:www|m)\.)?((?:youtube\.com|youtu.be))(\/(?:[\w\-]+\?v=|embed\/|v\/)?)([\w\-]+)(\S+)?$/;
/**
* The manager of queue handler
*
Expand Down Expand Up @@ -88,26 +94,22 @@ class QueueManager extends tiny_typed_emitter_1.TypedEmitter {
async youtubeSearch(options) {
validation_1.QueueManagerValidation.validateYoutubeSearchOptions(options);
const tracks = [];
const type = youtube_sr_1.default.Regex.VIDEO_URL.test(options.query)
? "video"
: youtube_sr_1.default.Regex.PLAYLIST_URL.test(options.query)
? "playlist"
const type = exports.PLAYLIST_URL.test(options.query)
? "playlist"
: exports.VIDEO_URL.test(options.query)
? "video"
: "search";
if (type === "video") {
const video = await youtube_sr_1.default.getVideo(options.query);
const { details } = await youtube_scrapper_1.getVideoInfo(options.query);
tracks.push(new Track_1.Track({
sourceType: 0,
urlOrLocation: video.url,
metadata: video
urlOrLocation: details.url,
metadata: details
}));
}
else if (type === "playlist") {
const limit = options.playlistLimit ?? 100;
const playlist = await youtube_sr_1.default.getPlaylist(options.query, { limit });
await playlist.fetch();
for (const video of playlist) {
if (tracks.length >= limit)
break;
const playlist = await youtube_scrapper_1.getPlaylistInfo(options.query, { full: options.fullPlaylist ?? false });
for (const video of playlist.tracks) {
tracks.push(new Track_1.Track({
sourceType: 0,
urlOrLocation: video.url,
Expand All @@ -116,12 +118,8 @@ class QueueManager extends tiny_typed_emitter_1.TypedEmitter {
}
}
else {
const searchResult = await youtube_sr_1.default.search(options.query, {
limit: options.searchLimit ?? 1,
type: "video",
safeSearch: true
});
for (const video of searchResult) {
const searchResult = await youtube_scrapper_1.search(options.query);
for (const video of searchResult.videos) {
tracks.push(new Track_1.Track({
sourceType: 0,
urlOrLocation: video.url,
Expand Down
6 changes: 2 additions & 4 deletions dist/validation/QueueManagerValidation.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ function validateYoutubeSearchOptions(options) {
throw new PlayerError_1.PlayerError(PlayerError_1.ErrorMessages.NotProvided("query", "YoutubeSearchOptions"));
else if (typeof options.query !== "string")
throw new PlayerError_1.PlayerError(PlayerError_1.ErrorMessages.Expecting("string", "YoutubeSearchOptions.query", typeof options.query));
if ("searchLimit" in options && typeof options.searchLimit !== "number")
throw new PlayerError_1.PlayerError(PlayerError_1.ErrorMessages.Expecting("number", "YoutubeSearchOptions.searchLimit", typeof options.searchLimit));
if ("playlistLimit" in options && typeof options.playlistLimit !== "number")
throw new PlayerError_1.PlayerError(PlayerError_1.ErrorMessages.Expecting("number", "YoutubeSearchOptions.playlistLimit", typeof options.playlistLimit));
if ("fullPlaylist" in options && typeof options.fullPlaylist !== "boolean")
throw new PlayerError_1.PlayerError(PlayerError_1.ErrorMessages.Expecting("boolean", "YoutubeSearchOptions.fullPlaylist", typeof options.fullPlaylist));
}
exports.validateYoutubeSearchOptions = validateYoutubeSearchOptions;
function validateSoundcloudSearchOptions(options) {
Expand Down
2 changes: 1 addition & 1 deletion docs/assets/js/search.js

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion docs/classes/AudioManager.html
Original file line number Diff line number Diff line change
Expand Up @@ -430,9 +430,12 @@ <h4 class="tsd-returns-title">Returns <a href="../interfaces/AudioPlayer.html" c
<li class=" tsd-kind-interface">
<a href="../interfaces/youtubeSearchOptions.html" class="tsd-kind-icon">youtube<wbr>Search<wbr>Options</a>
</li>
<li class=" tsd-kind-interface">
<li class=" tsd-kind-interface tsd-has-type-parameter">
<a href="../interfaces/youtubeSearchResult.html" class="tsd-kind-icon">youtube<wbr>Search<wbr>Result</a>
</li>
<li class=" tsd-kind-interface">
<a href="../interfaces/youtubeVideoType.html" class="tsd-kind-icon">youtube<wbr>Video<wbr>Type</a>
</li>
<li class=" tsd-kind-type-alias">
<a href="../modules.html#AudioManagerResolvable" class="tsd-kind-icon">Audio<wbr>Manager<wbr>Resolvable</a>
</li>
Expand All @@ -448,6 +451,12 @@ <h4 class="tsd-returns-title">Returns <a href="../interfaces/AudioPlayer.html" c
<li class=" tsd-kind-type-alias">
<a href="../modules.html#youtubeSearchResultType" class="tsd-kind-icon">youtube<wbr>Search<wbr>Result<wbr>Type</a>
</li>
<li class=" tsd-kind-variable">
<a href="../modules.html#PLAYLIST_URL" class="tsd-kind-icon">PLAYLIST_<wbr>URL</a>
</li>
<li class=" tsd-kind-variable">
<a href="../modules.html#VIDEO_URL" class="tsd-kind-icon">VIDEO_<wbr>URL</a>
</li>
<li class=" tsd-kind-variable">
<a href="../modules.html#version" class="tsd-kind-icon">version</a>
</li>
Expand Down
11 changes: 10 additions & 1 deletion docs/classes/AudioPlayerImpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,12 @@ <h3><span class="tsd-flag ts-flagStatic">Static</span> UNPAUSE</h3>
<li class=" tsd-kind-interface">
<a href="../interfaces/youtubeSearchOptions.html" class="tsd-kind-icon">youtube<wbr>Search<wbr>Options</a>
</li>
<li class=" tsd-kind-interface">
<li class=" tsd-kind-interface tsd-has-type-parameter">
<a href="../interfaces/youtubeSearchResult.html" class="tsd-kind-icon">youtube<wbr>Search<wbr>Result</a>
</li>
<li class=" tsd-kind-interface">
<a href="../interfaces/youtubeVideoType.html" class="tsd-kind-icon">youtube<wbr>Video<wbr>Type</a>
</li>
<li class=" tsd-kind-type-alias">
<a href="../modules.html#AudioManagerResolvable" class="tsd-kind-icon">Audio<wbr>Manager<wbr>Resolvable</a>
</li>
Expand All @@ -284,6 +287,12 @@ <h3><span class="tsd-flag ts-flagStatic">Static</span> UNPAUSE</h3>
<li class=" tsd-kind-type-alias">
<a href="../modules.html#youtubeSearchResultType" class="tsd-kind-icon">youtube<wbr>Search<wbr>Result<wbr>Type</a>
</li>
<li class=" tsd-kind-variable">
<a href="../modules.html#PLAYLIST_URL" class="tsd-kind-icon">PLAYLIST_<wbr>URL</a>
</li>
<li class=" tsd-kind-variable">
<a href="../modules.html#VIDEO_URL" class="tsd-kind-icon">VIDEO_<wbr>URL</a>
</li>
<li class=" tsd-kind-variable">
<a href="../modules.html#version" class="tsd-kind-icon">version</a>
</li>
Expand Down
11 changes: 10 additions & 1 deletion docs/classes/Cache.html
Original file line number Diff line number Diff line change
Expand Up @@ -526,9 +526,12 @@ <h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</spa
<li class=" tsd-kind-interface">
<a href="../interfaces/youtubeSearchOptions.html" class="tsd-kind-icon">youtube<wbr>Search<wbr>Options</a>
</li>
<li class=" tsd-kind-interface">
<li class=" tsd-kind-interface tsd-has-type-parameter">
<a href="../interfaces/youtubeSearchResult.html" class="tsd-kind-icon">youtube<wbr>Search<wbr>Result</a>
</li>
<li class=" tsd-kind-interface">
<a href="../interfaces/youtubeVideoType.html" class="tsd-kind-icon">youtube<wbr>Video<wbr>Type</a>
</li>
<li class=" tsd-kind-type-alias">
<a href="../modules.html#AudioManagerResolvable" class="tsd-kind-icon">Audio<wbr>Manager<wbr>Resolvable</a>
</li>
Expand All @@ -544,6 +547,12 @@ <h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</spa
<li class=" tsd-kind-type-alias">
<a href="../modules.html#youtubeSearchResultType" class="tsd-kind-icon">youtube<wbr>Search<wbr>Result<wbr>Type</a>
</li>
<li class=" tsd-kind-variable">
<a href="../modules.html#PLAYLIST_URL" class="tsd-kind-icon">PLAYLIST_<wbr>URL</a>
</li>
<li class=" tsd-kind-variable">
<a href="../modules.html#VIDEO_URL" class="tsd-kind-icon">VIDEO_<wbr>URL</a>
</li>
<li class=" tsd-kind-variable">
<a href="../modules.html#version" class="tsd-kind-icon">version</a>
</li>
Expand Down
11 changes: 10 additions & 1 deletion docs/classes/CacheManagerImpl.html
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,12 @@ <h3>Implements</h3>
<li class=" tsd-kind-interface">
<a href="../interfaces/youtubeSearchOptions.html" class="tsd-kind-icon">youtube<wbr>Search<wbr>Options</a>
</li>
<li class=" tsd-kind-interface">
<li class=" tsd-kind-interface tsd-has-type-parameter">
<a href="../interfaces/youtubeSearchResult.html" class="tsd-kind-icon">youtube<wbr>Search<wbr>Result</a>
</li>
<li class=" tsd-kind-interface">
<a href="../interfaces/youtubeVideoType.html" class="tsd-kind-icon">youtube<wbr>Video<wbr>Type</a>
</li>
<li class=" tsd-kind-type-alias">
<a href="../modules.html#AudioManagerResolvable" class="tsd-kind-icon">Audio<wbr>Manager<wbr>Resolvable</a>
</li>
Expand All @@ -186,6 +189,12 @@ <h3>Implements</h3>
<li class=" tsd-kind-type-alias">
<a href="../modules.html#youtubeSearchResultType" class="tsd-kind-icon">youtube<wbr>Search<wbr>Result<wbr>Type</a>
</li>
<li class=" tsd-kind-variable">
<a href="../modules.html#PLAYLIST_URL" class="tsd-kind-icon">PLAYLIST_<wbr>URL</a>
</li>
<li class=" tsd-kind-variable">
<a href="../modules.html#VIDEO_URL" class="tsd-kind-icon">VIDEO_<wbr>URL</a>
</li>
<li class=" tsd-kind-variable">
<a href="../modules.html#version" class="tsd-kind-icon">version</a>
</li>
Expand Down
11 changes: 10 additions & 1 deletion docs/classes/CacheReader.html
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,12 @@ <h3>packet<wbr>Read</h3>
<li class=" tsd-kind-interface">
<a href="../interfaces/youtubeSearchOptions.html" class="tsd-kind-icon">youtube<wbr>Search<wbr>Options</a>
</li>
<li class=" tsd-kind-interface">
<li class=" tsd-kind-interface tsd-has-type-parameter">
<a href="../interfaces/youtubeSearchResult.html" class="tsd-kind-icon">youtube<wbr>Search<wbr>Result</a>
</li>
<li class=" tsd-kind-interface">
<a href="../interfaces/youtubeVideoType.html" class="tsd-kind-icon">youtube<wbr>Video<wbr>Type</a>
</li>
<li class=" tsd-kind-type-alias">
<a href="../modules.html#AudioManagerResolvable" class="tsd-kind-icon">Audio<wbr>Manager<wbr>Resolvable</a>
</li>
Expand All @@ -278,6 +281,12 @@ <h3>packet<wbr>Read</h3>
<li class=" tsd-kind-type-alias">
<a href="../modules.html#youtubeSearchResultType" class="tsd-kind-icon">youtube<wbr>Search<wbr>Result<wbr>Type</a>
</li>
<li class=" tsd-kind-variable">
<a href="../modules.html#PLAYLIST_URL" class="tsd-kind-icon">PLAYLIST_<wbr>URL</a>
</li>
<li class=" tsd-kind-variable">
<a href="../modules.html#VIDEO_URL" class="tsd-kind-icon">VIDEO_<wbr>URL</a>
</li>
<li class=" tsd-kind-variable">
<a href="../modules.html#version" class="tsd-kind-icon">version</a>
</li>
Expand Down
11 changes: 10 additions & 1 deletion docs/classes/CacheWriter.html
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,12 @@ <h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</spa
<li class=" tsd-kind-interface">
<a href="../interfaces/youtubeSearchOptions.html" class="tsd-kind-icon">youtube<wbr>Search<wbr>Options</a>
</li>
<li class=" tsd-kind-interface">
<li class=" tsd-kind-interface tsd-has-type-parameter">
<a href="../interfaces/youtubeSearchResult.html" class="tsd-kind-icon">youtube<wbr>Search<wbr>Result</a>
</li>
<li class=" tsd-kind-interface">
<a href="../interfaces/youtubeVideoType.html" class="tsd-kind-icon">youtube<wbr>Video<wbr>Type</a>
</li>
<li class=" tsd-kind-type-alias">
<a href="../modules.html#AudioManagerResolvable" class="tsd-kind-icon">Audio<wbr>Manager<wbr>Resolvable</a>
</li>
Expand All @@ -307,6 +310,12 @@ <h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</spa
<li class=" tsd-kind-type-alias">
<a href="../modules.html#youtubeSearchResultType" class="tsd-kind-icon">youtube<wbr>Search<wbr>Result<wbr>Type</a>
</li>
<li class=" tsd-kind-variable">
<a href="../modules.html#PLAYLIST_URL" class="tsd-kind-icon">PLAYLIST_<wbr>URL</a>
</li>
<li class=" tsd-kind-variable">
<a href="../modules.html#VIDEO_URL" class="tsd-kind-icon">VIDEO_<wbr>URL</a>
</li>
<li class=" tsd-kind-variable">
<a href="../modules.html#version" class="tsd-kind-icon">version</a>
</li>
Expand Down
11 changes: 10 additions & 1 deletion docs/classes/PacketReader.html
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,12 @@ <h4 class="tsd-returns-title">Returns <a href="PacketReader.html" class="tsd-sig
<li class=" tsd-kind-interface">
<a href="../interfaces/youtubeSearchOptions.html" class="tsd-kind-icon">youtube<wbr>Search<wbr>Options</a>
</li>
<li class=" tsd-kind-interface">
<li class=" tsd-kind-interface tsd-has-type-parameter">
<a href="../interfaces/youtubeSearchResult.html" class="tsd-kind-icon">youtube<wbr>Search<wbr>Result</a>
</li>
<li class=" tsd-kind-interface">
<a href="../interfaces/youtubeVideoType.html" class="tsd-kind-icon">youtube<wbr>Video<wbr>Type</a>
</li>
<li class=" tsd-kind-type-alias">
<a href="../modules.html#AudioManagerResolvable" class="tsd-kind-icon">Audio<wbr>Manager<wbr>Resolvable</a>
</li>
Expand All @@ -235,6 +238,12 @@ <h4 class="tsd-returns-title">Returns <a href="PacketReader.html" class="tsd-sig
<li class=" tsd-kind-type-alias">
<a href="../modules.html#youtubeSearchResultType" class="tsd-kind-icon">youtube<wbr>Search<wbr>Result<wbr>Type</a>
</li>
<li class=" tsd-kind-variable">
<a href="../modules.html#PLAYLIST_URL" class="tsd-kind-icon">PLAYLIST_<wbr>URL</a>
</li>
<li class=" tsd-kind-variable">
<a href="../modules.html#VIDEO_URL" class="tsd-kind-icon">VIDEO_<wbr>URL</a>
</li>
<li class=" tsd-kind-variable">
<a href="../modules.html#version" class="tsd-kind-icon">version</a>
</li>
Expand Down
11 changes: 10 additions & 1 deletion docs/classes/Queue.html
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,12 @@ <h4 class="tsd-returns-title">Returns <a href="Queue.html" class="tsd-signature-
<li class=" tsd-kind-interface">
<a href="../interfaces/youtubeSearchOptions.html" class="tsd-kind-icon">youtube<wbr>Search<wbr>Options</a>
</li>
<li class=" tsd-kind-interface">
<li class=" tsd-kind-interface tsd-has-type-parameter">
<a href="../interfaces/youtubeSearchResult.html" class="tsd-kind-icon">youtube<wbr>Search<wbr>Result</a>
</li>
<li class=" tsd-kind-interface">
<a href="../interfaces/youtubeVideoType.html" class="tsd-kind-icon">youtube<wbr>Video<wbr>Type</a>
</li>
<li class=" tsd-kind-type-alias">
<a href="../modules.html#AudioManagerResolvable" class="tsd-kind-icon">Audio<wbr>Manager<wbr>Resolvable</a>
</li>
Expand All @@ -439,6 +442,12 @@ <h4 class="tsd-returns-title">Returns <a href="Queue.html" class="tsd-signature-
<li class=" tsd-kind-type-alias">
<a href="../modules.html#youtubeSearchResultType" class="tsd-kind-icon">youtube<wbr>Search<wbr>Result<wbr>Type</a>
</li>
<li class=" tsd-kind-variable">
<a href="../modules.html#PLAYLIST_URL" class="tsd-kind-icon">PLAYLIST_<wbr>URL</a>
</li>
<li class=" tsd-kind-variable">
<a href="../modules.html#VIDEO_URL" class="tsd-kind-icon">VIDEO_<wbr>URL</a>
</li>
<li class=" tsd-kind-variable">
<a href="../modules.html#version" class="tsd-kind-icon">version</a>
</li>
Expand Down
11 changes: 10 additions & 1 deletion docs/classes/QueueHandler.html
Original file line number Diff line number Diff line change
Expand Up @@ -767,9 +767,12 @@ <h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</spa
<li class=" tsd-kind-interface">
<a href="../interfaces/youtubeSearchOptions.html" class="tsd-kind-icon">youtube<wbr>Search<wbr>Options</a>
</li>
<li class=" tsd-kind-interface">
<li class=" tsd-kind-interface tsd-has-type-parameter">
<a href="../interfaces/youtubeSearchResult.html" class="tsd-kind-icon">youtube<wbr>Search<wbr>Result</a>
</li>
<li class=" tsd-kind-interface">
<a href="../interfaces/youtubeVideoType.html" class="tsd-kind-icon">youtube<wbr>Video<wbr>Type</a>
</li>
<li class=" tsd-kind-type-alias">
<a href="../modules.html#AudioManagerResolvable" class="tsd-kind-icon">Audio<wbr>Manager<wbr>Resolvable</a>
</li>
Expand All @@ -785,6 +788,12 @@ <h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</spa
<li class=" tsd-kind-type-alias">
<a href="../modules.html#youtubeSearchResultType" class="tsd-kind-icon">youtube<wbr>Search<wbr>Result<wbr>Type</a>
</li>
<li class=" tsd-kind-variable">
<a href="../modules.html#PLAYLIST_URL" class="tsd-kind-icon">PLAYLIST_<wbr>URL</a>
</li>
<li class=" tsd-kind-variable">
<a href="../modules.html#VIDEO_URL" class="tsd-kind-icon">VIDEO_<wbr>URL</a>
</li>
<li class=" tsd-kind-variable">
<a href="../modules.html#version" class="tsd-kind-icon">version</a>
</li>
Expand Down
11 changes: 10 additions & 1 deletion docs/classes/Track.html
Original file line number Diff line number Diff line change
Expand Up @@ -568,9 +568,12 @@ <h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</spa
<li class=" tsd-kind-interface">
<a href="../interfaces/youtubeSearchOptions.html" class="tsd-kind-icon">youtube<wbr>Search<wbr>Options</a>
</li>
<li class=" tsd-kind-interface">
<li class=" tsd-kind-interface tsd-has-type-parameter">
<a href="../interfaces/youtubeSearchResult.html" class="tsd-kind-icon">youtube<wbr>Search<wbr>Result</a>
</li>
<li class=" tsd-kind-interface">
<a href="../interfaces/youtubeVideoType.html" class="tsd-kind-icon">youtube<wbr>Video<wbr>Type</a>
</li>
<li class=" tsd-kind-type-alias">
<a href="../modules.html#AudioManagerResolvable" class="tsd-kind-icon">Audio<wbr>Manager<wbr>Resolvable</a>
</li>
Expand All @@ -586,6 +589,12 @@ <h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</spa
<li class=" tsd-kind-type-alias">
<a href="../modules.html#youtubeSearchResultType" class="tsd-kind-icon">youtube<wbr>Search<wbr>Result<wbr>Type</a>
</li>
<li class=" tsd-kind-variable">
<a href="../modules.html#PLAYLIST_URL" class="tsd-kind-icon">PLAYLIST_<wbr>URL</a>
</li>
<li class=" tsd-kind-variable">
<a href="../modules.html#VIDEO_URL" class="tsd-kind-icon">VIDEO_<wbr>URL</a>
</li>
<li class=" tsd-kind-variable">
<a href="../modules.html#version" class="tsd-kind-icon">version</a>
</li>
Expand Down
Loading

0 comments on commit 9d80601

Please sign in to comment.