Merge pull request #19 from harvard-lil/multi-video

Added support for multi-video tweets
pull/20/head 0.0.4
Matteo Cargnelutti 2022-12-22 14:53:46 -05:00 zatwierdzone przez GitHub
commit f56da57e14
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
5 zmienionych plików z 543 dodań i 391 usunięć

Wyświetl plik

@ -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
@ -559,21 +559,28 @@ export class TwitterCapture {
if (result.status !== 0) {
throw new Error(result.stderr);
}
const video = fs.readFileSync(filepathOut);
const videos = glob.sync(filepathOut.replace("%(autonumber)d", "*"))
if (!video) {
if (!videos) {
return;
}
let i = 1;
for (const file of videos) {
const video = fs.readFileSync(file);
await editablePDF.attach(video.buffer, "video.mp4", {
mimeType: 'video/mp4',
description: `Video captured from ${this.url}`,
creationDate: new Date(),
modificationDate: new Date(),
});
fs.unlink(filepathOut, () => {});
await editablePDF.attach(video.buffer, `video-${i}.mp4`, {
mimeType: 'video/mp4',
description: `Video captured from ${this.url}`,
creationDate: new Date(),
modificationDate: new Date(),
});
i++;
fs.unlink(file, () => {});
}
}
catch(err) { }
}

Wyświetl plik

@ -223,7 +223,7 @@ Playwright needs to be ready.
<a name="utils.module_TwitterCapture.TwitterCapture+captureAndAddVideoToPDF"></a>
#### twitterCapture.captureAndAddVideoToPDF ⇒ <code>Promise.&lt;void&gt;</code>
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.
**Kind**: instance property of [<code>TwitterCapture</code>](#utils.module_TwitterCapture.TwitterCapture)

890
package-lock.json wygenerowano

Plik diff jest za duży Load Diff

Wyświetl plik

@ -1,6 +1,6 @@
{
"name": "thread-keeper",
"version": "0.0.3",
"version": "0.0.4",
"description": "",
"main": "app.js",
"type": "module",
@ -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",

Wyświetl plik

@ -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;