Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: vixalien/muse
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.0.31
Choose a base ref
...
head repository: vixalien/muse
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
Loading
Showing with 2,473 additions and 1,591 deletions.
  1. +2 −0 .github/FUNDING.yml
  2. +25 −0 .github/workflows/main.yaml
  3. +2 −2 .github/workflows/npm.yaml
  4. +37 −83 README.md
  5. +0 −137 client.ts
  6. +2 −1 deno.json
  7. +165 −96 deno.lock
  8. +0 −2 deps.ts
  9. +52 −0 examples/authentication.ts
  10. +9 −0 examples/proxy.ts
  11. +1 −1 locales/strings.json
  12. +0 −431 locales/strings.ts
  13. +1 −9 mod.ts
  14. +0 −80 parsers/albums.ts
  15. +0 −73 parsers/types.d.ts
  16. +6 −0 { → scripts}/locales/README.md
  17. +1 −1 { → scripts}/locales/get.ts
  18. +321 −0 scripts/locales/strings.ts
  19. +22 −19 scripts/npm.ts
  20. +40 −7 { → src}/auth.ts
  21. +36 −2 { → src}/constants-ng.json
  22. +26 −4 { → src}/continuations.ts
  23. +3 −0 src/deps.ts
  24. +2 −0 { → src}/errors.ts
  25. +47 −7 { → src}/mixins/_request.ts
  26. +259 −88 { → src}/mixins/browsing.ts
  27. +29 −10 { → src}/mixins/explore.ts
  28. +115 −69 { → src}/mixins/library.ts
  29. +219 −90 { → src}/mixins/playlist.ts
  30. +159 −19 { → src}/mixins/queue.ts
  31. +48 −1 { → src}/mixins/search.ts
  32. +7 −6 { → src}/mixins/uploads.ts
  33. +40 −0 { → src}/mixins/utils.ts
  34. +16 −0 src/mod.ts
  35. +32 −2 { → src}/nav.ts
  36. +71 −0 src/parsers/albums.ts
  37. +199 −119 { → src}/parsers/browsing.ts
  38. +2 −2 { → src}/parsers/explore.ts
  39. +18 −110 { → src}/parsers/library.ts
  40. +7 −8 { → src}/parsers/playlists.ts
  41. +44 −5 { → src}/parsers/queue.ts
  42. +105 −52 { → src}/parsers/search.ts
  43. +198 −8 { → src}/parsers/songs.ts
  44. 0 { → src}/parsers/uploads.ts
  45. 0 { → src}/parsers/util.ts
  46. +10 −17 { → src}/request.ts
  47. +4 −2 { → src}/setup.ts
  48. +4 −1 { → src}/store.ts
  49. +16 −13 { → src}/util.ts
  50. +58 −0 src/util/cache-fetch.ts
  51. +1 −1 tests/asserts.ts
  52. +8 −8 tests/browsing/utils.test.ts
  53. +0 −1 tests/deps.ts
  54. +1 −1 tests/parsers/util.test.ts
  55. +1 −1 tests/util.test.ts
  56. +2 −2 tests/util.ts
2 changes: 2 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github: vixalien
custom: ["https://www.buymeacoffee.com/vixalien"]
25 changes: 25 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Run Unit Tests

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Deno
uses: denoland/setup-deno@v2
with:
deno-version: v2.x

- name: Lint
run: deno lint
4 changes: 2 additions & 2 deletions .github/workflows/npm.yaml
Original file line number Diff line number Diff line change
@@ -12,9 +12,9 @@ jobs:
fetch-depth: 0

- name: Setup Deno
uses: denoland/setup-deno@v1
uses: denoland/setup-deno@v2
with:
deno-version: v1.x
deno-version: v2.x

- name: Get tag version
if: startsWith(github.ref, 'refs/tags/')
120 changes: 37 additions & 83 deletions README.md
Original file line number Diff line number Diff line change
@@ -19,23 +19,16 @@ Don't forget to replace `VERSION` with the
### Deno

```ts
import { get_song, search } from "https://deno.land/x/muse@VERSION/mod.ts";
import * as muse from "https://deno.land/x/muse@VERSION/mod.ts";

// you can also use the latest version (not recommended) with
// import { get_song, search } from "https://deno.land/x/muse/mod.ts";
// import * as muse from "https://deno.land/x/muse/mod.ts";

// you can also import directly from github
// import { get_song, search } from "https://raw.githubusercontent.com/vixalien/muse/VERSION/mod.ts";
// import * as muse from "https://raw.githubusercontent.com/vixalien/muse/VERSION/mod.ts";

search("drake")
.then((data) => {
console.log("search results", data);
});

get_song("dQw4w9WgXcQ")
.then((data) => {
console.log("song", data);
});
const search_results = await muse.search("drake");
const rickroll = await muse.get_song("dQw4w9WgXcQ");
```

