-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(release): Release version 2.7.2 (#96)
* chore(deps): bump winston from 3.3.2 to 3.3.3 Bumps [winston](https://github.com/winstonjs/winston) from 3.3.2 to 3.3.3. - [Release notes](https://github.com/winstonjs/winston/releases) - [Changelog](https://github.com/winstonjs/winston/blob/master/CHANGELOG.md) - [Commits](winstonjs/winston@v3.3.2...v3.3.3) Signed-off-by: dependabot[bot] <[email protected]> * chore(deps-dev): bump eslint from 7.3.0 to 7.3.1 Bumps [eslint](https://github.com/eslint/eslint) from 7.3.0 to 7.3.1. - [Release notes](https://github.com/eslint/eslint/releases) - [Changelog](https://github.com/eslint/eslint/blob/master/CHANGELOG.md) - [Commits](eslint/eslint@v7.3.0...v7.3.1) Signed-off-by: dependabot[bot] <[email protected]> * chore(deps-dev): bump @types/node from 14.0.13 to 14.0.14 Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 14.0.13 to 14.0.14. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node) Signed-off-by: dependabot[bot] <[email protected]> * chore(deps): Update ytdl-core to 3.1.2 * chore(docker): Cleanup Dockerfile * chore(docker): Cleanup Dockerfile * fix(HelpCommand): fix grammar * fix: Pass token from build function instead * feat(docker): Add volumes for cache * feat(caching): Some improvements * Add song length limiter for cache * Fix #81 by using a finish marker * feat: Make song titles clickable by using Markdown link Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
- Loading branch information
1 parent
943f602
commit 06893e6
Showing
17 changed files
with
159 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,4 +100,4 @@ dist | |
.tern-port | ||
|
||
# YTDL Caches | ||
*.webm | ||
cache/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,28 +6,11 @@ LABEL maintainer "Hazmi35 <[email protected]>" | |
WORKDIR /usr/Jukebox | ||
|
||
COPY . . | ||
RUN echo [INFO] Starting to build Docker image... \ | ||
&& echo [INFO] Installing build deps... \ | ||
&& apk add --no-cache --virtual .build-deps python g++ make git curl \ | ||
&& echo [INFO] Build deps installed! \ | ||
&& echo [INFO] Installing 3rd party packages... \ | ||
RUN apk add --no-cache --virtual .build-deps python3 build-base git curl \ | ||
&& apk add --no-cache --virtual .third-party ffmpeg \ | ||
&& echo [INFO] 3rd party packages installed! \ | ||
&& echo [INFO] Node version: $(node --version) \ | ||
&& echo [INFO] npm version: $(npm --version) \ | ||
&& echo [INFO] Yarn version: $(yarn --version) \ | ||
&& echo [INFO] Git version: $(git --version) \ | ||
&& echo [INFO] Installing npm packages... \ | ||
&& yarn install \ | ||
&& echo [INFO] All npm packages installed! \ | ||
&& echo [INFO] Everything looks okay. \ | ||
&& echo [INFO] Building TypeScript project... \ | ||
&& echo Using TypeScript version: $(node -p "require('typescript').version") \ | ||
&& npm run build \ | ||
&& echo [INFO] Done building TypeScript project! \ | ||
&& echo [INFO] Pruning devDependencies... \ | ||
&& yarn run build \ | ||
&& yarn install --production \ | ||
&& apk del .build-deps \ | ||
&& echo [INFO] Done! Starting bot with node | ||
&& apk del .build-deps | ||
|
||
CMD ["node", "dist/main.js"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
version: '2.4' | ||
|
||
services: | ||
bot: | ||
container_name: "jukebox-bot" | ||
build: | ||
services: | ||
bot: | ||
build: | ||
context: ./ | ||
dockerfile: Dockerfile | ||
restart: unless-stopped | ||
env_file: | ||
container_name: jukebox-bot | ||
env_file: | ||
- .env | ||
restart: unless-stopped | ||
volumes: | ||
- "./cache:/usr/Jukebox/cache" | ||
version: "2.4" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,48 @@ | ||
import { getInfo, downloadFromInfo, videoInfo, downloadOptions, videoFormat } from "ytdl-core"; | ||
import { Readable, PassThrough } from "stream"; | ||
import { resolve as resolvePath } from "path"; | ||
import { createReadStream, createWriteStream, existsSync } from "fs"; | ||
import { createReadStream, createWriteStream, existsSync, appendFileSync } from "fs"; | ||
|
||
// Inspired by ytdl-core-discord (https://github.com/amishshah/ytdl-core-discord) // 1048576 * 1 = 1MB | ||
export default function playSong(YoutubeLink: string, options: IdownloadOptions = { filter: "audio", quality: "highestaudio", highWaterMark: 1048576 * 32 }): Promise<ISongData> { | ||
return new Promise((resolve, reject) => { | ||
getInfo(YoutubeLink, (err, info) => { | ||
if (err) return reject(err); | ||
const canDemux: boolean = info.formats.find(filter)! && Number(info.length_seconds) != 0; | ||
getInfo(YoutubeLink).then((info) => { | ||
const canDemux: boolean = info.formats.find(filter)! && Number(info.videoDetails.lengthSeconds) != 0; | ||
options = canDemux ? { ...options, filter } : { ...options }; | ||
if (options.cache && info.formats.find(f => !f.live)) { | ||
const path = resolvePath(process.cwd(), "cache", `${info.video_id}.webm`); | ||
if (existsSync(resolvePath(path))) return resolve({ canDemux, info, stream: createReadStream(path), cache: true }); | ||
const data = downloadFromInfo(info, options); | ||
const stream = new PassThrough(); | ||
const cache = createWriteStream(path); | ||
data.on("data", (chunk) => { stream.write(chunk); cache.write(chunk); } ); | ||
data.on("end", () => { stream.end(); cache.end(); }); | ||
return resolve({ canDemux, info, stream, cache: false }); | ||
if (options.cache && info.formats.find(f => !f.live) && !(Number(info.videoDetails.lengthSeconds) >= options.cacheMaxLength!)) { | ||
const path = resolvePath(process.cwd(), "cache"); | ||
const filePath = resolvePath(path, `${info.videoDetails.videoId}.webm`); | ||
const finishMarkerPath = `${filePath}.jukeboxCacheFinish.marker`; | ||
if (existsSync(resolvePath(filePath))) { | ||
if (existsSync(resolvePath(finishMarkerPath))) return resolve({ canDemux, info, stream: createReadStream(filePath), cache: true }); | ||
return cache(info, options, canDemux, filePath, finishMarkerPath, resolve); | ||
} | ||
return cache(info, options, canDemux, filePath, finishMarkerPath, resolve); | ||
} | ||
return resolve({ canDemux, info, stream: downloadFromInfo(info, options), cache: false }); | ||
}); | ||
}).catch(reject); | ||
}); | ||
} | ||
|
||
function filter(f: videoFormat): boolean { | ||
return f.codecs === "opus" && f.container === "webm" && Number(f.audioSampleRate) === 48000; | ||
} | ||
|
||
function cache(info: videoInfo, options: IdownloadOptions, canDemux: boolean, path: string, finishMarkerPath: string, resolve: any,): any { | ||
const data = downloadFromInfo(info, options); | ||
const stream = new PassThrough(); | ||
const cache = createWriteStream(path) | ||
.on("close", () => appendFileSync(finishMarkerPath, "")); | ||
data.on("data", (chunk) => { stream.write(chunk); cache.write(chunk); } ); | ||
data.on("end", () => { stream.end(); cache.end(); }); | ||
return resolve({ canDemux, info, stream, cache: false }); | ||
} | ||
|
||
interface ISongData { | ||
canDemux: boolean; | ||
info: videoInfo; | ||
stream: Readable; | ||
cache: boolean; | ||
} | ||
|
||
interface IdownloadOptions extends downloadOptions { cache?: boolean } | ||
interface IdownloadOptions extends downloadOptions { cache?: boolean; cacheMaxLength?: number } |
Oops, something went wrong.