youtube-moosick
v0.3.0-rc1
Published
Unofficial Youtube music API, fully written in TypeScript
Downloads
590
Readme
youtube-moosick
Unofficial YouTube Music Library, written in TypeScript.
import { YoutubeMoosick } from "youtube-moosick";
const ytms = new YoutubeMoosick.new();
// Using async await
const results = await ytms.search("Never gonna give you up");
console.log(results);
/*
ContinuableUnsorted(16) [
Video {
thumbnails: [ [Object] ],
name: 'Never Gonna Give You Up',
url: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
videoId: 'dQw4w9WgXcQ',
author: [ [Artist] ],
views: 1000,
length: 213000
},
Song {
type: 'SONG',
artist: [ [Artist] ],
album: [ [Album] ],
duration: 214000,
name: 'Never Gonna Give You Up',
url: 'https://www.youtube.com/watch?v=lYBUbBu4W08',
videoId: 'lYBUbBu4W08',
thumbnails: [ [Object], [Object] ],
playlistId: 'RDAMVMlYBUbBu4W08',
params: 'wAEB'
},
// ...
]
*/
Installation
npm i youtube-moosick
API
search
▸ search(query
, searchType?
): Promise
<unknown
>
Searches YouTube Music.
Parameters
| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| query
| string
| undefined
| String query text to search |
| searchType?
| Category
| undefined
| Type of category to search |
Returns
The return of this function depends on the supplied value of searchType
.
| Category | Return Type |
| :------ | :------ |
| undefined
| Promise
<ContinuableUnsorted
> |
| Category.SONG
| Promise
<ContinuableResult
<Song>
> |
| Category.VIDEO
| Promise
<ContinuableResult
<Video>
> |
| Category.ALBUM
,Category.SINGLE
,Category.EP
| Promise
<ContinuableResult
<Album>
> |
| Category.ARTIST
| Promise
<ContinuableResult
<ArtistExtended>
> |
| Category.PLAYLIST
| Promise
<ContinuableResult
<Playlist>
> |
For more info, see here.
Example
const ytms = await YoutubeMoosick.new();
// Get the general search results.
const resultsGeneral = await ytms.search('Never gonna give you up');
console.log(resultsGeneral)
/*
ContinuableUnsorted(16) [
Video {
thumbnails: [ [Object] ],
name: 'Never Gonna Give You Up',
url: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
videoId: 'dQw4w9WgXcQ',
author: [ [Artist] ],
views: 1000,
length: 213000
},
Song {
type: 'SONG',
artist: [ [Artist] ],
album: [ [Album] ],
duration: 214000,
name: 'Never Gonna Give You Up',
url: 'https://www.youtube.com/watch?v=lYBUbBu4W08',
videoId: 'lYBUbBu4W08',
thumbnails: [ [Object], [Object] ],
playlistId: 'RDAMVMlYBUbBu4W08',
params: 'wAEB'
},
// ...
]
*/
// Gets a specific category
const resultsSong = await ytms.search('Never gonna give you up', Category.SONG);
console.log(resultsSong)
/*
ContinuableResult(20) [
Song {
type: 'SONG',
artist: [ [Artist] ],
album: [ [Album] ],
duration: 214000,
name: 'Never Gonna Give You Up',
url: 'https://www.youtube.com/watch?v=lYBUbBu4W08',
videoId: 'lYBUbBu4W08',
thumbnails: [ [Object], [Object] ],
playlistId: 'RDAMVMlYBUbBu4W08',
params: 'wAEB'
},
Song {
type: 'SONG',
artist: [ [Artist] ],
album: [ [Album] ],
duration: 267000,
name: 'Never Gonna Give You Up (Rick Astley)',
url: 'https://www.youtube.com/watch?v=4ywFyK8cCg4',
videoId: '4ywFyK8cCg4',
thumbnails: [ [Object], [Object] ],
playlistId: 'RDAMVM4ywFyK8cCg4',
params: 'wAEB'
},
....
]
*/
getSearchSuggestions
▸ getSearchSuggestions(query
): Promise
<SearchSuggestions
[]>
Fetches search suggestions from YouTube Music.
Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| query
| string
| String query text to search |
Returns
Promise
<SearchSuggestions
[]>
An object containing data gotten from the search.
Example
const suggestions = ytms.getSearchSuggestions("All We know");
console.log(suggestions);
/*
[
SearchSuggestions { artist: '', title: 'all we know' },
SearchSuggestions { artist: ' chainsmokers lyrics', title: 'all we know'},
SearchSuggestions { artist: ' shy', title: 'all we know' },
SearchSuggestions { artist: ' slowed', title: 'all we know' },
SearchSuggestions { artist: ' remix', title: 'all we know' },
SearchSuggestions { artist: ' nightcore', title: 'all we know' },
SearchSuggestions { artist: ' paramore', title: 'all we know' }
]
*/
getAlbum
▸ getAlbum(browseId
): Promise
<AlbumURL
>
Fetches album details from YouTube Music.
Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| browseId
| string
| The album Id only, without https://....
|
Returns
Promise
<AlbumURL
>
An object containing data of the Album requested.
Example
const ytms = await YoutubeMoosick.new();
const results = await ytms.getAlbum('MPREb_REsMMqBZjZB');
console.log(results)
/*
AlbumURL {
AlbumURLHeader: AlbumURLHeader {
title: 'Eyes wide open',
description: `Eyes Wide Open is the second Korean studio album by South Korean girl group Twice. It was released on
October 26, 2020, by JYP Entertainment and Republic Records. It is the group's first ...",
date: '2020',
thumbnails: [ [Object], [Object], [Object], [Object] ],
trackCount: 13,
totalRuntime: '43 minutes',
artist: [ [Artist] ]
},
tracks: [
Track {
lengthMs: 206000,
title: "I CAN'T STOP ME",
videoId: 'CM4CkVFmTds',
playlistId: 'OLAK5uy_nGyCX4aNigDzsvNSRZ63NPiH75wef3lCw',
url: 'https://www.youtube.com/watch?v=CM4CkVFmTds'
},
Track {
lengthMs: 180000,
title: 'HELL IN HEAVEN',
videoId: '0O18GnTW1CU',
playlistId: 'OLAK5uy_nGyCX4aNigDzsvNSRZ63NPiH75wef3lCw',
url: 'https://www.youtube.com/watch?v=0O18GnTW1CU'
},
Track {
lengthMs: 215000,
title: 'UP NO MORE',
videoId: 'Qgylz1pLFE0',
playlistId: 'OLAK5uy_nGyCX4aNigDzsvNSRZ63NPiH75wef3lCw',
url: 'https://www.youtube.com/watch?v=Qgylz1pLFE0'
},
....
]
}
*/
getArtist
▸ getArtist(browseId
): Promise
<ArtistURL
>
Fetches artist details from YouTube Music.
Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| browseId
| string
| The artist browseId
only, without https://....
|
Returns
Promise
<ArtistURL
>
An object containing data of the Artist requested.
Example
const ytms = await YoutubeMoosick.new();
const results = await ytms.getArtist('UCAq0pFGa2w9SjxOq0ZxKVIw');
console.log(results);
/*
ArtistURL {
headers: ArtistHeader {
artistName: 'TWICE',
description: 'Twice, commonly stylized as TWICE, is a South Korean girl grou
p formed by JYP Entertainment. The group is composed of nine members: Nayeon, Je
ongyeon, Momo, Sana, Jihyo, Mina, Dahyun, Chaeyoung, and Tzuyu. Twice was ...',
totalSubscribers: '11.5M',
thumbnails: [ [Thumbnails], [Thumbnails] ]
},
artistContents: ArtistContent {
albums: [
[Albums], [Albums],
[Albums], [Albums],
[Albums], [Albums],
[Albums], [Albums],
[Albums], [Albums]
],
single: [
[Single], [Single],
[Single], [Single],
[Single], [Single],
[Single], [Single],
[Single], [Single]
],
videos: [
[Videos], [Videos],
[Videos], [Videos],
[Videos], [Videos],
[Videos], [Videos],
[Videos], [Videos]
]
}
}
*/
getPlaylist
▸ getPlaylist(browseId
, contentLimit?
): Promise
<PlaylistURL
>
Fetches playlist details from YouTube Music.
Parameters
| Name | Type | Default value | Description |
| :------ | :------ | :------ | :------ |
| browseId
| string
| undefined
| The playlist browseId
only, without https://....
|
| contentLimit
| number
| 100
| Maximum amount of contents to get, defaults to 100 |
Returns
Promise
<PlaylistURL
>
An object containing data of the Playlist requested.
Example
const ytms = await YoutubeMoosick.new();
const results = await ytms.getPlaylist('PLXs921kKn8XT5_bq5kR2gQ_blPZ7DgyS1');
console.log(results);
/*
PlaylistURL {
headers: PlaylistHeader {
playlistName: 'The Chainsmokers - All We Know ft. Phoebe Ryan',
owner: 'Jakub Gabryš',
createdYear: 2021,
thumbnail: [ [Object], [Object], [Object] ],
songCount: 38,
approxRunTime: '1+ hours'
},
playlistContents: [
{
trackTitle: 'All We Know (feat. Phoebe Ryan)',
trackId: 'lEi_XBg2Fpk',
artist: [Array],
thumbnail: [Array]
},
{
trackTitle: 'The Chainsmokers ft. Phoebe Ryan : All We Know - Lyrics',
trackId: '4kNcLZ3kcZg',
artist: [Array],
thumbnail: [Array]
},
...
],
continuation: {
continuation: '4qmFsgIwEiRWTFBMWHM5MjFrS244WFQ1X2JxNWtSMmdRX2J************
GtnRURDTTBH',
clickTrackingParams: 'CBIQybcCIhMI1KHIoI7E8gIVC8***********'
}
}
*/
getAlbumBrowseId
▸ getAlbumBrowseId(listID
): Promise
<string
>
Gets the browseId
for the album based on the newer listID
Parameters
| Name | Type | Description |
| :------ | :------ | :------ |
| listID
| string
| The listID
of the album |
Returns
Promise
<string
>
String The browseID
of the album
Example:
const api = await MooSick.new();
const results = await api.getAlbumBrowseId('OLAK5uy_ljhFMBuzqiynvNq_3dC2QhQaz12zkD0LE');
console.log(results);
Tests
Tests are written in tape
npm run test
These tests are real life tests, they actually run a query to simulate a real life situation.
Contributing
All contributions are welcome. File an issue if you find something wrong, & a pull request if you can fix it.