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; 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 { export interface SoundTrackJSON {
/** /**

View File

@ -192,4 +192,4 @@ export function setSoundCloudToken(options: SoundDataOptions) {
soundData = options; 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 { export interface TrackJSON {
/** /**

View File

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

View File

@ -47,7 +47,7 @@ export class YouTubePlayList {
/** /**
* YouTube Playlist thumbnail Data * YouTube Playlist thumbnail Data
*/ */
thumbnail?: YouTubeThumbnail thumbnail?: YouTubeThumbnail;
/** /**
* Videos array containing data of first 100 videos * Videos array containing data of first 100 videos
*/ */
@ -289,5 +289,5 @@ interface PlaylistJSON{
/** /**
* first 100 videos in that playlist * first 100 videos in that playlist
*/ */
videos? : YouTubeVideo[] videos?: YouTubeVideo[];
} }

View File

@ -5,10 +5,10 @@ export class YouTubeThumbnail {
height: number; height: number;
constructor(data: any) { constructor(data: any) {
this.id = data.id this.id = data.id;
this.url = data.url this.url = data.url;
this.width = data.width this.width = data.width;
this.height = data.height this.height = data.height;
} }
toJSON() { toJSON() {
@ -17,6 +17,6 @@ export class YouTubeThumbnail {
url: this.url, url: this.url,
width: this.width, width: this.width,
height: this.height height: this.height
} };
} }
} }

View File

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

View File

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

View File

@ -46,3 +46,29 @@ export function setCookieToken(options: { cookie: string }) {
youtubeData = { cookie }; youtubeData = { cookie };
youtubeData.file = false; 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 player_response.playabilityStatus.errorScreen.playerKavRenderer?.reason.simpleText
}` }`
); );
const ownerInfo = initial_response.contents.twoColumnWatchNextResults.results?.results?.contents[1]?.videoSecondaryInfoRenderer const ownerInfo =
?.owner?.videoOwnerRenderer initial_response.contents.twoColumnWatchNextResults.results?.results?.contents[1]?.videoSecondaryInfoRenderer
const badge = ?.owner?.videoOwnerRenderer;
ownerInfo?.badges && const badge = ownerInfo?.badges && ownerInfo?.badges[0];
ownerInfo?.badges[0];
const html5player = `https://www.youtube.com${body.split('"jsUrl":"')[1].split('"')[0]}`; const html5player = `https://www.youtube.com${body.split('"jsUrl":"')[1].split('"')[0]}`;
const related: string[] = []; const related: string[] = [];
initial_response.contents.twoColumnWatchNextResults.secondaryResults.secondaryResults.results.forEach( initial_response.contents.twoColumnWatchNextResults.secondaryResults.secondaryResults.results.forEach(

View File

@ -11,9 +11,34 @@ export {
YouTubePlayList, YouTubePlayList,
YouTubeVideo YouTubeVideo
} from './YouTube'; } from './YouTube';
export { spotify, sp_validate, refreshToken, is_expired, SpotifyAlbum, SpotifyPlaylist, SpotifyTrack, Spotify } from './Spotify'; export {
export { soundcloud, so_validate, SoundCloud, SoundCloudStream, getFreeClientID, SoundCloudPlaylist, SoundCloudTrack } from './SoundCloud'; spotify,
export { deezer, dz_validate, dz_advanced_track_search, Deezer, DeezerTrack, DeezerPlaylist, DeezerAlbum } from './Deezer'; 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'; export { setToken } from './token';
enum AudioPlayerStatus { enum AudioPlayerStatus {
@ -83,6 +108,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(
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 * Main Search Command for searching through various sources
* @param query string to search. * @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 * @returns Array of YouTube or Spotify or SoundCloud or Deezer
deezer?: 'track' | 'playlist' | 'album'; 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( export async function search(
query: string, query: string,
options: SearchOptions = {} options: SearchOptions = {}