Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"tasks": {
"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/",
"test2": "deno test src",
"npm": "deno run -A ./scripts/npm.ts"
},
"lint": {
Expand Down
160 changes: 21 additions & 139 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 6 additions & 7 deletions examples/authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,9 @@ auth.addEventListener("requires-login", (event) => {
resolve(auth_flow);
});

muse.get_library()
.then((data) => {
return Deno.writeTextFile(
"store/library.json",
JSON.stringify(data, null, 2),
);
});
const data = await muse.get_home();

await Deno.writeTextFile(
"store/home.json",
JSON.stringify(data, null, 2),
);
45 changes: 45 additions & 0 deletions src/mixins2/browse/home.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { request_json } from "../../mixins/_request.ts";

import { RawJSON } from "../../parsers2/types.d.ts";
import { parse_single_column_browse_results_renderer } from "../../parsers2/tabs/mod.ts";
import { parse_background, Thumbnail } from "../../parsers2/thumbnail/mod.ts";
import { parse_mood_chips } from "../../parsers2/chips/mod.ts";
import { ParseMoodChipResult } from "../../parsers2/chips/mood.ts";
import { parse_section_list } from "../../parsers2/list/mod.ts";
import { parse_music_carousel_shelf_renderers } from "../../parsers2/music_carousel/mod.ts";
import { parse_music_two_row_item_renderer } from "../../parsers2/items/mod.ts";

export type MoodChip = ParseMoodChipResult;

export interface Home {
moods: MoodChip[];
thumbnails: Thumbnail[];
continuation: string | null;
content: RawJSON;
}

export async function get_home(): Promise<Home> {
const json = await request_json("browse", {
data: { browseId: "FEmusic_home" },
});

const background = parse_background(json);
const tab = parse_single_column_browse_results_renderer(json.contents).tab;
const section_list = parse_section_list(tab.content);
const moods = parse_mood_chips(section_list.header);

const contents = parse_music_carousel_shelf_renderers(section_list.contents)
.map((content) => {
return {
...content,
contents: content.contents.map(parse_music_two_row_item_renderer),
};
});

return {
moods,
thumbnails: background.thumbnails,
continuation: section_list.nextContinuation,
content: contents,
};
}
1 change: 1 addition & 0 deletions src/mixins2/browse/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./home.ts";
1 change: 1 addition & 0 deletions src/mixins2/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./browse/mod.ts";
10 changes: 1 addition & 9 deletions src/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,4 @@ export * from "./errors.ts";
export * from "./request.ts";
export * from "./auth.ts";

export * from "./mixins/browsing.ts";
export * from "./mixins/explore.ts";
export * from "./mixins/library.ts";
export * from "./mixins/playlist.ts";
export * from "./mixins/queue.ts";
export * from "./mixins/search.ts";
export * from "./mixins/uploads.ts";

export type * from "./mixins/utils.ts";
export * from "./mixins2/mod.ts";
26 changes: 26 additions & 0 deletions src/parsers2/chips/_chip_list.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { expect } from "jsr:@std/expect";
import { describe, it } from "jsr:@std/testing/bdd";

import { _parse_chips_list } from "./_chip_list.ts";

describe("_parse_chips_list", () => {
const stub_parser = (t: string) => t;

it("parses chips", () => {
expect(
_parse_chips_list(
{ chipCloudRenderer: { chips: ["hello"] } },
stub_parser,
)[0],
).toBe("hello");
});

it("produces expected amount of chips", () => {
expect(
_parse_chips_list(
{ chipCloudRenderer: { chips: ["hello", "world", "!"] } },
stub_parser,
),
).toHaveLength(3);
});
});
7 changes: 7 additions & 0 deletions src/parsers2/chips/_chip_list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Parser, RawJSON } from "../types.d.ts";

export function _parse_chips_list<T>(content: RawJSON, parser: Parser<T>): T[] {
const chips = content.chipCloudRenderer.chips;

return chips.map(parser);
}
59 changes: 59 additions & 0 deletions src/parsers2/chips/chip.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { assert } from "jsr:@std/assert/assert";
import { expect } from "jsr:@std/expect";
import { describe, it } from "jsr:@std/testing/bdd";

import { EndpointType } from "../endpoint/mod.ts";
import { parse_chip } from "./chip.ts";
import { RawJSON } from "../types.d.ts";

describe("parse_text_runs_simple", () => {
const text = { runs: [{ text: "Chip Title" }] };

function getChip(overrides: RawJSON) {
return {
chipCloudChipRenderer: {
text,
isSelected: false,
navigationEndpoint: {},
...overrides,
},
};
}

describe("parses selected", () => {
it("parses selected false", () => {
expect(
parse_chip(getChip({ isSelected: false })).selected,
).toBe(false);
});

it("parses selected false", () => {
expect(
parse_chip(getChip({ isSelected: true })).selected,
).toBe(true);
});
});

it("parses text", () => {
expect(
parse_chip(getChip({ text: { runs: [{ text: "Hello, World!" }] } })).text,
).toBe("Hello, World!");
});

it("parses navigation", () => {
const chip = parse_chip(getChip({
navigationEndpoint: {
browseEndpoint: {
browseId: "BROWSE_ID",
params: "PARAMS",
},
},
}));

assert(chip.navigation.browse, "must parse a browse endpoint");

expect(
chip.navigation.browse.type,
).toBe(EndpointType.BROWSE);
});
});
Loading