Merge pull request #214 from play-dl/developer

1.6.3
This commit is contained in:
Killer069 2021-12-24 12:44:05 +05:30 committed by GitHub
commit ee8f8b9686
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 169 additions and 55 deletions

70
.github/discord.js vendored Normal file
View File

@ -0,0 +1,70 @@
const bot_token = process.env['BOT_TOKEN']
const { request } = require('https')
let tag = undefined, body = undefined, channel = undefined;
process.argv.forEach((arg) => {
const [ key, value ] = arg.split('=')
if(key === 'tag') tag = value
if(key === 'body') body = value
if(key === 'channel') channel = value
})
if(!tag || !body || !channel) {
console.log(`Some args are missing`)
process.exit(1)
}
else if(!bot_token) {
console.log('Bot Token is missing')
process.exit(1)
};
(async() => {
const body_args = body.replaceAll('\r', '').split('- [x]')
body_args.shift()
body_args.unshift('**Change Log :-**\n')
const description = body_args.join('\n<a:tick:893093621623037972>')
const embed = {
title : tag,
url : `https://github.com/play-dl/play-dl/releases/tag/${tag}`,
description : description,
color : 0x00FF00
}
const payload = {
embeds : [embed]
}
console.log(payload)
const x = await https_getter(`https://discord.com/api/v9/channels/${channel}/messages`, {
headers : {
"Authorization" : `Bot ${bot_token}`,
"content-type" : "application/json"
},
method : "POST",
body : JSON.stringify(payload)
})
console.log(x.statusCode)
process.exit(0)
})()
function https_getter(req_url, options = {}) {
return new Promise((resolve, reject) => {
const s = new URL(req_url);
options.method ??= 'GET';
const req_options = {
host: s.hostname,
path: s.pathname + s.search,
headers: options.headers ?? {},
method: options.method
};
const req = request(req_options, resolve);
req.on('error', (err) => {
reject(err);
});
if (options.method === 'POST') req.write(options.body);
req.end();
});
}

12
.github/docs.js vendored Normal file
View File

@ -0,0 +1,12 @@
const fs = require('fs')
const path = "play-dl/index.ts"
if(!fs.existsSync(path)) {
console.log('File Missing')
process.exit(1)
}
const oldData = fs.readFileSync(path, 'utf-8')
fs.writeFileSync(path, oldData.split('// Export Default ')[0])

View File

@ -42,6 +42,9 @@ jobs:
- name: Install Dependencies - name: Install Dependencies
run: npm install run: npm install
- name: Deleting default exports for ESM.
run: node .github/docs.js
- name: TypeDoc - name: TypeDoc
run: npx typedoc run: npx typedoc
@ -53,3 +56,17 @@ jobs:
git add * git add *
git commit -m "Automated Docs" git commit -m "Automated Docs"
git push git push
publish_discord:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 16
registry-url: 'https://registry.npmjs.org'
- name: Publish on discord
run: node .github/discord.js channel="888999793458835466" body="${{ github.event.release.body }}" tag="${{ github.event.release.tag_name }}"
env:
BOT_TOKEN: ${{ secrets.BOT_TOKEN }}

View File

