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
Deno
import { get_song, search } from "https://deno.land/x/muse/mod.ts";
search("drake")
.then((data) => {
console.log("search results", data);
});
get_song("dQw4w9WgXcQ")
.then((data) => {
console.log("song", data);
});
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 { get_song, search } from "libmuse";
get_artist("UCvyjk7zKlaFyNIPZ-Pyvkng")
.then((data) => {
console.log("artist", data);
});
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 { get_option, setup } from "https://deno.land/x/muse/mod.ts";
import { RequiresLoginEvent } from "https://deno.land/x/muse/auth.ts";
const auth = get_option("auth");
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}`,
);
confirm("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 as RequiresLoginEvent).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 { setup } from "https://deno.land/x/muse/mod.ts";
import {
DenoFileStore,
get_default_store,
LocalStorageStore,
MemoryStore,
Store,
} from "https://deno.land/x/muse/store.ts";
const client = setup({ store: get_default_store() });
const client = setup({ store: new DenoFileStore("/path/to/file.json") });
const client = setup({ store: new LocalStorageStore() });
const client = setup({ store: new MemoryStore() });
class MyStore extends Store {
get<T>(key: string): T | null;
set(key: string, value: unknown): void;
delete(key: string): void;
}
const client = setup({ store: new MyStore() });
setup({ auth: { } });
setup({ store: });
Operations
I'm currently targetting to match the ytmusicapi's capabilities.
search
browsing
explore
watch
library
playlists
uploads
Acknowledgements