muse
A library to interact with the YouTube Music (InnerTube) api.
Note: This library is still in development, and is not ready for production
use.
Usage
muse works on Deno, Node.js, the browser and any javascript environment that
supports ES modules and fetch.
You can read the docs for more information about
the usage of each function.
Don't forget to replace VERSION
with the
latest version
Deno
import * as muse from "https://deno.land/x/muse@VERSION/mod.ts";
const search_results = await muse.search("drake");
const rickroll = await muse.get_song("dQw4w9WgXcQ");
Browser
You'll need to use a CDN that supports ES modules, such as
esm.sh, jspm.io or
skypack.dev.
Proxy
You'll also need to use a proxy server to get around CORS errors. It's a good
idea to self host the proxy server
(cors-anywhere and
deno_deploy_cors_proxy
are good options).
import * as muse from "https://esm.sh/libmuse@VERSION";
muse.set_option("fetch", (url, options) => {
return fetch(`https://proxy.example.com/${url}`, options);
});
const search_results = await muse.search("top radio");
Node
First install using your preferred package manager (npm, yarn, pnpm etc.)
npm install libmuse
Then use it in by importing libmuse
. The Node version has the exact same
features as the Deno version.
import * as muse from "libmuse";
const artist = await muse.get_artist("UCvyjk7zKlaFyNIPZ-Pyvkng");
For the complete list of operations, see
the docs.
Auth
Currently, muse supports oauth authentication by posing as the YouTube TV app.
Here's the flow:
- Get a login code
- Go to the given login url, and type in the login code on a device that is
logged into a google account
- Get the OAuth token & refresh tokens
import * as muse from "https://deno.land/x/muse@VERSION/mod.ts";
const auth = muse.get_option("auth");
muse.setup({
store: new DenoFileStore("store/muse-store.json"),
debug: true,
});
const auth_flow = async () => {
if (auth.has_token()) return;
console.log("Getting login code...");
const loginCode = await auth.get_login_code();
console.log(
`Go to ${loginCode.verification_url} and enter the code: ${loginCode.user_code}`,
);
alert("Press enter when you have logged in");
console.log("Loading token...");
await auth.load_token_with_code(
loginCode.device_code,
loginCode.interval,
);
console.log("Logged in!", auth._token);
};
auth.addEventListener("requires-login", (event) => {
const resolve = event.detail;
resolve(auth_flow);
});
In the future, I plan to add support for other auth methods, such as cookies and
Youtube TV login codes.
Storage
You can pass in a storage object to the client to persist the auth token.
import * as muse from "https://deno.land/x/muse@VERSION/mod.ts";
const client = muse.setup({ store: muse.get_best_store() });
const client = muse.setup({ store: new muse.DenoFileStore("/path/to/file.json") });
const client = muse.setup({ store: new muse.LocalStorageStore() });
const client = muse.setup({ store: new muse.MemoryStore() });
class MyStore extends muse.Store {
get<T>(key: string): T | null;
set(key: string, value: unknown): void;
delete(key: string): void;
}
const client = muse.setup({ store: new MyStore() });
muse.setup({ auth: { } });
muse.setup({ store: });
muse.set_option("store", )
Operations
I'm currently targetting to match the ytmusicapi's capabilities.
search
browsing
explore
watch
library
playlists
uploads
Acknowledgements