npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

youtube-moosick

v0.3.0-rc1

Published

Unofficial Youtube music API, fully written in TypeScript

Downloads

82

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.

Authors

License

MIT