Giter Site home page Giter Site logo

codyduong / ytmusicapijs Goto Github PK

View Code? Open in Web Editor NEW
8.0 1.0 1.0 1.31 MB

Unofficial API for YouTube Music

Home Page: https://codyduong.github.io/ytmusicapiJS/

License: MIT License

JavaScript 0.41% TypeScript 98.66% Shell 0.37% Python 0.56%
ytmusicapi api nodejs node node-js music lyrics typescript ytmusic

ytmusicapijs's Introduction

Archived

ytmusicapiJS was a library I started as an idea to help me make a cli-based YT Music user interface with JavaScript/TypeScript. However, this was also one of the first proper libraries I ever properly attempted to bundle and publish to npm, as well as maintain some semblance of SemVer. It also heavily leaned on the ytmusicapi codebase, and should've been more decoupled. This has led to a variety of issues with supporting many environments, working/tested only in NodeJS, and probably rarely works as the average user expects it to (IE. in the browser).

I no longer have the time/willingness to maintain this library, and there are much better alternatives that have popped up since I have started ytmusicapiJS. As such I have decided to archive this repository, so as not to mislead anybody about its development status.

Please check out vixalien/muse as an alternative to ytmusicapiJS


Downloads Code coverage Latest release Commits since latest release

ytmusicapiJS: Unofficial API for YouTube Music

ytmusicapiJS is a TypeScript implementation of the Python 3 library ytmusicapi for NodeJS

It emulates YouTube Music web client requests using the user's cookie data for authentication.

This library is intended to carry the same functionality as the library it is inspired by. As such, unless the need becomes great enough for a specific feature in this library, I recommend all API specific changes be directed to ytmusicapi instead.

Features

See API here https://codyduong.github.io/ytmusicapiJS/

Setup and Usage

npm yarn
npm install @codyduong/ytmusicapi yarn add @codyduong/ytmusicapi

For authenticated requests

To run authenticated requests, set it up by first copying your request headers from an authenticated POST request in your browser. To do so, follow these steps:

  • Open a new tab
  • Open the developer tools (Ctrl-Shift-I) and select the “Network” tab
  • Go to https://music.youtube.com and ensure you are logged in
  • Find an authenticated POST request. The simplest way is to filter by /browse using the search bar of the developer tools. If you don’t see the request, try scrolling down a bit or clicking on the library button in the top bar.

A sample headers.json is provided below:

{
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:72.0) Gecko/20100101 Firefox/72.0",
    "Accept": "*/*",
    "Accept-Language": "en-US,en;q=0.5",
    "Content-Type": "application/json",
    "X-Goog-AuthUser": "0",
    "x-origin": "https://music.youtube.com",
    "Cookie" : "PASTE_COOKIE"
}

Either point to this file when instantiating YTMusic, or load the file with JSON.parse ahead of time and pass in the object.

