pretty code

This commit is contained in:
killer069 2021-11-23 09:56:08 +05:30
parent 6fe9372989
commit 32b9fdbf65
19 changed files with 601 additions and 515 deletions

View File

@ -256,4 +256,4 @@ export async function dz_advanced_track_search(options: DeezerAdvancedSearchOpti
return results;
}
export { DeezerTrack, DeezerAlbum, DeezerPlaylist }
export { DeezerTrack, DeezerAlbum, DeezerPlaylist };

View File

@ -182,7 +182,7 @@ export class SoundCloudTrack {
* Converts class to JSON
* @returns JSON parsed Data
*/
toJSON() : SoundTrackJSON {
toJSON(): SoundTrackJSON {
return {
name: this.name,
id: this.id,

View File

@ -1,6 +1,6 @@
import { SoundCloudTrack, SoundCloudTrackDeprecated, SoundCloudTrackFormat, SoundCloudUser } from "./classes";
import { SoundCloudTrack, SoundCloudTrackDeprecated, SoundCloudTrackFormat, SoundCloudUser } from './classes';
export interface SoundTrackJSON{
export interface SoundTrackJSON {
/**
* SoundCloud Track Name
*/
@ -49,7 +49,7 @@ export interface SoundTrackJSON{
user: SoundCloudUser;
}
export interface PlaylistJSON{
export interface PlaylistJSON {
/**
* SoundCloud Playlist Name
*/

View File

@ -192,4 +192,4 @@ export function setSoundCloudToken(options: SoundDataOptions) {
soundData = options;
}
export { SoundCloudTrack, SoundCloudPlaylist, SoundCloudStream }
export { SoundCloudTrack, SoundCloudPlaylist, SoundCloudStream };

View File

@ -149,7 +149,7 @@ export class SpotifyTrack {
else this.thumbnail = data.album.images[0];
}
toJSON() : TrackJSON {
toJSON(): TrackJSON {
return {
name: this.name,
id: this.id,
@ -332,7 +332,7 @@ export class SpotifyPlaylist {
* Converts Class to JSON
* @returns JSON data
*/
toJSON() : PlaylistJSON{
toJSON(): PlaylistJSON {
return {
name: this.name,
collaborative: this.collaborative,
@ -341,7 +341,7 @@ export class SpotifyPlaylist {
id: this.id,
thumbnail: this.thumbnail,
owner: this.owner,
tracksCount : this.tracksCount
tracksCount: this.tracksCount
};
}
}
@ -520,10 +520,10 @@ export class SpotifyAlbum {
return (page_number - 1) * 100 + (this.fetched_tracks.get(`${page_number}`) as SpotifyTrack[]).length;
}
toJSON() : AlbumJSON {
toJSON(): AlbumJSON {
return {
name: this.name,
id : this.id,
id: this.id,
type: this.type,
url: this.url,
thumbnail: this.thumbnail,
@ -531,7 +531,7 @@ export class SpotifyAlbum {
copyrights: this.copyrights,
release_date: this.release_date,
release_date_precision: this.release_date_precision,
tracksCount : this.tracksCount
tracksCount: this.tracksCount
};
}
}

View File

@ -1,6 +1,6 @@
import { SpotifyArtists, SpotifyCopyright, SpotifyThumbnail, SpotifyTrackAlbum } from './classes'
import { SpotifyArtists, SpotifyCopyright, SpotifyThumbnail, SpotifyTrackAlbum } from './classes';
export interface TrackJSON{
export interface TrackJSON {
/**
* Spotify Track Name
*/
@ -74,7 +74,7 @@ export interface PlaylistJSON {
tracksCount: number;
}
export interface AlbumJSON{
export interface AlbumJSON {
/**
* Spotify Album Name
*/

View File

@ -243,4 +243,4 @@ export function setSpotifyToken(options: SpotifyDataOptions) {
refreshToken();
}
export { SpotifyTrack, SpotifyAlbum, SpotifyPlaylist }
export { SpotifyTrack, SpotifyAlbum, SpotifyPlaylist };

View File

@ -86,7 +86,7 @@ export class YouTubeChannel {
* Converts Channel Class to JSON format
* @returns json data of the channel
*/
toJSON() : ChannelJSON {
toJSON(): ChannelJSON {
return {
name: this.name,
verified: this.verified,
@ -100,7 +100,7 @@ export class YouTubeChannel {
}
}
interface ChannelJSON{
interface ChannelJSON {
/**
* YouTube Channel Title
*/

View File

@ -47,7 +47,7 @@ export class YouTubePlayList {
/**
* YouTube Playlist thumbnail Data
*/
thumbnail?: YouTubeThumbnail
thumbnail?: YouTubeThumbnail;
/**
* Videos array containing data of first 100 videos
*/
@ -173,7 +173,7 @@ export class YouTubePlayList {
this.__count++;
const res = await this.next();
max -= res.length;
if(max <= 0) break;
if (max <= 0) break;
if (!res.length) break;
}
@ -232,7 +232,7 @@ export class YouTubePlayList {
* Converts Playlist Class to a json parsed data.
* @returns
*/
toJSON() : PlaylistJSON {
toJSON(): PlaylistJSON {
return {
id: this.id,
title: this.title,
@ -244,7 +244,7 @@ export class YouTubePlayList {
}
}
interface PlaylistJSON{
interface PlaylistJSON {
/**
* YouTube Playlist ID
*/
@ -289,5 +289,5 @@ interface PlaylistJSON{
/**
* first 100 videos in that playlist
*/
videos? : YouTubeVideo[]
videos?: YouTubeVideo[];
}

View File

@ -1,22 +1,22 @@
export class YouTubeThumbnail {
id : string;
url : string;
width : number;
height : number;
id: string;
url: string;
width: number;
height: number;
constructor(data : any){
this.id = data.id
this.url = data.url
this.width = data.width
this.height = data.height
constructor(data: any) {
this.id = data.id;
this.url = data.url;
this.width = data.width;
this.height = data.height;
}
toJSON(){
toJSON() {
return {
id : this.id,
url : this.url,
width : this.width,
height : this.height
}
id: this.id,
url: this.url,
width: this.width,
height: this.height
};
}
}

View File

@ -1,6 +1,6 @@
export { stream, stream_from_info, YouTubeStream } from './stream';
export * from './utils';
export { YouTube } from './search';
export { YouTubeVideo } from './classes/Video'
export { YouTubePlayList } from './classes/Playlist'
export { YouTubeChannel } from './classes/Channel'
export { YouTubeVideo } from './classes/Video';
export { YouTubePlayList } from './classes/Playlist';
export { YouTubeChannel } from './classes/Channel';

View File

@ -1,39 +1,39 @@
import { YouTubeVideo } from "../classes/Video";
import { YouTubeVideo } from '../classes/Video';
export interface LiveStreamData {
isLive: boolean;
dashManifestUrl: string | null
hlsManifestUrl: string | null
dashManifestUrl: string | null;
hlsManifestUrl: string | null;
}
export interface formatData {
itag: number;
mimeType: string
bitrate: number
width: number
height: number
lastModified: string
contentLength: string
quality: string
fps: number
qualityLabel: string
projectionType: string
averageBitrate: number
audioQuality: string
approxDurationMs: string
audioSampleRate: string
audioChannels: number
url : string
signatureCipher : string;
cipher : string;
loudnessDb : number;
targetDurationSec : number;
mimeType: string;
bitrate: number;
width: number;
height: number;
lastModified: string;
contentLength: string;
quality: string;
fps: number;
qualityLabel: string;
projectionType: string;
averageBitrate: number;
audioQuality: string;
approxDurationMs: string;
audioSampleRate: string;
audioChannels: number;
url: string;
signatureCipher: string;
cipher: string;
loudnessDb: number;
targetDurationSec: number;
}
export interface InfoData{
LiveStreamData : LiveStreamData
html5player : string
format : Partial<formatData>[]
video_details : YouTubeVideo
related_videos: string[]
export interface InfoData {
LiveStreamData: LiveStreamData;
html5player: string;
format: Partial<formatData>[];
video_details: YouTubeVideo;
related_videos: string[];
}

View File

@ -46,3 +46,29 @@ export function setCookieToken(options: { cookie: string }) {
youtubeData = { cookie };
youtubeData.file = false;
}
/**
* Updates cookies locally either in file or in memory.
*
* Example
* ```ts
* const response = ... // Any https package get function.
*
* play.cookieHeaders(response.headers['set-cookie'])
* ```
* @param headCookie response headers['set-cookie'] array
* @returns Nothing
*/
export function cookieHeaders(headCookie: string[]): void {
if (!youtubeData?.cookie) return;
headCookie.forEach((x: string) => {
x.split(';').forEach((z) => {
const arr = z.split('=');
if (arr.length <= 1) return;
const key = arr.shift()?.trim() as string;
const value = arr.join('=').trim();
setCookie(key, value);
});
});
uploadCookie();
}

View File

@ -114,7 +114,7 @@ export function extractID(url: string): string {
* - `boolean` htmldata : given data is html data or not
* @returns Video Basic Info {@link InfoData}.
*/
export async function video_basic_info(url: string, options: InfoOptions = {}) : Promise<InfoData> {
export async function video_basic_info(url: string, options: InfoOptions = {}): Promise<InfoData> {
let body: string;
if (options.htmldata) {
body = url;
@ -147,11 +147,10 @@ export async function video_basic_info(url: string, options: InfoOptions = {}) :
player_response.playabilityStatus.errorScreen.playerKavRenderer?.reason.simpleText
}`
);
const ownerInfo = initial_response.contents.twoColumnWatchNextResults.results?.results?.contents[1]?.videoSecondaryInfoRenderer
?.owner?.videoOwnerRenderer
const badge =
ownerInfo?.badges &&
ownerInfo?.badges[0];
const ownerInfo =
initial_response.contents.twoColumnWatchNextResults.results?.results?.contents[1]?.videoSecondaryInfoRenderer
?.owner?.videoOwnerRenderer;
const badge = ownerInfo?.badges && ownerInfo?.badges[0];
const html5player = `https://www.youtube.com${body.split('"jsUrl":"')[1].split('"')[0]}`;
const related: string[] = [];
initial_response.contents.twoColumnWatchNextResults.secondaryResults.secondaryResults.results.forEach(
@ -178,7 +177,7 @@ export async function video_basic_info(url: string, options: InfoOptions = {}) :
url: `https://www.youtube.com/channel/${vid.channelId}`,
verified: Boolean(badge?.metadataBadgeRenderer?.style?.toLowerCase().includes('verified')),
artist: Boolean(badge?.metadataBadgeRenderer?.style?.toLowerCase().includes('artist')),
icons : ownerInfo?.thumbnail?.thumbnails || undefined
icons: ownerInfo?.thumbnail?.thumbnails || undefined
},
views: vid.viewCount,
tags: vid.keywords,

View File

@ -134,7 +134,7 @@ export function parseVideo(data?: any): YouTubeVideo {
data.videoRenderer.ownerText.runs[0].navigationEndpoint.browseEndpoint.canonicalBaseUrl ||
data.videoRenderer.ownerText.runs[0].navigationEndpoint.commandMetadata.webCommandMetadata.url
}`,
icons : data.videoRenderer.channelThumbnailSupportedRenderers.channelThumbnailWithLinkRenderer.thumbnail
icons: data.videoRenderer.channelThumbnailSupportedRenderers.channelThumbnailWithLinkRenderer.thumbnail
.thumbnails,
verified: Boolean(badge?.metadataBadgeRenderer?.style?.toLowerCase().includes('verified')),
artist: Boolean(badge?.metadataBadgeRenderer?.style?.toLowerCase().includes('artist'))

View File

@ -11,9 +11,34 @@ export {
YouTubePlayList,
YouTubeVideo
} from './YouTube';
export { spotify, sp_validate, refreshToken, is_expired, SpotifyAlbum, SpotifyPlaylist, SpotifyTrack, Spotify } from './Spotify';
export { soundcloud, so_validate, SoundCloud, SoundCloudStream, getFreeClientID, SoundCloudPlaylist, SoundCloudTrack } from './SoundCloud';
export { deezer, dz_validate, dz_advanced_track_search, Deezer, DeezerTrack, DeezerPlaylist, DeezerAlbum } from './Deezer';
export {
spotify,
sp_validate,
refreshToken,
is_expired,
SpotifyAlbum,
SpotifyPlaylist,
SpotifyTrack,
Spotify
} from './Spotify';
export {
soundcloud,
so_validate,
SoundCloud,
SoundCloudStream,
getFreeClientID,
SoundCloudPlaylist,
SoundCloudTrack
} from './SoundCloud';
export {
deezer,
dz_validate,
dz_advanced_track_search,
Deezer,
DeezerTrack,
DeezerPlaylist,
DeezerAlbum
} from './Deezer';
export { setToken } from './token';
enum AudioPlayerStatus {
@ -83,6 +108,56 @@ export async function stream(url: string, options: StreamOptions = {}): Promise<
else return await yt_stream(url, options);
}
export async function search(
query: string,
options: { source: { deezer: 'album' } } & SearchOptions
): Promise<DeezerAlbum[]>;
export async function search(
query: string,
options: { source: { deezer: 'playlist' } } & SearchOptions
): Promise<DeezerPlaylist[]>;
export async function search(
query: string,
options: { source: { deezer: 'track' } } & SearchOptions
): Promise<DeezerTrack[]>;
export async function search(
query: string,
options: { source: { soundcloud: 'albums' } } & SearchOptions
): Promise<SoundCloudPlaylist[]>;
export async function search(
query: string,
options: { source: { soundcloud: 'playlists' } } & SearchOptions
): Promise<SoundCloudPlaylist[]>;
export async function search(
query: string,
options: { source: { soundcloud: 'tracks' } } & SearchOptions
): Promise<SoundCloudTrack[]>;
export async function search(
query: string,
options: { source: { spotify: 'album' } } & SearchOptions
): Promise<SpotifyAlbum[]>;
export async function search(
query: string,
options: { source: { spotify: 'playlist' } } & SearchOptions
): Promise<SpotifyPlaylist[]>;
export async function search(
query: string,
options: { source: { spotify: 'track' } } & SearchOptions
): Promise<SpotifyTrack[]>;
export async function search(
query: string,
options: { source: { youtube: 'channel' } } & SearchOptions
): Promise<YouTubeChannel[]>;
export async function search(
query: string,
options: { source: { youtube: 'playlist' } } & SearchOptions
): Promise<YouTubePlayList[]>;
export async function search(
query: string,
options: { source: { youtube: 'video' } } & SearchOptions
): Promise<YouTubeVideo[]>;
export async function search(query: string, options: { limit: number } & SearchOptions): Promise<YouTubeVideo[]>;
export async function search(query: string, options?: SearchOptions): Promise<YouTubeVideo[]>;
/**
* Main Search Command for searching through various sources
* @param query string to search.
@ -90,20 +165,6 @@ export async function stream(url: string, options: StreamOptions = {}): Promise<
* @returns Array of YouTube or Spotify or SoundCloud or Deezer
deezer?: 'track' | 'playlist' | 'album';
*/
export async function search( query: string, options: { source : { deezer : "album" } } & SearchOptions) : Promise<DeezerAlbum[]>;
export async function search( query: string, options: { source : { deezer : "playlist" } } & SearchOptions) : Promise<DeezerPlaylist[]>;
export async function search( query: string, options: { source : { deezer : "track" } } & SearchOptions) : Promise<DeezerTrack[]>;
export async function search( query: string, options: { source : { soundcloud : "albums" } } & SearchOptions) : Promise<SoundCloudPlaylist[]>;
export async function search( query: string, options: { source : { soundcloud : "playlists" } } & SearchOptions) : Promise<SoundCloudPlaylist[]>;
export async function search( query: string, options: { source : { soundcloud : "tracks" } } & SearchOptions) : Promise<SoundCloudTrack[]>;
export async function search( query: string, options: { source : { spotify : "album" } } & SearchOptions) : Promise<SpotifyAlbum[]>;
export async function search( query: string, options: { source : { spotify : "playlist" } } & SearchOptions) : Promise<SpotifyPlaylist[]>;
export async function search( query: string, options: { source : { spotify : "track" } } & SearchOptions) : Promise<SpotifyTrack[]>;
export async function search( query: string, options: { source : { youtube : "channel" } } & SearchOptions) : Promise<YouTubeChannel[]>;
export async function search( query: string, options: { source : { youtube : "playlist" } } & SearchOptions) : Promise<YouTubePlayList[]>;
export async function search( query: string, options: { source : { youtube : "video" } } & SearchOptions) : Promise<YouTubeVideo[]>;
export async function search( query: string, options: { limit : number } & SearchOptions ) : Promise<YouTubeVideo[]>;
export async function search( query: string, options? : SearchOptions) : Promise<YouTubeVideo[]>;
export async function search(
query: string,
options: SearchOptions = {}
@ -114,7 +175,7 @@ export async function search(
else if (options.source.spotify) return await sp_search(query, options.source.spotify, options.limit);
else if (options.source.soundcloud) return await so_search(query, options.source.soundcloud, options.limit);
else if (options.source.deezer)
return await dz_search(query, { limit: options.limit, type: options.source.deezer, fuzzy : options.fuzzy });
return await dz_search(query, { limit: options.limit, type: options.source.deezer, fuzzy: options.fuzzy });
else throw new Error('Not possible to reach Here LOL. Easter Egg of play-dl if someone get this.');
}