@ -16,7 +16,7 @@ const video_id_pattern = /^[a-zA-Z\d_-]{11,12}$/;
const playlist_id_pattern = /^(PL|UU|LL|RD|OL)[a-zA-Z\d_-]{10,}$/; const playlist_id_pattern = /^(PL|UU|LL|RD|OL)[a-zA-Z\d_-]{10,}$/;
const DEFAULT_API_KEY = 'AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8'; const DEFAULT_API_KEY = 'AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8';
const video_pattern = const video_pattern =
/^((?:https?:)?\/\/)?(?:(?:www|m)\.)?((?:youtube\.com|youtu.be))(\/(?:[\w\-]+\?v=|shorts\/|embed\/|v\/)?)([\w\-]+)(\S+)?$/; /^((?:https?:)?\/\/)?(?:(?:www|m|music)\.)?((?:youtube\.com|youtu.be))(\/(?:[\w\-]+\?v=|shorts\/|embed\/|v\/)?)([\w\-]+)(\S+)?$/;
const playlist_pattern = const playlist_pattern =
/^((?:https?:)?\/\/)?(?:(?:www|m)\.)?(youtube\.com)\/(?:(playlist|watch))(.*)?((\?|\&)list=)(PL|UU|LL|RD|OL)[a-zA-Z\d_-]{10,}(.*)?$/; /^((?:https?:)?\/\/)?(?:(?:www|m)\.)?(youtube\.com)\/(?:(playlist|watch))(.*)?((\?|\&)list=)(PL|UU|LL|RD|OL)[a-zA-Z\d_-]{10,}(.*)?$/;
/** /**

View File

@ -1,4 +1,4 @@
export { import {
playlist_info, playlist_info,
video_basic_info, video_basic_info,
video_info, video_info,
@ -11,7 +11,7 @@ export {
YouTubePlayList, YouTubePlayList,
YouTubeVideo YouTubeVideo
} from './YouTube'; } from './YouTube';
export { import {
spotify, spotify,
sp_validate, sp_validate,
refreshToken, refreshToken,
@ -19,27 +19,34 @@ export {
SpotifyAlbum, SpotifyAlbum,
SpotifyPlaylist, SpotifyPlaylist,
SpotifyTrack, SpotifyTrack,
Spotify Spotify,
SpotifyAuthorize,
sp_search
} from './Spotify'; } from './Spotify';
export { import {
soundcloud, soundcloud,
so_validate, so_validate,
SoundCloud, SoundCloud,
SoundCloudStream, SoundCloudStream,
getFreeClientID, getFreeClientID,
SoundCloudPlaylist, SoundCloudPlaylist,
SoundCloudTrack SoundCloudTrack,
check_id,
so_search,
stream as so_stream,
stream_from_info as so_stream_info
} from './SoundCloud'; } from './SoundCloud';
export { import {
deezer, deezer,
dz_validate, dz_validate,
dz_advanced_track_search, dz_advanced_track_search,
Deezer, Deezer,
DeezerTrack, DeezerTrack,
DeezerPlaylist, DeezerPlaylist,
DeezerAlbum DeezerAlbum,
dz_search
} from './Deezer'; } from './Deezer';
export { setToken } from './token'; import { setToken } from './token';
enum AudioPlayerStatus { enum AudioPlayerStatus {
Idle = 'idle', Idle = 'idle',
@ -62,35 +69,16 @@ interface SearchOptions {
import { createInterface } from 'node:readline'; import { createInterface } from 'node:readline';
import { existsSync, mkdirSync, writeFileSync } from 'node:fs'; import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
import {
sp_validate,
yt_validate,
so_validate,
YouTubeStream,
SoundCloudStream,
YouTube,
SoundCloud,
Spotify
} from '.';
import { SpotifyAuthorize, sp_search } from './Spotify';
import { check_id, so_search, stream as so_stream, stream_from_info as so_stream_info } from './SoundCloud';
import { stream as yt_stream, StreamOptions, stream_from_info as yt_stream_info } from './YouTube/stream'; import { stream as yt_stream, StreamOptions, stream_from_info as yt_stream_info } from './YouTube/stream';
import { SoundCloudPlaylist, SoundCloudTrack } from './SoundCloud/classes';
import { yt_search } from './YouTube/search'; import { yt_search } from './YouTube/search';
import { EventEmitter } from 'stream'; import { EventEmitter } from 'stream';
import { Deezer, dz_search, dz_validate } from './Deezer';
import { InfoData } from './YouTube/utils/constants'; import { InfoData } from './YouTube/utils/constants';
import { YouTubeVideo } from './YouTube/classes/Video';
import { YouTubePlayList } from './YouTube/classes/Playlist';
import { YouTubeChannel } from './YouTube/classes/Channel';
import { SpotifyAlbum, SpotifyPlaylist, SpotifyTrack } from './Spotify/classes';
import { DeezerAlbum, DeezerPlaylist, DeezerTrack } from './Deezer/classes';
export async function stream( async function stream(
url: string, url: string,
options: { seek?: number; seekMode?: 'precise' | 'granular' } & StreamOptions options: { seek?: number; seekMode?: 'precise' | 'granular' } & StreamOptions
): Promise<YouTubeStream>; ): Promise<YouTubeStream>;
export async function stream(url: string, options?: StreamOptions): Promise<YouTubeStream | SoundCloudStream>; async function stream(url: string, options?: StreamOptions): Promise<YouTubeStream | SoundCloudStream>;
/** /**
* Creates a Stream [ YouTube or SoundCloud ] class from a url for playing. * Creates a Stream [ YouTube or SoundCloud ] class from a url for playing.
* *
@ -118,7 +106,7 @@ export async function stream(url: string, options?: StreamOptions): Promise<YouT
* - `boolean` htmldata : given data is html data or not * - `boolean` htmldata : given data is html data or not
* @returns A {@link YouTubeStream} or {@link SoundCloudStream} Stream to play * @returns A {@link YouTubeStream} or {@link SoundCloudStream} Stream to play
*/ */
export async function stream(url: string, options: StreamOptions = {}): Promise<YouTubeStream | SoundCloudStream> { async function stream(url: string, options: StreamOptions = {}): Promise<YouTubeStream | SoundCloudStream> {
if (url.length === 0) throw new Error('Stream URL has a length of 0. Check your url again.'); if (url.length === 0) throw new Error('Stream URL has a length of 0. Check your url again.');
if (options.htmldata) return await yt_stream(url, options); if (options.htmldata) return await yt_stream(url, options);
if (url.indexOf('spotify') !== -1) { if (url.indexOf('spotify') !== -1) {
@ -135,56 +123,56 @@ export async function stream(url: string, options: StreamOptions = {}): Promise<
else return await yt_stream(url, options); else return await yt_stream(url, options);
} }
export async function search( async function search(
query: string, query: string,
options: { source: { deezer: 'album' } } & SearchOptions options: { source: { deezer: 'album' } } & SearchOptions
): Promise<DeezerAlbum[]>; ): Promise<DeezerAlbum[]>;
export async function search( async function search(
query: string, query: string,
options: { source: { deezer: 'playlist' } } & SearchOptions options: { source: { deezer: 'playlist' } } & SearchOptions
): Promise<DeezerPlaylist[]>; ): Promise<DeezerPlaylist[]>;
export async function search( async function search(
query: string, query: string,
options: { source: { deezer: 'track' } } & SearchOptions options: { source: { deezer: 'track' } } & SearchOptions
): Promise<DeezerTrack[]>; ): Promise<DeezerTrack[]>;
export async function search( async function search(
query: string, query: string,
options: { source: { soundcloud: 'albums' } } & SearchOptions options: { source: { soundcloud: 'albums' } } & SearchOptions
): Promise<SoundCloudPlaylist[]>; ): Promise<SoundCloudPlaylist[]>;
export async function search( async function search(
query: string, query: string,
options: { source: { soundcloud: 'playlists' } } & SearchOptions options: { source: { soundcloud: 'playlists' } } & SearchOptions
): Promise<SoundCloudPlaylist[]>; ): Promise<SoundCloudPlaylist[]>;
export async function search( async function search(
query: string, query: string,
options: { source: { soundcloud: 'tracks' } } & SearchOptions options: { source: { soundcloud: 'tracks' } } & SearchOptions
): Promise<SoundCloudTrack[]>; ): Promise<SoundCloudTrack[]>;
export async function search( async function search(
query: string, query: string,
options: { source: { spotify: 'album' } } & SearchOptions options: { source: { spotify: 'album' } } & SearchOptions
): Promise<SpotifyAlbum[]>; ): Promise<SpotifyAlbum[]>;
export async function search( async function search(
query: string, query: string,
options: { source: { spotify: 'playlist' } } & SearchOptions options: { source: { spotify: 'playlist' } } & SearchOptions
): Promise<SpotifyPlaylist[]>; ): Promise<SpotifyPlaylist[]>;
export async function search( async function search(
query: string, query: string,
options: { source: { spotify: 'track' } } & SearchOptions options: { source: { spotify: 'track' } } & SearchOptions
): Promise<SpotifyTrack[]>; ): Promise<SpotifyTrack[]>;
export async function search( async function search(
query: string, query: string,
options: { source: { youtube: 'channel' } } & SearchOptions options: { source: { youtube: 'channel' } } & SearchOptions
): Promise<YouTubeChannel[]>; ): Promise<YouTubeChannel[]>;
export async function search( async function search(
query: string, query: string,
options: { source: { youtube: 'playlist' } } & SearchOptions options: { source: { youtube: 'playlist' } } & SearchOptions
): Promise<YouTubePlayList[]>; ): Promise<YouTubePlayList[]>;
export async function search( async function search(
query: string, query: string,
options: { source: { youtube: 'video' } } & SearchOptions options: { source: { youtube: 'video' } } & SearchOptions
): Promise<YouTubeVideo[]>; ): Promise<YouTubeVideo[]>;
export async function search(query: string, options: { limit: number } & SearchOptions): Promise<YouTubeVideo[]>; async function search(query: string, options: { limit: number } & SearchOptions): Promise<YouTubeVideo[]>;
export async function search(query: string, options?: SearchOptions): Promise<YouTubeVideo[]>; async function search(query: string, options?: SearchOptions): Promise<YouTubeVideo[]>;
/** /**
* Searches through a particular source and gives respective info. * Searches through a particular source and gives respective info.
* *
@ -214,7 +202,7 @@ export async function search(query: string, options?: SearchOptions): Promise<Yo
``` ```
* @returns Array of {@link YouTube} or {@link Spotify} or {@link SoundCloud} or {@link Deezer} type * @returns Array of {@link YouTube} or {@link Spotify} or {@link SoundCloud} or {@link Deezer} type
*/ */
export async function search( async function search(
query: string, query: string,
options: SearchOptions = {} options: SearchOptions = {}
): Promise<YouTube[] | Spotify[] | SoundCloud[] | Deezer[]> { ): Promise<YouTube[] | Spotify[] | SoundCloud[] | Deezer[]> {
@ -228,8 +216,8 @@ export async function search(
else throw new Error('Not possible to reach Here LOL. Easter Egg of play-dl if someone get this.'); else throw new Error('Not possible to reach Here LOL. Easter Egg of play-dl if someone get this.');
} }
export async function stream_from_info(info: SoundCloudTrack, options?: StreamOptions): Promise<SoundCloudStream>; async function stream_from_info(info: SoundCloudTrack, options?: StreamOptions): Promise<SoundCloudStream>;
export async function stream_from_info(info: InfoData, options?: StreamOptions): Promise<YouTubeStream>; async function stream_from_info(info: InfoData, options?: StreamOptions): Promise<YouTubeStream>;
/** /**
* Creates a Stream [ YouTube or SoundCloud ] class from video or track info for playing. * Creates a Stream [ YouTube or SoundCloud ] class from video or track info for playing.
* *
@ -260,7 +248,7 @@ export async function stream_from_info(info: InfoData, options?: StreamOptions):
* - `boolean` htmldata : given data is html data or not * - `boolean` htmldata : given data is html data or not
* @returns A {@link YouTubeStream} or {@link SoundCloudStream} Stream to play * @returns A {@link YouTubeStream} or {@link SoundCloudStream} Stream to play
*/ */
export async function stream_from_info( async function stream_from_info(
info: InfoData | SoundCloudTrack, info: InfoData | SoundCloudTrack,
options: StreamOptions = {} options: StreamOptions = {}
): Promise<YouTubeStream | SoundCloudStream> { ): Promise<YouTubeStream | SoundCloudStream> {
@ -280,7 +268,7 @@ export async function stream_from_info(
* 'so_playlist' / 'so_track' | 'sp_track' | 'sp_album' | 'sp_playlist' | 'dz_track' | 'dz_playlist' | 'dz_album' | 'yt_video' | 'yt_playlist' | 'search' | false * 'so_playlist' / 'so_track' | 'sp_track' | 'sp_album' | 'sp_playlist' | 'dz_track' | 'dz_playlist' | 'dz_album' | 'yt_video' | 'yt_playlist' | 'search' | false
* ``` * ```
*/ */
export async function validate( async function validate(
url: string url: string
): Promise< ): Promise<
| 'so_playlist' | 'so_playlist'
@ -325,7 +313,7 @@ export async function validate(
* *
* Just run the above command and you will get a interface asking some questions. * Just run the above command and you will get a interface asking some questions.
*/ */
export function authorization(): void { function authorization(): void {
const ask = createInterface({ const ask = createInterface({
input: process.stdin, input: process.stdin,
output: process.stdout output: process.stdout
@ -444,7 +432,7 @@ export function authorization(): void {
* @param player discordjs voice AudioPlayer * @param player discordjs voice AudioPlayer
* @param resource A {@link YouTubeStream} or {@link SoundCloudStream} * @param resource A {@link YouTubeStream} or {@link SoundCloudStream}
*/ */
export function attachListeners(player: EventEmitter, resource: YouTubeStream | SoundCloudStream) { function attachListeners(player: EventEmitter, resource: YouTubeStream | SoundCloudStream) {
// cleanup existing listeners if they are still registered // cleanup existing listeners if they are still registered
type listenerType = (...args: any[]) => void; type listenerType = (...args: any[]) => void;
@ -472,22 +460,49 @@ export function attachListeners(player: EventEmitter, resource: YouTubeStream |
player.once(AudioPlayerStatus.Idle, idleListener); player.once(AudioPlayerStatus.Idle, idleListener);
} }
import { // Export Main Commands
export {
DeezerAlbum,
DeezerPlaylist,
DeezerTrack,
SoundCloudPlaylist,
SoundCloudStream,
SoundCloudTrack,
SpotifyAlbum,
SpotifyPlaylist,
SpotifyTrack,
YouTubeChannel,
YouTubePlayList,
YouTubeVideo,
attachListeners,
authorization,
decipher_info, decipher_info,
deezer, deezer,
dz_advanced_track_search, dz_advanced_track_search,
dz_validate,
extractID, extractID,
getFreeClientID, getFreeClientID,
is_expired, is_expired,
playlist_info, playlist_info,
refreshToken, refreshToken,
search,
setToken, setToken,
so_validate,
soundcloud, soundcloud,
spotify, spotify,
sp_validate,
stream,
stream_from_info,
validate,
video_basic_info, video_basic_info,
video_info video_info,
} from '.'; yt_validate
}
// Export Types
export { Deezer, YouTube, SoundCloud, Spotify }
// Export Default
export default { export default {
DeezerAlbum, DeezerAlbum,
DeezerPlaylist, DeezerPlaylist,