const ytm = new YTMusic({auth: 'path/to/headers.json'})
const ytm = new YTMusic({auth: JSON.parse('path/to/headers.json')}
// Or even a raw string object is accepted
const ytm = new YTMusic({auth: fs.readFileSync('path/to/file', {encoding: 'utf-8'})}

Quick Usage

Quick Usage Snippet

import YTMusic from '@codyduong/ytmusicapi';

const ytm = new YTMusic()

const results = await ytm.search('Rickroll')

results

[
  {
    category: 'Top result',
    resultType: 'video',
    title: 'Never Gonna Give You Up',
    views: null,
    videoId: 'dQw4w9WgXcQ',
    duration: null,
    year: null,
    artists: [ [Object], [Object] ],
    thumbnails: [ [Object] ]
  },
  {
    category: 'Songs',
    resultType: 'song',
    title: 'Never Gonna Give You Up',
    album: null,
    feedbackTokens: { add: null, remove: null },
    videoId: 'lYBUbBu4W08',
    duration: null,
    year: null,
    artists: [ [Object], [Object] ],
    isExplicit: false,
    thumbnails: [ [Object], [Object] ]
  },
  {
    category: 'Songs',
    resultType: 'song',
    title: 'Rickroll',
    album: null,
    feedbackTokens: { add: null, remove: null },
    videoId: 'oBKeQItWbnA',
    duration: null,
    year: null,
    artists: [ [Object], [Object], [Object] ],
    isExplicit: false,
    thumbnails: [ [Object], [Object] ]
  },
  ...
]

Documentation

For more demos, look in tests/index.test.ts

Contributing

The library is intended to keep features within the same scope of the original Python 3 library. This may/may not change at my discretion.

Pull requests are welcome, esp. with regards to resolving any API differences that occured through mistakes or otherwise. However, note that I would like to remain with similar API to the original library, so it is unlikely new API features will be approved (unless strictly relevant to the JS/TS version).

The source code is structured almost identically to the Python 3 Library. I've also mocked some other dependencies, this is to maintain readability and ease of changes between the two APIs.

Acknowledgements

A majority of this codebase is possible thanks to the work done by sigma67

ytmusicapijs's People

Contributors

codyduong avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

ndlm46

ytmusicapijs's Issues

401 on authenticated actions

data: {
      error: {
        code: 401,
        message: 'You must be signed in to perform this operation.',
        errors: [
          {
            message: 'You must be signed in to perform this operation.',
            domain: 'global',
            reason: 'unauthorized'
          }
        ],
        status: 'UNAUTHENTICATED'
      }
    }

Despite YTMusic.checkAuth() returning valid.

Remove postinstall

Find an alternative way for pre-commit hooks, since this will run when people use the library as well.

0.4.1 CI/CD Failure

  ● Browsing › Get Lyrics › #2
    TypeError: Cannot read properties of undefined (reading 'playlistPanelRenderer')
      152 |
      153 |       //Waiting on bugfix for nav nested arrays objects
    > 154 |       const results = nav(watchNextRenderer, [
          |                       ^
      155 |         ...TAB_CONTENT,
      156 |         'musicQueueRenderer',
      157 |         'content',
      at nav (node_modules/@codyduong/nav/dist/index.js:9:28)
      at UploadsMixin.getWatchPlaylist (src/mixins/watch.ts:154:23)
          at runMicrotasks (<anonymous>)
      at Object.<anonymous> (tests/index.test.ts:313:24)

Remove Null

There is too much inconsistency between usage of null and undefined.

Originally this was a stand-in for the None type from python, however the handling has never been consistent, where in some places we explicitly set something to Null, and in others we simply do not set it at all (after checking some data).

0.5.0-rc.1 Resolve getSongRelated

The CI/CD test is failing. I think the code is exactly the same as the parent library. But there needs to be more investigation before I can release 0.5.0

Create fallback for locales

Currently, we have any English text displayed in locales, pasted throughout the .json locales, ex. playlist in de.json.

Perhaps it may be better for this to fallback to en.json rather than explicitly declaring it in de.json.

Kept open as an issue, just as a note to myself. Will remain open as long as I deliberate over what to do about it.

Remove webpack

Originally webpack was added to add support for the API in browsers, however it has proven just to be a headache in terms of dependencies as well as packaging the code.

Given the limited usage as a web API, I will remove browser compatibility. This is technically a breaking change, but I will not change the major version, just because, namely I do what I want. And because I don't imagine this API will have many users whose use case involves browser with a proxy.

Resolve outstanding issues with for of/for in

Python has different syntax when handling for of/for in loops for objects/arrays.

However, since I had to assume some types, it's entirely possible the shape of these objects are wrong. This can be resolved when I go around typing everything, but until then put this on the backburner as a reminder to double check all the for loops.

The lazy choice is to make some helper function that accepts both objects and arrays.

1.0.0 parity

Breaking Changes

  • Add OAuth
  • Change duration_seconds to durationSeconds

0.23.0 parity

  • #16
    • Downgrades from ES2021 to ES2015
    • ytmusicapi/continuations.py
    • ytmusicapi/mixins/browsing.py
    • ytmusicapi/helpers.py
    • ytmusicapi/mixins/library.py
    • ytmusicapi/mixins/playlists.py
    • ytmusicapi/mixins/search.py
    • ytmusicapi/mixins/uploads.py
    • ytmusicapi/mixins/watch.py
    • ytmusicapi/navigation.py
    • ytmusicapi/parsers/browsing.py
    • ytmusicapi/parsers/library.py
  • .github/workflows/coverage.yml
  • docs/source/setup.rst
  • tests/test.py
  • ytmusicapi/ytmusic.py

Browser Support

Need to use webpack for this. Or rollup or snowpack or whatever...

ERROR in ./node_modules/@codyduong/ytmusicapi/dist/helpers.js 52:28-45

Module not found: Error: Can't resolve 'crypto' in 'C:\Users\duong\Documents\GitHub\test-dir\node_modules\@codyduong\ytmusicapi\dist'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
	- add a fallback 'resolve.fallback: { "crypto": require.resolve("crypto-browserify") }'
	- install 'crypto-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
	resolve.fallback: { "crypto": false }


ERROR in ./node_modules/@codyduong/ytmusicapi/dist/mixins/uploads.js 29:13-26

Module not found: Error: Can't resolve 'fs' in 'C:\Users\duong\Documents\GitHub\test-dir\node_modules\@codyduong\ytmusicapi\dist\mixins'


ERROR in ./node_modules/@codyduong/ytmusicapi/dist/mixins/uploads.js 31:15-30

Module not found: Error: Can't resolve 'path' in 'C:\Users\duong\Documents\GitHub\test-dir\node_modules\@codyduong\ytmusicapi\dist\mixins'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
	- add a fallback 'resolve.fallback: { "path": require.resolve("path-browserify") }'
	- install 'path-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
	resolve.fallback: { "path": false }


ERROR in ./node_modules/@codyduong/ytmusicapi/dist/setup.js 51:24-37

Module not found: Error: Can't resolve 'fs' in 'C:\Users\duong\Documents\GitHub\test-dir\node_modules\@codyduong\ytmusicapi\dist'


ERROR in ./node_modules/@codyduong/ytmusicapi/dist/ytmusic.js 73:24-37

Module not found: Error: Can't resolve 'fs' in 'C:\Users\duong\Documents\GitHub\test-dir\node_modules\@codyduong\ytmusicapi\dist'


ERROR in ./node_modules/@codyduong/ytmusicapi/dist/ytmusic.js 83:32-48

Module not found: Error: Can't resolve 'https' in 'C:\Users\duong\Documents\GitHub\test-dir\node_modules\@codyduong\ytmusicapi\dist'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
	- add a fallback 'resolve.fallback: { "https": require.resolve("https-browserify") }'
	- install 'https-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
	resolve.fallback: { "https": false }

Remove fs

fs is node-only. Remove this, instead users parse their auth.json ahead of time.

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.