Giter Site home page Giter Site logo

baptistearno / node-youtube-music Goto Github PK

View Code? Open in Web Editor NEW
106.0 5.0 18.0 244 KB

Unofficial YouTube Music API for Node.js

License: GNU General Public License v3.0

JavaScript 0.43% TypeScript 99.57%
youtube api-wrapper api youtube-api youtube-search youtube-channel youtube-playlist youtube-video

node-youtube-music's Introduction

typescript-starter dark logo

Unofficial YouTube Music API for Node.js

version downloads install size

Features

  • Search
    • Musics
    • Playlists
    • Albums
    • Artists
  • List musics from playlist
  • List musics from album
  • List albums from artist
  • List musics from artist
  • Get suggestions from music
  • Playlist management (create, push, remove)
  • Library management

Get started

npm install node-youtube-music

or

yarn add node-youtube-music

How to use

import {
  searchMusics,
  searchAlbums,
  searchPlaylists,
  getSuggestions,
  listMusicsFromAlbum,
  listMusicsFromPlaylist,
  searchArtists,
  getArtist,
} from 'node-youtube-music';

const musics = await searchMusics('Never gonna give you up');

const albums = await searchAlbums('Human after all');

const playlists = await searchPlaylists('Jazz');

const suggestions = await getSuggestions(musics[0].youtubeId);

const albumSongs = await listMusicsFromAlbum(albums[0].albumId);

const playlistSongs = await listMusicsFromPlaylist(playlists[0].playlistId);

const artists = await searchArtists('Daft Punk');

const artist = await getArtist(artists[0].artistId);

node-youtube-music's People

Contributors

baptistearno avatar eyezahhhh avatar giorgi-o avatar imlinguin avatar to-dy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

node-youtube-music's Issues

Searching playlists throws error

Hey, thanks for creating this amazing API. I have some issues with searching playlists, do you mind taking a look?
TypeError: Cannot destructure property 'contents' of 'body.contents.tabbedSearchResultsRenderer.tabs[0].tabRenderer.content.sectionListRenderer.contents[0].musicShelfRenderer' as it is undefined.

listMusicsFromPlaylist seems to be broken

`node:internal/process/esm_loader:97
internalBinding('errors').triggerUncaughtException(
^

HTTPError: Response code 400 (Bad Request)
at Request. (C:\Users\obi_c\Desktop\project\music-test-node\node_modules\got\dist\source\as-promise\index.js:118:42)
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
code: 'ERR_NON_2XX_3XX_RESPONSE',
timings: {
start: 1670437178318,
socket: 1670437178319,
lookup: 1670437178320,
connect: 1670437178383,
secureConnect: 1670437178462,
upload: 1670437178462,
response: 1670437178534,
end: 1670437178537,
error: undefined,
abort: undefined,
phases: {
wait: 1,
dns: 1,
tcp: 63,
tls: 79,
request: 0,
firstByte: 72,
download: 3,
total: 219
}
}
}`

Suggestions seem to be broken

It seems to not be able to parse YouTube's response anymore. Here is what getSuggestions(id) returns for Stronger by Kanye:

[
  {
    youtubeId: '2ulp_AMut14',
    title: 'Stronger',
    artists: [ [Object] ],
    isExplicit: true,
    album: 'Graduation',
    thumbnailUrl: 'https://lh3.googleusercontent.com/LENzUxyoVSRKUEZrw6nG5cOajuDDnFaIQIbD3LW95HaLLNOW4IHHvpGl0nmCoyFpiQE93jtT2FJTJk2Oqg=w544-h544-l90-rj',
    duration: { label: '5:12', totalSeconds: 312 }
  },
  {
    youtubeId: undefined,
    title: undefined,
    artists: undefined,
    isExplicit: false,
    album: undefined,
    thumbnailUrl: undefined,
    duration: undefined
  }
]

There are also many warnings printed to the console, saying that it can't retrieve any of the attributes.

Artists support

As I started to work on artists, I encountered a few issues.

  • Not every artist has Songs section e.g Bella Poarch
  • I didn't found a way to distinguish sections between Albums, Singles and Videos

For now Artist object contains:

  • name - artist name
  • songsPlaylistId - id of the playlist with every song
  • description
  • thumbnails - array with artist's pictures in different resolutions

