Prepare to upload to npm

This commit is contained in:
Zechariah 2021-12-26 14:42:50 +08:00
parent 9edefbb351
commit 50b92f9fc4
6 changed files with 383 additions and 7327 deletions

7
.npmignore Normal file
View File

@ -0,0 +1,7 @@
/src
.vscode
.gitignore
.prettierrc
.editorconfig
nodemon.json
tsconfig.json

8
.vscode/launch.json vendored
View File

@ -7,8 +7,8 @@
{
"type": "node",
"request": "launch",
"name": "index.ts",
"program": "${workspaceFolder}/src/index.ts",
"name": "testing/run.ts",
"program": "${workspaceFolder}/src/testing/run.ts",
"sourceMaps": true,
"skipFiles": ["<node_internals>/**"],
"runtimeExecutable": "node",
@ -17,8 +17,8 @@
{
"type": "node",
"request": "launch",
"name": "tests/testing.ts",
"program": "${workspaceFolder}/src/tests/testing.ts",
"name": "tests/all.ts",
"program": "${workspaceFolder}/src/tests/all.ts",
"sourceMaps": true,
"skipFiles": ["<node_internals>/**"],
"runtimeExecutable": "node",

View File

@ -11,7 +11,7 @@
"**/*.cs.meta": true,
"**/android": true,
"**/ios": true,
"**/node_modules": true,
"**/node_modules": false,
"**/__pycache__": true,
"**/babel.config.js": true,
"**/metro.config.js": true,

369
README.md Normal file
View File

@ -0,0 +1,369 @@
# yt-music
YouTube Music API which comes with TypeScript support
## Initialization
Import YTMusic from the npm package
```ts
// TypeScript
import YTMusic from "yt-music"
// JavaScript
const YTMusic = require("yt-music")
```
Create an instance of the class `YTMusic`.
Then, call the `initialize()` to initialize the API before using the API anywhere
```ts
const ytmusic = new YTMusic()
ytmusic.initialize().then(() => {
// Use API here
})
```
## Class Methods
### `getSearchSuggestions`
This function takes in the following parameters
| Name | Data Type | Description |
| :--- | :-------- | :---------- |
| query | `string` | Search query you want suggestions for |
The function returns a `Promise<string[]>` which are the suggestion results
```ts
ytmusic.getSearchSuggestions("Lilac").then(res => {
console.log(res)
})
```
### `search`
This function takes in the following parameters
| Name | Data Type | Description |
| :--- | :-------- | :---------- |
| query | `string` | Search query |
| category | `"SONG" \| "VIDEO" \| "ARTIST" \| "ALBUM" \| "PLAYLIST" \| undefined` | Type of results to search for. If not specified, returns all types of search result |
The function **when nothing is passed as the category** returns a `Promise<`[SearchResult](#SearchResult)`[]>` which are the search results of all categories
```ts
ytmusic.search("Lilac").then(results => {
console.log(results)
})
```
#### `search (category = "SONG")`
When you pass in `"SONG"` as the category,
The function returns a `Promise<`[SongDetailed](#SongDetailed)`[]>` which are the song results
```ts
ytmusic.search("Lilac", "SONG").then(songs => {
console.log(songs)
})
```
#### `search (category = "VIDEO")`
When you pass in `"VIDEO"` as the category,
The function returns a `Promise<`[VideoDetailed](#VideoDetailed)`[]>` which are the video results
```ts
ytmusic.search("Lilac", "VIDEO").then(videos => {
console.log(videos)
})
```
#### `search (category = "ARTIST")`
When you pass in `"ARTIST"` as the category
The function returns a `Promise<`[ArtistDetailed](#ArtistDetailed)`[]>` which are the artist results
```ts
ytmusic.search("Lilac", "ARTIST").then(artists => {
console.log(artists)
})
```
#### `search (category = "ALBUM")`
When you pass in `"ALBUM"` as the category,
The function returns a `Promise<`[AlbumDetailed](#AlbumDetailed)`[]>` which are the album results
```ts
ytmusic.search("Lilac", "ALBUM").then(albums => {
console.log(albums)
})
```
#### `search (category = "PLAYLIST")`
When you pass in `"PLAYLIST"` as the category,
The function returns a `Promise<`[PlaylistFull](#PlaylistFull)`[]>` which are the playlist results
```ts
ytmusic.search("Lilac", "PLAYLIST").then(playlists => {
console.log(playlists)
})
```
### `getSong`
This function takes in the following parameters
| Name | Data Type | Description |
| :--- | :-------- | :---------- |
| videoId | `string` | Video ID |
The function returns a `Promise<`[SongFull](#SongFull)`>` which is the information about the song
```ts
ytmusic.getSong("v7bnOxV4jAc").then(song => {
console.log(song)
})
```
### `getVideo`
This function takes in the following parameters
| Name | Data Type | Description |
| :--- | :-------- | :---------- |
| videoId | `string` | Video ID |
The function returns a `Promise<`[VideoFull](#VideoFull)`>` which is the information about the video
```ts
ytmusic.getVideo("v7bnOxV4jAc").then(video => {
console.log(video)
})
```
### `getArtist`
This function takes in the following parameters
| Name | Data Type | Description |
| :--- | :-------- | :---------- |
| artistId | `string` | Artist ID |
The function returns a `Promise<`[ArtistFull](#ArtistFull)`>` which is the information about the artist
```ts
ytmusic.getArtist("UCTUR0sVEkD8T5MlSHqgaI_Q").then(artist => {
console.log(artist)
})
```
### `getArtistSongs`
This function takes in the following parameters
| Name | Data Type | Description |
| :--- | :-------- | :---------- |
| artistId | `string` | Artist ID |
The function returns a `Promise<`[SongDetailed](#SongDetailed)`[]>` which is the information about all the artist's songs
```ts
ytmusic.getArtistSongs("UCTUR0sVEkD8T5MlSHqgaI_Q").then(artistSongs => {
console.log(artistSongs)
})
```
### `getArtistAlbums`
This function takes in the following parameters
| Name | Data Type | Description |
| :--- | :-------- | :---------- |
| artistId | `string` | Artist ID |
The function returns a `Promise<`[AlbumDetailed](#AlbumDetailed)`[]>` which is the information about all the artist's albums
```ts
ytmusic.getArtistAlbums("UCTUR0sVEkD8T5MlSHqgaI_Q").then(artistAlbums => {
console.log(artistAlbums)
})
```
### `getAlbum`
This function takes in the following parameters
| Name | Data Type | Description |
| :--- | :-------- | :---------- |
| albumId | `string` | Album ID |
The function returns a `Promise<`[AlbumFull](#AlbumFull)`>` which is the information about the album
```ts
ytmusic.getAlbum("MPREb_iG5q5DIdhdA").then(album => {
console.log(album)
})
```
### `getPlaylist`
This function takes in the following parameters
| Name | Data Type | Description |
| :--- | :-------- | :---------- |
| playlistId | `string` | Playlist ID |
The function returns a `Promise<`[PlaylistFull](#PlaylistFull)`>` which is the information about the playlist (without the videos)
```ts
ytmusic.getPlaylist("OLAK5uy_nRb467jR73IXKybwzw22_rTYIJ808x4Yc").then(playlist => {
console.log(playlist)
})
```
### `getPlaylistVideos`
This function takes in the following parameters
| Name | Data Type | Description |
| :--- | :-------- | :---------- |
| playlistId | `string` | Playlist ID |
The function returns a `Promise<Omit<`[VideoDetailed](#VideoDetailed)`, "views">[]>` which is the information about the videos without the view count
```ts
ytmusic.getPlaylistVideos("OLAK5uy_nRb467jR73IXKybwzw22_rTYIJ808x4Yc").then(playlistVideos => {
console.log(playlistVideos)
})
```
## Data Types
### `ThumbnailFull`
| Name | Data Type | Description |
| :--- | :-------- | :---------- |
| url | `string` | Link |
| width | `number` | Width of the image |
| height | `number` | Height of the image |
### `SongDetailed`
| Name | Data Type | Description |
| :--- | :-------- | :---------- |
| type | `"SONG"` | Type of data |
| videoId | `string \| null` | YouTube Video ID |
| name | `string` | Name |
| artists | [ArtistBasic](#ArtistBasic)`[]` | Artists |
| album | [AlbumBasic](#AlbumBasic) | Album |
| duration | `number` | Duration in seconds |
| thumbnails | [ThumbnailFull](#ThumbnailFull)`[]` | Thumbnails |
### `SongFull`
| Name | Data Type | Description |
| :--- | :-------- | :---------- |
| type | `"SONG"` | Type of data |
| videoId | `string \| null` | YouTube Video ID |
| name | `string` | Name |
| artists | [ArtistBasic](#ArtistBasic)`[]` | Artists |
| duration | `number` | Duration in seconds |
| thumbnails | [ThumbnailFull](#ThumbnailFull)`[]` | Thumbnails |
| description | `string` | Description |
| formats | `any[]` | Video Formats |
| adaptiveFormats | `any[]` | Adaptive Video Formats |
### `VideoDetailed`
| Name | Data Type | Description |
| :--- | :-------- | :---------- |
| type | `"VIDEO"` | Type of data |
| videoId | `string \| null` | YouTube Video ID |
| name | `string` | Name |
| artists | [ArtistBasic](#ArtistBasic)`[]` | Channels that created the video |
| views | `number` | View count |
| duration | `number` | Duration in seconds |
| thumbnails | [ThumbnailFull](#ThumbnailFull)`[]` | Thumbnails |
### `VideoFull`
| Name | Data Type | Description |
| :--- | :-------- | :---------- |
| type | `"VIDEO"` | Type of data |
| videoId | `string \| null` | YouTube Video ID |
| name | `string` | Name |
| artists | [ArtistBasic](#ArtistBasic)`[]` | Channels that created the video |
| views | `number` | View count |
| duration | `number` | Duration in seconds |
| thumbnails | [ThumbnailFull](#ThumbnailFull)`[]` | Thumbnails |
| description | `string` | Description |
| unlisted | `boolean` | If the video is unlisted on YouTube |
| familySafe | `boolean` | If the video is family safe on YouTube |
| paid | `boolean` | If the video is paid on YouTube |
| tags | `string[]` | Tags |
### `ArtistBasic`
| Name | Data Type | Description |
| :--- | :-------- | :---------- |
| artistId | `string \| null` | Artist ID |
| name | `string` | Name |
### `ArtistDetailed`
| Name | Data Type | Description |
| :--- | :-------- | :---------- |
| type | `"ARTIST"` | Type of data |
| artistId | `string` | Artist ID |
| name | `string` | Name |
| thumbnails | [ThumbnailFull](#ThumbnailFull)`[]` | Thumbnails |
### `ArtistFull`
| Name | Data Type | Description |
| :--- | :-------- | :---------- |
| type | `"ARTIST"` | Type of data |
| artistId | `string` | Artist ID |
| name | `string` | Name |
| thumbnails | [ThumbnailFull](#ThumbnailFull)`[]` | Thumbnails |
| description | `string \| null` | Description |
| subscribers | `number` | Number of subscribers the Artist has|
| topSongs | `Omit<`[SongDetailed](#SongDetailed)`, "duration">[]` | Top Songs from Artist |
| topAlbums | [AlbumDetailed](#AlbumDetailed)`[]` | Top Albums from Artist |
### `AlbumBasic`
| Name | Data Type | Description |
| :--- | :-------- | :---------- |
| albumId | `string` | Album ID |
| name | `string` | Name |
### `AlbumDetailed`
| Name | Data Type | Description |
| :--- | :-------- | :---------- |
| type | `"ALBUM"` | Type of data |
| albumId | `string` | Album ID |
| playlistId | `string` | Playlist ID for Album |
| name | `string` | Name |
| artists | [ArtistBasic](#ArtistBasic)`[]` | Creators of the Album |
| year | `number` | Publication Year |
| thumbnails | [ThumbnailFull](#ThumbnailFull)`[]` | Thumbnails |
### `AlbumFull`
| Name | Data Type | Description |
| :--- | :-------- | :---------- |
| type | `"ALBUM"` | Type of data |
| albumId | `string` | Album ID |
| playlistId | `string` | Playlist ID for Album |
| name | `string` | Name |
| artists | [ArtistBasic](#ArtistBasic)`[]` | Creators of the Album |
| year | `number` | Publication Year |
| thumbnails | [ThumbnailFull](#ThumbnailFull)`[]` | Thumbnails |
| description | `string \| null` | Description |
| songs | [SongDetailed](#SongDetailed)`[]` | Songs in the Album
### `PlaylistFull`
| Name | Data Type | Description |
| :--- | :-------- | :---------- |
| type | `"PLAYLIST"` | Type of data |
| playlistId | `string` | Playlist ID |
| name | `string` | Name |
| artist | [ArtistBasic](#ArtistBasic) | Creator of the Playlist |
| videoCount | `number` | Number of videos in the Playlist |
| thumbnails | [ThumbnailFull](#ThumbnailFull)`[]` | Thumbnails |
### `SearchResult`
[SongDetailed](#SongDetailed) or [VideoDetailed](#VideoDetailed) or [ArtistDetailed](#ArtistDetailed) or [AlbumDetailed](#AlbumDetailed) or [PlaylistFull](#PlaylistFull)

File diff suppressed because it is too large Load Diff

View File

@ -17,7 +17,5 @@
"outDir": "build",
"rootDir": "src"
},
"exclude": [
"**/*.test.*"
]
"exclude": ["**/*.test.*", "**/tests"]
}