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
4 changes: 2 additions & 2 deletions package-lock.json

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

94 changes: 49 additions & 45 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -597,55 +597,59 @@ void (async () => {

await Promise.all(
types.map(async (type) => {
// download/generate file data
let fileExt: String;
let fileData: Buffer;
switch (type) {
case "midi": {
fileExt = "mid";
const fileUrl = await getFileUrl(
scoreinfo.id,
"midi",
argv.input
);
fileData = await fetchBuffer(fileUrl);
break;
}
case "mp3": {
fileExt = "mp3";
const fileUrl = await getFileUrl(
scoreinfo.id,
"mp3",
argv.input
);
fileData = await fetchBuffer(fileUrl);
break;
}
case "pdf": {
fileExt = "pdf";
fileData = Buffer.from(
await exportPDF(
scoreinfo,
scoreinfo.sheet,
try {
// download/generate file data
let fileExt: String;
let fileData: Buffer;
switch (type) {
case "midi": {
fileExt = "mid";
const fileUrl = await getFileUrl(
scoreinfo.id,
"midi",
argv.input
)
);
break;
);
fileData = await fetchBuffer(fileUrl);
break;
}
case "mp3": {
fileExt = "mp3";
const fileUrl = await getFileUrl(
scoreinfo.id,
"mp3",
argv.input
);
fileData = await fetchBuffer(fileUrl);
break;
}
case "pdf": {
fileExt = "pdf";
fileData = Buffer.from(
await exportPDF(
scoreinfo,
scoreinfo.sheet,
argv.input
)
);
break;
}
}
}

// save to filesystem
const f = path.join(
argv.output,
`${scoreinfo.fileName}.${fileExt}`
);
await fs.promises.writeFile(f, fileData);
if (argv.verbose) {
spinner.info(
i18next.t("cli_saved_message", {
file: chalk.underline(f),
})
// save to filesystem
const f = path.join(
argv.output,
`${scoreinfo.fileName}.${fileExt}`
);
await fs.promises.writeFile(f, fileData);
if (argv.verbose) {
spinner.info(
i18next.t("cli_saved_message", {
file: chalk.underline(f),
})
);
}
} catch (e) {
spinner.fail(`Failed to download ${type}: ${e.message}`);
}
})
);
Expand Down
8 changes: 8 additions & 0 deletions src/file.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable no-extend-native */
/* eslint-disable @typescript-eslint/no-unsafe-return */

import isNode from "detect-node";
import md5 from "md5";
import { getFetch } from "./utils";
import { auths } from "./file-magics";
Expand All @@ -18,6 +19,10 @@ const getSuffix = async (scoreUrl: string): Promise<string | null> => {
),
].map((match) => match[1]);
} else {
if (isNode) {
// Cannot get suffix in node without a scoreUrl
return null;
}
suffixUrls = [
...document.head.innerHTML.matchAll(
/link.+?href=["'](https:\/\/musescore\.com\/static\/public\/build\/musescore.*?(?:_es6)?\/20.+?\.js)["']/g
Expand Down Expand Up @@ -58,6 +63,9 @@ const getApiAuthNetwork = async (
type: FileType,
index: number
): Promise<string> => {
if (isNode) {
throw new Error("getApiAuthNetwork is not supported in Node.js");
}
let numPages = 0;
let pageCooldown = 25;
if (!auths[type + index]) {
Expand Down