### Browser
@@ -44,24 +37,26 @@ You'll need to use a CDN that supports ES modules, such as
[esm.sh](https://esm.sh/), [jspm.io](https://jspm.io/) or
[skypack.dev](https://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](https://github.com/Rob--W/cors-anywhere) and
[deno_deploy_cors_proxy](https://github.com/justjavac/deno_deploy_cors_proxy/)
are good options).

```js
import { search, set_option } from "https://esm.sh/libmuse@VERSION";
import * as muse from "https://esm.sh/libmuse@VERSION";

// import { search, set_option } from "https://jspm.dev/npm:libmuse@VERSION";
// import { search, set_option } from "https://cdn.skypack.dev/libmuse@VERSION";
// import * as muse from "https://jspm.dev/npm:libmuse@VERSION";
// import * as muse from "https://cdn.skypack.dev/libmuse@VERSION";

set_option("proxy", "https://proxy.example.com/");
// setting up our proxy
muse.set_option("fetch", (url, options) => {
return fetch(`https://proxy.example.com/${url}`, options);
});

search("top radio")
.then((data) => {
console.log("search results", data);
});
const search_results = await muse.search("top radio");
```

### Node
@@ -76,13 +71,10 @@ Then use it in by importing `libmuse`. The Node version has the exact same
features as the Deno version.

```js
import { get_song, search } from "libmuse";
// commonjs: const { get_artist } = require("libmuse");
import * as muse from "libmuse";
// commonjs: const muse = require("libmuse");

get_artist("UCvyjk7zKlaFyNIPZ-Pyvkng")
.then((data) => {
console.log("artist", data);
});
const artist = await muse.get_artist("UCvyjk7zKlaFyNIPZ-Pyvkng");
```

For the complete list of operations, see
@@ -100,21 +92,11 @@ Here's the flow:
3. Get the OAuth token & refresh tokens

```ts
import { get_option, setup } from "https://deno.land/x/muse@VERSION/mod.ts";

/*
node imports:
import { get_option, setup } from "libmuse";
import * as muse from "https://deno.land/x/muse@VERSION/mod.ts";

commonjs imports:
const auth = muse.get_option("auth");

const { get_option, setup } = require("libmuse");
*/

const auth = get_option("auth");

setup({
muse.setup({
// make sure to persist the token
store: new DenoFileStore("store/muse-store.json"),
debug: true,
@@ -132,7 +114,7 @@ const auth_flow = async () => {
);

// not necessary, but saves some requests
confirm("Press enter when you have logged in");
alert("Press enter when you have logged in");

console.log("Loading token...");

@@ -161,66 +143,38 @@ Youtube TV login codes.
You can pass in a storage object to the client to persist the auth token.

```ts
import { setup } from "https://deno.land/x/muse@VERSION/mod.ts";
import {
DenoFileStore,
get_default_store,
LocalStorageStore,
MemoryStore,
Store,
} from "https://deno.land/x/muse@VERSION/store.ts";

/*
npm imports:
import { setup } from "libmuse";
import {
DenoFileStore,
get_default_store,
LocalStorageStore,
MemoryStore,
Store,
} from "libmuse/store.js";
commonjs imports:
const { setup } = require("libmuse");
const {
DenoFileStore,
get_default_store,
LocalStorageStore,
MemoryStore,
Store,
} = require("libmuse/store.js");
*/

// you can use the default store, which is DenoFileStore if available, then LocalStorageStore, then MemoryStore
const client = setup({ store: get_default_store() });
import * as muse from "https://deno.land/x/muse@VERSION/mod.ts";

// you can use the "best" store, which is DenoFileStore if available, then LocalStorageStore, then MemoryStore
const client = muse.setup({ store: muse.get_best_store() });

// or you can use any of the built-in stores
const client = setup({ store: new DenoFileStore("/path/to/file.json") });
const client = setup({ store: new LocalStorageStore() });
const client = setup({ store: new MemoryStore() });
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() });

// or you can implement your own store
// by extending the Store abstract class
class MyStore extends Store {
class MyStore extends muse.Store {
get<T>(key: string): T | null;
set(key: string, value: unknown): void;
delete(key: string): void;
}

// then use it accordingly
const client = setup({ store: new MyStore() });
const client = muse.setup({ store: new MyStore() });

// Do note that setup() can be called multiple times, but it's not recommended.
// this is because setup overrides the global store, so if you call setup()
// multiple times, other options set before will be ignored. example:

setup({ auth: { /* custom auth options */ } });
setup({ store: /* custom store */ });
muse.setup({ auth: { /* custom auth options */ } });
muse.setup({ store: /* custom store */ });

// the above will only use the custom store, and ignore the custom auth options

// if you need to configure options many times use `muse.set_option`
muse.set_option("store", /* custom store */)
```

## Operations
@@ -257,7 +211,7 @@ I'm currently targetting to match the [ytmusicapi]'s capabilities.

### watch

- [x] get queue ~get watch playlist~
- [x] get queue ~~get watch playlist~~

### library

137 changes: 0 additions & 137 deletions client.ts

This file was deleted.

3 changes: 2 additions & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"tasks": {
"start": "deno run --allow-net --allow-read --allow-write --allow-env=DEBUG ./client.ts",
"example": "deno run --allow-net --allow-read --allow-write --allow-env=DEBUG ./examples/authentication.ts",
"test": "deno test --allow-net --allow-read --allow-write --allow-env=DEBUG --fail-fast ./tests/",
"npm": "deno run -A ./scripts/npm.ts"
},
"lint": {
"rules": {
"include": ["no-import-assertions"],
"exclude": ["no-explicit-any"]
}
}
Loading