Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

Commit

Permalink
feat(play-dl): git-less download
Browse files Browse the repository at this point in the history
  • Loading branch information
Mednoob authored and mzrtamp committed Jul 21, 2024
1 parent 402a6c9 commit a807b19
Show file tree
Hide file tree
Showing 3 changed files with 173 additions and 9 deletions.
17 changes: 14 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
/* eslint-disable node/no-sync */
import { execSync } from "node:child_process";
import { existsSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { cpSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { Server } from "node:http";
import nodePath from "node:path";
import process from "node:process";
import got from "got";
import prism from "prism-media";
import { extract } from "zip-lib";
import { downloadExecutable } from "./yt-dlp-utils/index.js";

const ensureEnv = arr => arr.every(x => process.env[x] !== undefined);
Expand Down Expand Up @@ -109,8 +111,17 @@ if (isGlitch || isReplit) {
const streamStrategy = process.env.STREAM_STRATEGY;
if (streamStrategy !== "play-dl") await downloadExecutable();
if (streamStrategy === "play-dl" && !existsSync(nodePath.resolve(process.cwd(), "play-dl-fix"))) {
console.log("[INFO] Cloning play-dl fix...");
execSync("git clone https://github.com/YuzuZensai/play-dl-test.git play-dl-fix && cd play-dl-fix && git reset --hard 2bfbfe6");
console.log("[INFO] Downloading play-dl fix...");
writeFileSync(nodePath.resolve(process.cwd(), "temp.zip"), await got.get("https://github.com/YuzuZensai/play-dl-test/archive/2bfbfe6decd68261747ba55800319f9906f12b03.zip").buffer());

console.log("[INFO] Extracting play-dl fix...");
mkdirSync(nodePath.resolve(process.cwd(), "play-dl-fix"), { recursive: true });
await extract(nodePath.resolve(process.cwd(), "temp.zip"), nodePath.resolve(process.cwd(), "play-dl-fix"), { overwrite: true });

const dirs = readdirSync(nodePath.resolve(process.cwd(), "play-dl-fix"));
cpSync(nodePath.resolve(process.cwd(), "play-dl-fix", dirs[0]), nodePath.resolve(process.cwd(), "play-dl-fix"), { force: true, recursive: true });
rmSync(nodePath.resolve(process.cwd(), "play-dl-fix", dirs[0]), { force: true, recursive: true });
rmSync(nodePath.resolve(process.cwd(), "temp.zip"), { force: true });

console.log("[INFO] Installing packages for play-dl...");
execSync("cd play-dl-fix && npm install");
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
"soundcloud.ts": "^0.5.3",
"tslib": "2.6.3",
"tweetnacl": "1.0.3",
"youtubei": "1.5.4"
"youtubei": "1.5.4",
"zip-lib": "^1.0.4"
},
"devDependencies": {
"@eslint/compat": "^1.1.1",
Expand Down
Loading

0 comments on commit a807b19

Please sign in to comment.