kopia lustrzana https://github.com/harvard-lil/archive.social
Added support for multi-video tweets
rodzic
60a6c62956
commit
1ecef44e4b
|
@ -10,7 +10,7 @@ import { chromium } from "playwright";
|
|||
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import { PDFDocument } from "pdf-lib";
|
||||
import nunjucks from "nunjucks";
|
||||
import glob from "glob";
|
||||
|
||||
import { CERTS_PATH, TMP_PATH, EXECUTABLES_FOLDER, TEMPLATES_PATH, APP_VERSION } from "../const.js";
|
||||
|
||||
|
@ -512,13 +512,13 @@ export class TwitterCapture {
|
|||
}
|
||||
|
||||
/**
|
||||
* Tries to capture main video from current Twitter url and add it as attachment to the PDF.
|
||||
* Tries to capture video(s) from current Twitter url and add them as attachment to the PDF.
|
||||
* @param {PDFDocument} - Editable PDF object from `pdf-lib`.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
captureAndAddVideoToPDF = async(editablePDF) => {
|
||||
const id = uuidv4();
|
||||
const filepathOut = `${this.options.tmpFolderPath}${id}.mp4`;
|
||||
const filepathOut = `${this.options.tmpFolderPath}${id}-%(autonumber)d.mp4`;
|
||||
const ytDlpExecutable = this.options.ytDlpPath;
|
||||
|
||||
// yt-dlp health check
|
||||
|
@ -560,20 +560,27 @@ export class TwitterCapture {
|
|||
throw new Error(result.stderr);
|
||||
}
|
||||
|
||||
const video = fs.readFileSync(filepathOut);
|
||||
const videos = glob.sync(filepathOut.replace("%(autonumber)d", "*"))
|
||||
|
||||
if (!video) {
|
||||
if (!videos) {
|
||||
return;
|
||||
}
|
||||
|
||||
await editablePDF.attach(video.buffer, "video.mp4", {
|
||||
let i = 1;
|
||||
for (const file of videos) {
|
||||
const video = fs.readFileSync(file);
|
||||
|
||||
await editablePDF.attach(video.buffer, `video-${i}.mp4`, {
|
||||
mimeType: 'video/mp4',
|
||||
description: `Video captured from ${this.url}`,
|
||||
creationDate: new Date(),
|
||||
modificationDate: new Date(),
|
||||
});
|
||||
|
||||
fs.unlink(filepathOut, () => {});
|
||||
i++;
|
||||
|
||||
fs.unlink(file, () => {});
|
||||
}
|
||||
}
|
||||
catch(err) { }
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
"fastq": "^1.13.0",
|
||||
"find-my-way": "^7.3.1",
|
||||
"forwarded": "^0.2.0",
|
||||
"glob": "^8.0.3",
|
||||
"ieee754": "^1.2.1",
|
||||
"ipaddr.js": "^1.9.1",
|
||||
"jsdoc-to-markdown": "^7.1.1",
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
"fastq": "^1.13.0",
|
||||
"find-my-way": "^7.3.1",
|
||||
"forwarded": "^0.2.0",
|
||||
"glob": "^8.0.3",
|
||||
"ieee754": "^1.2.1",
|
||||
"ipaddr.js": "^1.9.1",
|
||||
"jsdoc-to-markdown": "^7.1.1",
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
# Pulls yt-dlp (2022.10.04 version) and saves it in `executables`.
|
||||
curl -L https://github.com/yt-dlp/yt-dlp/releases/download/2022.10.04/yt-dlp > ../executables/yt-dlp;
|
||||
# Pulls yt-dlp (2022.11.11 version) and saves it in `executables`.
|
||||
curl -L https://github.com/yt-dlp/yt-dlp/releases/download/2022.11.11/yt-dlp > ../executables/yt-dlp;
|
||||
chmod a+x ../executables/yt-dlp;
|
||||
|
|
Ładowanie…
Reference in New Issue