From 729466a03193b00b0848f504c659fb493938cabc Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Wed, 27 Mar 2024 20:03:05 +0200 Subject: [PATCH] Downloading from spotify works properly --- Dockerfile | 9 ++++----- src/client/components/MusicDownloader.ts | 4 ++-- src/client/components/MusicLibrary.ts | 2 +- src/client/components/downloaders/Spotify.ts | 3 +++ 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 47ad225..f3d88f9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,4 @@ +FROM zotify as zotify FROM node:lts-alpine as builder RUN apk update && apk add build-base python3 @@ -10,13 +11,11 @@ RUN yarn install FROM node:lts-alpine RUN apk update && apk add ffmpeg -# RUN python3 -m ensurepip -# RUN python3 -m pip install --user pipx -# RUN pipx install https://get.zotify.xyz +COPY --from=zotify /app/dist/zotify /bin/zotify WORKDIR /musicbot COPY build build COPY --from=builder /musicbot/node_modules ./node_modules COPY package.json package.json VOLUME [ "/musicbot/cache" ] -CMD ["node", "--enable-source-maps", "build/index.js"] -# CMD ["/bin/ash"] \ No newline at end of file +# CMD ["node", "--enable-source-maps", "build/index.js"] +CMD ["/bin/ash"] \ No newline at end of file diff --git a/src/client/components/MusicDownloader.ts b/src/client/components/MusicDownloader.ts index 6aeca14..da67ceb 100644 --- a/src/client/components/MusicDownloader.ts +++ b/src/client/components/MusicDownloader.ts @@ -14,13 +14,13 @@ class MusicDownloader implements Initialisable #logger: LoggerClient; #client: DiscordClient; #downloadDir: string; - constructor (client: DiscordClient) + constructor (client: DiscordClient, downloads?: string) { this.#ready = false; this.#logger = client.createLogger(this); this.#client = client; this.#availableDownloaders = new Collection(); - this.#downloadDir = 'Z:\\media\\downloads'; + this.#downloadDir = downloads ?? './cache/downloads'; } async initialise (): Promise diff --git a/src/client/components/MusicLibrary.ts b/src/client/components/MusicLibrary.ts index 22429cc..71c9332 100644 --- a/src/client/components/MusicLibrary.ts +++ b/src/client/components/MusicLibrary.ts @@ -26,7 +26,7 @@ class MusicLibrary implements Initialisable this.#path = libraryPath; this.#ready = false; this.#index = new Collection(); - this.#downloader = new MusicDownloader(client); + this.#downloader = new MusicDownloader(client, path.join(libraryPath, '.downloads')); this.#logger = client.createLogger(this); this.#currentId = 0; } diff --git a/src/client/components/downloaders/Spotify.ts b/src/client/components/downloaders/Spotify.ts index 2fb4531..1195c8e 100644 --- a/src/client/components/downloaders/Spotify.ts +++ b/src/client/components/downloaders/Spotify.ts @@ -28,6 +28,8 @@ class SpotifyDownloader extends Downloader '--output "{artist} - {song_name} - {album}.{ext}"', '--print-downloads true', ]; + if (process.env.CREDENTIAL_PATH) + this.#options.push('--credentials-location ' + process.env.CREDENTIAL_PATH); } override test (): void | Promise @@ -99,6 +101,7 @@ class SpotifyDownloader extends Downloader ext }); }); + // child.stdout?.on('data', (chunk => this.logger.debug('child stdout:', chunk))); }); }