Skip to content

Commit

Permalink
fix: update got usages for v11
Browse files Browse the repository at this point in the history
  • Loading branch information
lightpohl committed Apr 29, 2020
1 parent 150088c commit e946775
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions bin/util.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
let stream = require("stream");
let { promisify } = require("util");
let got = require("got");
let fs = require("fs");
let path = require("path");
let filenamify = require("filenamify");

let pipeline = promisify(stream.pipeline);

let MAX_DEPTH = 10;
let DEFAULT_LIMIT = 100;
let RATE_LIMIT_MS = 1000;
Expand Down Expand Up @@ -85,7 +89,7 @@ let getVideoSearch = async ({
console.log(`fetching ${requestUrl}`);
}

let { body } = await got(requestUrl, { json: true });
let body = await got(requestUrl).json();

if (!body) {
console.error("search: no response body");
Expand Down Expand Up @@ -240,7 +244,7 @@ let getShowsResponse = async ({ apiKey, limit, offset, clean, debug }) => {
console.log(`fetching ${requestUrl}`);
}

let { body } = await got(requestUrl, { json: true });
let body = await got(requestUrl).json();

if (!body) {
console.error("shows: no response body");
Expand Down Expand Up @@ -287,7 +291,7 @@ let getVideosResponse = async ({
console.log(`fetching ${requestUrl}`);
}

let { body } = await got(requestUrl, { json: true });
let body = await got(requestUrl).json();

if (!body) {
console.error("videos: no response body");
Expand Down Expand Up @@ -365,20 +369,23 @@ let downloadVideo = async ({
console.log(`output path: ${outputPath}`);

await rateLimit(debug);
got
.stream(downloadUrl)
.on("downloadProgress", (progress) => {
printProgress(progress);
})
.on("end", () => {
endPrintProgress();
console.log("download complete!");

if (archive) {
writeToArchive(downloadUrl);
}
})
.pipe(fs.createWriteStream(outputPath));
await pipeline(
got
.stream(downloadUrl)
.on("downloadProgress", (progress) => {
printProgress(progress);
})
.on("end", () => {
endPrintProgress();
}),
fs.createWriteStream(outputPath)
);

console.log("download complete!");

if (archive) {
writeToArchive(downloadUrl);
}
};

let qualityList = ["hd", "high", "low", "mobile"];
Expand Down

0 comments on commit e946775

Please sign in to comment.