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

@ -1,4 +1,4 @@
import { SoundCloudTrack, SoundCloudTrackDeprecated, SoundCloudTrackFormat, SoundCloudUser } from "./classes";
import { SoundCloudTrack, SoundCloudTrackDeprecated, SoundCloudTrackFormat, SoundCloudUser } from './classes';
export interface SoundTrackJSON {
/**

View File

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

View File

@ -1,4 +1,4 @@
import { SpotifyArtists, SpotifyCopyright, SpotifyThumbnail, SpotifyTrackAlbum } from './classes'
import { SpotifyArtists, SpotifyCopyright, SpotifyThumbnail, SpotifyTrackAlbum } from './classes';
export interface TrackJSON {
/**

View File

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

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
*/
@ -289,5 +289,5 @@ interface PlaylistJSON{
/**
* first 100 videos in that playlist
*/
videos? : YouTubeVideo[]
videos?: YouTubeVideo[];
}

View File

@ -5,10 +5,10 @@ export class YouTubeThumbnail {
height: number;
constructor(data: any) {
this.id = data.id
this.url = data.url
this.width = data.width
this.height = data.height
this.id = data.id;
this.url = data.url;
this.width = data.width;
this.height = data.height;
}
toJSON() {
@ -17,6 +17,6 @@ export class YouTubeThumbnail {
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,29 +1,29 @@
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
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;
@ -31,9 +31,9 @@ export interface formatData {
}
export interface InfoData {
LiveStreamData : LiveStreamData
html5player : string
format : Partial<formatData>[]
video_details : YouTubeVideo
related_videos: string[]
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

@ -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(

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 = {}