As I mentioned before songsPlaylistId isn't always defined. Also when artist has less than 5 songs songsPlaylistId isn't there too. I was thinking about featuredSongs, which would contain 5 or less songs listed in Songs section. There would be one caveat: API doesn't provide a duration of these songs.

What else should I add?

Error [ERR_REQUIRE_ESM]: require() of ES Module ...\node_modules\node-youtube-music\dist\index.js from ...\index.js not supported.

i've been getting these errors everytime i try to normally require the module, probably due to a broken esm

const { searchMusics } = require('node-youtube-music');
                         ^

Error [ERR_REQUIRE_ESM]: require() of ES Module C:\Users\User\Desktop\Recycle Bin\lucspyt\node_modules\node-youtube-music\dist\index.js from C:\Users\User\Desktop\Recycle Bin\lucspyt\index.js not supported.
Instead change the require of ...\node_modules\node-youtube-music\dist\index.js in ...\index.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (...\index.js:7:26) {
  code: 'ERR_REQUIRE_ESM'
}

luckily, i found a work-around with fix-esm:

const { searchMusics } = require("fix-esm").require('node-youtube-music');
searchMusics("Bound 2 - Kanye West")
    .then(function(data) {
        console.log(`https://www.youtube.com/watch?v=${data[0].youtubeId}`); //output should be https://www.youtube.com/watch?v=5gjKuISTMRE
    });

net getting artist details by id

{
"code": "ERR_NON_2XX_3XX_RESPONSE",
"timings": {
"start": 1699121342335,
"socket": 1699121342336,
"lookup": 1699121342336,
"connect": 1699121342375,
"secureConnect": 1699121342472,
"upload": 1699121342473,
"response": 1699121342596,
"end": 1699121342598,
"phases": {
"wait": 1,
"dns": 0,
"tcp": 39,
"tls": 97,
"request": 1,
"firstByte": 123,
"download": 2,
"total": 263
}
},
"name": "HTTPError",
"options": {
"agent": {},
"decompress": true,
"timeout": {},
"prefixUrl": "",
"body": "{"context":{"capabilities":{},"client":{"clientName":"WEB_REMIX","clientVersion":"0.1"}},"browseId":"https://www.youtube.com/watch?v=UCDxKh1gFWeYsqePvgVzmPoQ}\"}",
"ignoreInvalidCookies": false,
"context": {},
"hooks": {
"init": [],
"beforeRequest": [],
"beforeError": [],
"beforeRedirect": [],
"beforeRetry": [],
"afterResponse": []
},
"followRedirect": true,
"maxRedirects": 10,
"throwHttpErrors": true,
"username": "",
"password": "",
"http2": false,
"allowGetBody": false,
"headers": {
"user-agent": "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)",
"accept-language": "en",
"origin": "https://music.youtube.com",
"content-type": "application/json",
"content-length": "160",
"accept-encoding": "gzip, deflate, br"
},
"methodRewriting": false,
"retry": {
"limit": 2,
"methods": [
"GET",
"PUT",
"HEAD",
"DELETE",
"OPTIONS",
"TRACE"
],
"statusCodes": [
408,
413,
429,
500,
502,
503,
504,
521,
522,
524
],
"errorCodes": [
"ETIMEDOUT",
"ECONNRESET",
"EADDRINUSE",
"ECONNREFUSED",
"EPIPE",
"ENOTFOUND",
"ENETUNREACH",
"EAI_AGAIN"
],
"backoffLimit": null,
"noise": 100
},
"method": "POST",
"cacheOptions": {},
"https": {},
"resolveBodyOnly": false,
"isStream": false,
"responseType": "text",
"url": "https://music.youtube.com/youtubei/v1/browse?key=AIzaSyC9XL3ZjWddXya6X74dJoCTL-WEYFDNX30",
"pagination": {
"countLimit": null,
"backoff": 0,
"requestLimit": 10000,
"stackAllItems": false
},
"setHost": true,
"enableUnixSockets": true
}
}

geting thsi error

Use API key from YouTube Data API

I assume that the API key used to query youtube music is hard coded here. It would be better to have a configurable API key so that any one can use their Youtube Data API key to search music.

Add a license.

Hello, I suggest you to add a license to this project.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.