diff --git a/dev-tools/audius-cmd b/dev-tools/audius-cmd index 68a1b188e82..b722fb506eb 100755 --- a/dev-tools/audius-cmd +++ b/dev-tools/audius-cmd @@ -5,4 +5,24 @@ if [[ "$PROTOCOL_DIR" != "" ]]; then cd $PROTOCOL_DIR fi -docker compose exec audius-cmd node src/index.mjs "$@" +# modify :file args to path inside the container +tmpfiles=() +updated_args=() +for arg in "$@"; do + echo "$arg" + if [[ "$arg" == :* ]]; then + filename="${arg:1}" + tmpfile="/tmp/$RANDOM.${filename#*.}" + tmpfiles+=("$tmpfile") + updated_args+=(":$tmpfile") + docker compose cp "${arg:1}" audius-cmd:$tmpfile + else + updated_args+=("$arg") + fi +done + +docker compose exec audius-cmd node src/index.mjs "${updated_args[@]}" || true + +for tmpfile in "${tmpfiles[@]}"; do + docker compose exec audius-cmd rm $tmpfile +done diff --git a/dev-tools/commands/Dockerfile b/dev-tools/commands/Dockerfile index 1aab236ecf8..fa74b9948f6 100644 --- a/dev-tools/commands/Dockerfile +++ b/dev-tools/commands/Dockerfile @@ -2,6 +2,8 @@ FROM node:14 WORKDIR /usr/src/app +RUN apt update && apt install -y ffmpeg + COPY package*.json . RUN --mount=type=cache,target=/usr/src/app/.npm \ npm set cache /usr/src/app/.npm && \ diff --git a/dev-tools/commands/src/index.mjs b/dev-tools/commands/src/index.mjs index 1e748acd605..22cb00fac36 100644 --- a/dev-tools/commands/src/index.mjs +++ b/dev-tools/commands/src/index.mjs @@ -11,6 +11,7 @@ import "./repost-playlist.mjs"; import "./tip-audio.mjs"; import "./unfollow.mjs"; import "./auth-headers.mjs"; +import "./upload-track.mjs"; async function main() { program.parseAsync(process.argv); diff --git a/dev-tools/commands/src/upload-track.mjs b/dev-tools/commands/src/upload-track.mjs new file mode 100644 index 00000000000..4a7a5ba78eb --- /dev/null +++ b/dev-tools/commands/src/upload-track.mjs @@ -0,0 +1,107 @@ +import { randomBytes } from "crypto"; +import { createReadStream } from "fs"; +import { spawn } from "child_process"; + +import chalk from "chalk"; +import { program } from "commander"; + +import { initializeAudiusLibs } from "./utils.mjs"; + +function generateWhiteNoise(duration, outFile) { + return new Promise((resolve, reject) => { + const process = spawn("ffmpeg", [ + "-f", // audio/video filtering framework + "lavfi", // provides generic audio filtering for audio/video signals + "-i", // input flag + `anoisesrc=d=${duration}`, // generate a noise audio signal for the duration + outFile, // output filepath + "-y" // overwrite existing file + ]); + + let error = ""; + + process.stderr.on("data", data => { error += data; }); + process.on("close", (returncode) => { + if (returncode !== 0) { + reject(new Error(`Failed to generate white noise: ${error}`)); + } else { + resolve(); + } + }); + }); +} + +program.command("upload-track") + .description("Upload a new track") + .argument("[track]", "The handle for the new user", "%1m") + .option("-t, --title