GithubHelp home page GithubHelp logo

vladdenisov / ytmusic-api Goto Github PK

View Code? Open in Web Editor NEW
46.0 2.0 8.0 547 KB

Unofficial YouTube Music API for NodeJS written in TypeScript

Home Page: https://vladdenisov.github.io/ytmusic-api/

License: MIT License

TypeScript 100.00%
typescript nodejs youtube-api youtube-music youtube-music-api ytmusicapi api javascript youtube node

ytmusic-api's Introduction

Unofficial YouTube Music API

GitHub last commit GitHub npm bundle size Snyk Vulnerabilities for GitHub Repo

Simple API Project for NodeJS written in TypeScript inspired by sigma67's python library

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development.

Prerequisites

  1. NodeJS 10+
  2. Yarn v2
  3. Google Account (optional)

Installing

Using npm

NPM

Building it yourself

Clone github repo

  $ git clone https://github.com/vladdenisov/ytmusic-api 

Install dependencies

  $ yarn

Build it

  $ yarn build

You will see dist folder, where all built files are stored.

Usage

Anonymous usage

You should be able to just use it, if you need only information-getting features:

  const api = new YTMUSIC()
  const data = await api.getPlaylist('RDCLAK5uy_k1Wu8QbZASiGVqr1wmie9NIYo38aBqscQ')
  console.log(data.title)

Getting the cookie

Get the auth cookie from requests to YTMusic in your browser:

  • Open YouTube Music in browser
  • Go to the developer tools (Ctrl-Shift-I) and find an authenticated POST request. You can filter for /browse to easily find a suitable request.
  • Copy cookie from Request Headers

Using in code

Import lib to your code:

  const { YTMUSIC } = require('ytmusic')
  // or if you build it yourself
  const { YTMUSIC } = require('path/to/ytmusic/dist/index.js')

Create new Instance of api with your cookie:

  const api = new YTMUSIC("cookie")

  // or if you want it to use not default account, specify userID (refer to docs to get it): 
  const api = new YTMUSIC("cookie", "userID")

Use it:

  const data = await api.getPlaylist('RDCLAK5uy_k1Wu8QbZASiGVqr1wmie9NIYo38aBqscQ')
  console.log(data.title)
  // { text: '80s Pop-Rock Anthems' }

Built With

  • TypeScript - JavaScript that scales.
  • node-fetch - A light-weight module that brings window.fetch to Node.js

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Just contribute <3

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE file for details

ytmusic-api's People

Contributors

deters avatar dhleong avatar sourack avatar vladdenisov 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

Watchers

 avatar  avatar

ytmusic-api's Issues

Browser usage

I see that this library uses node-fetch (by the way, Node finally added native Fetch in v17.5), but I'm thinking whether it's possible to use it in the browser as well.

One of the biggest problems to overcome in a browser context is CORS restrictions, which I think requires the user to provide a proxy themselves (like All Origins) that needs to be prepended before the URLs. Other than that, I don't really know if there are other things that could be affected, especially the request headers. I'm wondering if the author would be interested to support browser usage? @vladdenisov

Returning Empty Array.

Code:

const { YTMUSIC } = require("ytmusic");
const api = new YTMUSIC("COOKIE", "USER ID");
async function a() {
 let data = await api.search("boss bitch", { filter: "songs"})
 console.log(data)
}
a()

Search is not working

The search endpoint is not working right now...

let COOKIE = 'yyy';
let USER_ID = 'xxx';

import { YTMUSIC } from 'ytmusic';

const api = new YTMUSIC(COOKIE, { userID: USER_ID })

api.search('Hey Jude', { filter: 'songs' })
.then(console.log)
.catch(console.error)

------ result:

TypeError: Cannot read property 'contents' of undefined
at /home/deters/workspace/yti/node_modules/ytmusic/dist/lib/endpoints/Search.js:111:66
at step (/home/deters/workspace/yti/node_modules/ytmusic/dist/lib/endpoints/Search.js:52:23)
at Object.next (/home/deters/workspace/yti/node_modules/ytmusic/dist/lib/endpoints/Search.js:33:53)
at fulfilled (/home/deters/workspace/yti/node_modules/ytmusic/dist/lib/endpoints/Search.js:24:58)
at process._tickCallback (internal/process/next_tick.js:68:7)
[nodemon] clean exit - waiting for changes before restart

Cannot read property 'popup' of undefined

ytmusic/dist/lib/endpoints/Playlist.js 189 line
if I try to add song that already in a playlist it will give an error because response from api doesn't have openPopupAction

TypeError: Cannot read property 'popup' of undefined at...

Port to dart

Is it possible you can port this library to dart.

TypeError in Playlist.js

When I tried to run

const api = new YTMUSIC(
    "cookie",
    { userID: "" },
);
const data = await api.getPlaylist("RDCLAK5uy_k1Wu8QbZASiGVqr1wmie9NIYo38aBqscQ");
console.log(data);

Node exited with an error:

/Users/<path>/node_modules/ytmusic/dist/lib/endpoints/Playlist.js:128
                        album: e.flexColumns[2].musicResponsiveListItemFlexColumnRenderer.text.runs[0],
                                                                                                   ^

TypeError: Cannot read properties of undefined (reading '0')
    at /Users/<path>/node_modules/ytmusic/dist/lib/endpoints/Playlist.js:128:100
    at Array.map (<anonymous>)
    at /Users/<path>/node_modules/ytmusic/dist/lib/endpoints/Playlist.js:112:31
    at step (/Users/<path>/node_modules/ytmusic/dist/lib/endpoints/Playlist.js:52:23)
    at Object.next (/Users/<path>/node_modules/ytmusic/dist/lib/endpoints/Playlist.js:33:53)
    at fulfilled (/Users/<path>/node_modules/ytmusic/dist/lib/endpoints/Playlist.js:24:58)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Node.js v19.3.0

Any ideas why?

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.