Published types properly
This commit is contained in:
parent
513cada27a
commit
5a458d5557
|
|
@ -1,9 +1,9 @@
|
||||||
{
|
{
|
||||||
"name": "ytmusic-api",
|
"name": "ytmusic-api",
|
||||||
"version": "1.0.1",
|
"version": "1.0.2",
|
||||||
"description": "YouTube Music API",
|
"description": "YouTube Music API",
|
||||||
"main": "build/YTMusic.js",
|
"main": "build/index.js",
|
||||||
"types": "build/YTMusic.d.ts",
|
"types": "build/index.d.ts",
|
||||||
"author": "zS1L3NT <zechariahtan144@gmail.com> (http://www.zectan.com)",
|
"author": "zS1L3NT <zechariahtan144@gmail.com> (http://www.zectan.com)",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,10 @@ import SearchParser from "./parsers/SearchParser"
|
||||||
import SongParser from "./parsers/SongParser"
|
import SongParser from "./parsers/SongParser"
|
||||||
import traverse from "./utils/traverse"
|
import traverse from "./utils/traverse"
|
||||||
import VideoParser from "./parsers/VideoParser"
|
import VideoParser from "./parsers/VideoParser"
|
||||||
|
import YTMusic from "."
|
||||||
import { Cookie, CookieJar } from "tough-cookie"
|
import { Cookie, CookieJar } from "tough-cookie"
|
||||||
|
|
||||||
export default class YTMusic {
|
export default class Api {
|
||||||
private cookiejar: CookieJar
|
private cookiejar: CookieJar
|
||||||
private config?: Record<string, string>
|
private config?: Record<string, string>
|
||||||
private client: AxiosInstance
|
private client: AxiosInstance
|
||||||
|
|
@ -1,11 +1,15 @@
|
||||||
|
import Api from "./Api"
|
||||||
|
|
||||||
declare namespace YTMusic {
|
declare namespace YTMusic {
|
||||||
interface ThumbnailFull {
|
export { Api }
|
||||||
|
|
||||||
|
export interface ThumbnailFull {
|
||||||
url: string
|
url: string
|
||||||
width: number
|
width: number
|
||||||
height: number
|
height: number
|
||||||
}
|
}
|
||||||
|
|
||||||
interface SongDetailed {
|
export interface SongDetailed {
|
||||||
type: "SONG"
|
type: "SONG"
|
||||||
videoId: string | null
|
videoId: string | null
|
||||||
name: string
|
name: string
|
||||||
|
|
@ -15,13 +19,13 @@ declare namespace YTMusic {
|
||||||
thumbnails: ThumbnailFull[]
|
thumbnails: ThumbnailFull[]
|
||||||
}
|
}
|
||||||
|
|
||||||
interface SongFull extends Omit<SongDetailed, "album"> {
|
export interface SongFull extends Omit<SongDetailed, "album"> {
|
||||||
description: string
|
description: string
|
||||||
formats: any[]
|
formats: any[]
|
||||||
adaptiveFormats: any[]
|
adaptiveFormats: any[]
|
||||||
}
|
}
|
||||||
|
|
||||||
interface VideoDetailed {
|
export interface VideoDetailed {
|
||||||
type: "VIDEO"
|
type: "VIDEO"
|
||||||
videoId: string | null
|
videoId: string | null
|
||||||
name: string
|
name: string
|
||||||
|
|
@ -31,7 +35,7 @@ declare namespace YTMusic {
|
||||||
thumbnails: ThumbnailFull[]
|
thumbnails: ThumbnailFull[]
|
||||||
}
|
}
|
||||||
|
|
||||||
interface VideoFull extends VideoDetailed {
|
export interface VideoFull extends VideoDetailed {
|
||||||
description: string
|
description: string
|
||||||
unlisted: boolean
|
unlisted: boolean
|
||||||
familySafe: boolean
|
familySafe: boolean
|
||||||
|
|
@ -39,30 +43,30 @@ declare namespace YTMusic {
|
||||||
tags: string[]
|
tags: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ArtistBasic {
|
export interface ArtistBasic {
|
||||||
artistId: string | null
|
artistId: string | null
|
||||||
name: string
|
name: string
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ArtistDetailed extends ArtistBasic {
|
export interface ArtistDetailed extends ArtistBasic {
|
||||||
type: "ARTIST"
|
type: "ARTIST"
|
||||||
artistId: string
|
artistId: string
|
||||||
thumbnails: ThumbnailFull[]
|
thumbnails: ThumbnailFull[]
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ArtistFull extends ArtistDetailed {
|
export interface ArtistFull extends ArtistDetailed {
|
||||||
description: string | null
|
description: string | null
|
||||||
subscribers: number
|
subscribers: number
|
||||||
topSongs: Omit<SongDetailed, "duration">[]
|
topSongs: Omit<SongDetailed, "duration">[]
|
||||||
topAlbums: AlbumDetailed[]
|
topAlbums: AlbumDetailed[]
|
||||||
}
|
}
|
||||||
|
|
||||||
interface AlbumBasic {
|
export interface AlbumBasic {
|
||||||
albumId: string
|
albumId: string
|
||||||
name: string
|
name: string
|
||||||
}
|
}
|
||||||
|
|
||||||
interface AlbumDetailed extends AlbumBasic {
|
export interface AlbumDetailed extends AlbumBasic {
|
||||||
type: "ALBUM"
|
type: "ALBUM"
|
||||||
playlistId: string
|
playlistId: string
|
||||||
artists: ArtistBasic[]
|
artists: ArtistBasic[]
|
||||||
|
|
@ -70,12 +74,12 @@ declare namespace YTMusic {
|
||||||
thumbnails: ThumbnailFull[]
|
thumbnails: ThumbnailFull[]
|
||||||
}
|
}
|
||||||
|
|
||||||
interface AlbumFull extends AlbumDetailed {
|
export interface AlbumFull extends AlbumDetailed {
|
||||||
description: string | null
|
description: string | null
|
||||||
songs: SongDetailed[]
|
songs: SongDetailed[]
|
||||||
}
|
}
|
||||||
|
|
||||||
interface PlaylistFull {
|
export interface PlaylistFull {
|
||||||
type: "PLAYLIST"
|
type: "PLAYLIST"
|
||||||
playlistId: string
|
playlistId: string
|
||||||
name: string
|
name: string
|
||||||
|
|
@ -84,10 +88,12 @@ declare namespace YTMusic {
|
||||||
thumbnails: ThumbnailFull[]
|
thumbnails: ThumbnailFull[]
|
||||||
}
|
}
|
||||||
|
|
||||||
type SearchResult =
|
export type SearchResult =
|
||||||
| SongDetailed
|
| SongDetailed
|
||||||
| VideoDetailed
|
| VideoDetailed
|
||||||
| AlbumDetailed
|
| AlbumDetailed
|
||||||
| ArtistDetailed
|
| ArtistDetailed
|
||||||
| PlaylistFull
|
| PlaylistFull
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default YTMusic
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import SongParser from "./SongParser"
|
import SongParser from "./SongParser"
|
||||||
import traverse from "../utils/traverse"
|
import traverse from "../utils/traverse"
|
||||||
|
import YTMusic from ".."
|
||||||
|
|
||||||
export default class AlbumParser {
|
export default class AlbumParser {
|
||||||
public static parse(data: any, albumId: string): YTMusic.AlbumFull {
|
public static parse(data: any, albumId: string): YTMusic.AlbumFull {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
import AlbumParser from "./AlbumParser"
|
import AlbumParser from "./AlbumParser"
|
||||||
import Parse from "./Parser"
|
import Parser from "./Parser"
|
||||||
import SongParser from "./SongParser"
|
import SongParser from "./SongParser"
|
||||||
import traverse from "../utils/traverse"
|
import traverse from "../utils/traverse"
|
||||||
|
import YTMusic from ".."
|
||||||
|
|
||||||
export default class ArtistParser {
|
export default class ArtistParser {
|
||||||
public static parse(data: any, artistId: string): YTMusic.ArtistFull {
|
public static parse(data: any, artistId: string): YTMusic.ArtistFull {
|
||||||
|
|
@ -17,7 +18,7 @@ export default class ArtistParser {
|
||||||
...artistBasic,
|
...artistBasic,
|
||||||
thumbnails: [traverse(data, "header", "thumbnails")].flat(),
|
thumbnails: [traverse(data, "header", "thumbnails")].flat(),
|
||||||
description: description instanceof Array ? null : description,
|
description: description instanceof Array ? null : description,
|
||||||
subscribers: Parse.parseNumber(traverse(data, "subscriberCountText", "text")),
|
subscribers: Parser.parseNumber(traverse(data, "subscriberCountText", "text")),
|
||||||
topSongs: traverse(data, "musicShelfRenderer", "contents").map((item: any) =>
|
topSongs: traverse(data, "musicShelfRenderer", "contents").map((item: any) =>
|
||||||
SongParser.parseArtistTopSong(item, artistBasic)
|
SongParser.parseArtistTopSong(item, artistBasic)
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
export default class Parse {
|
export default class Parser {
|
||||||
public static parseDuration(time: string) {
|
public static parseDuration(time: string) {
|
||||||
const [seconds, minutes, hours] = time
|
const [seconds, minutes, hours] = time
|
||||||
.split(":")
|
.split(":")
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import traverse from "../utils/traverse"
|
import traverse from "../utils/traverse"
|
||||||
|
import YTMusic from ".."
|
||||||
|
|
||||||
export default class PlaylistParser {
|
export default class PlaylistParser {
|
||||||
public static parse(data: any, playlistId: string): YTMusic.PlaylistFull {
|
public static parse(data: any, playlistId: string): YTMusic.PlaylistFull {
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import PlaylistParser from "./PlaylistParser"
|
||||||
import SongParser from "./SongParser"
|
import SongParser from "./SongParser"
|
||||||
import traverse from "../utils/traverse"
|
import traverse from "../utils/traverse"
|
||||||
import VideoParser from "./VideoParser"
|
import VideoParser from "./VideoParser"
|
||||||
|
import YTMusic from ".."
|
||||||
|
|
||||||
export default class SearchParser {
|
export default class SearchParser {
|
||||||
public static parse(item: any): YTMusic.SearchResult {
|
public static parse(item: any): YTMusic.SearchResult {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import Parser from "./Parser"
|
import Parser from "./Parser"
|
||||||
import traverse from "../utils/traverse"
|
import traverse from "../utils/traverse"
|
||||||
|
import YTMusic from ".."
|
||||||
|
|
||||||
export default class SongParser {
|
export default class SongParser {
|
||||||
public static parse(data: any): YTMusic.SongFull {
|
public static parse(data: any): YTMusic.SongFull {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import Parser from "./Parser"
|
import Parser from "./Parser"
|
||||||
import traverse from "../utils/traverse"
|
import traverse from "../utils/traverse"
|
||||||
|
import YTMusic from ".."
|
||||||
|
|
||||||
export default class VideoParser {
|
export default class VideoParser {
|
||||||
public static parse(data: any): YTMusic.VideoFull {
|
public static parse(data: any): YTMusic.VideoFull {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import Validator from "validate-any/build/classes/Validator"
|
import Validator from "validate-any/build/classes/Validator"
|
||||||
import YTMusic from "../YTMusic"
|
import YTMusicApi from "../Api"
|
||||||
import {
|
import {
|
||||||
ALBUM_DETAILED,
|
ALBUM_DETAILED,
|
||||||
ALBUM_FULL,
|
ALBUM_FULL,
|
||||||
|
|
@ -15,7 +15,7 @@ import {
|
||||||
import { LIST, validate } from "validate-any"
|
import { LIST, validate } from "validate-any"
|
||||||
|
|
||||||
const queries = ["Lilac", "Weekend", "Yours Raiden", "Eminem", "Lisa Hannigan"]
|
const queries = ["Lilac", "Weekend", "Yours Raiden", "Eminem", "Lisa Hannigan"]
|
||||||
const ytmusic = new YTMusic()
|
const ytmusic = new YTMusicApi()
|
||||||
|
|
||||||
ytmusic.initialize().then(() =>
|
ytmusic.initialize().then(() =>
|
||||||
queries.forEach(async query => {
|
queries.forEach(async query => {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import ObjectValidator from "validate-any/build/validators/ObjectValidator"
|
import ObjectValidator from "validate-any/build/validators/ObjectValidator"
|
||||||
|
import YTMusic from "../index"
|
||||||
import { BOOLEAN, LIST, NULL, NUMBER, OBJECT, OR, STRING } from "validate-any"
|
import { BOOLEAN, LIST, NULL, NUMBER, OBJECT, OR, STRING } from "validate-any"
|
||||||
|
|
||||||
export const THUMBNAIL_FULL: ObjectValidator<YTMusic.ThumbnailFull> = OBJECT({
|
export const THUMBNAIL_FULL: ObjectValidator<YTMusic.ThumbnailFull> = OBJECT({
|
||||||
|
|
@ -113,7 +114,7 @@ export const ALBUM_FULL: ObjectValidator<YTMusic.AlbumFull> = OBJECT({
|
||||||
songs: LIST(SONG_DETAILED)
|
songs: LIST(SONG_DETAILED)
|
||||||
})
|
})
|
||||||
|
|
||||||
export const PLAYLIST_DETAILED: ObjectValidator<YTMusic.PlaylistDetailed> = OBJECT({
|
export const PLAYLIST_DETAILED: ObjectValidator<YTMusic.PlaylistFull> = OBJECT({
|
||||||
type: STRING("PLAYLIST"),
|
type: STRING("PLAYLIST"),
|
||||||
playlistId: STRING(),
|
playlistId: STRING(),
|
||||||
name: STRING(),
|
name: STRING(),
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import YTMusic from "../YTMusic"
|
import YTMusicApi from "../Api"
|
||||||
|
|
||||||
const ytmusic = new YTMusic()
|
const ytmusic = new YTMusicApi()
|
||||||
ytmusic.initialize().then(() => {
|
ytmusic.initialize().then(() => {
|
||||||
ytmusic.search("Lilac", "SONG").then(res => {
|
ytmusic.search("Lilac", "SONG").then(res => {
|
||||||
ytmusic.getSong(res.find(r => !!r.videoId)!.videoId!).then(res => {
|
ytmusic.getSong(res.find(r => !!r.videoId)!.videoId!).then(res => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue