diff --git a/app/utils/TwitterCapture.js b/app/utils/TwitterCapture.js index ce6becd..bb3cad5 100644 --- a/app/utils/TwitterCapture.js +++ b/app/utils/TwitterCapture.js @@ -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} */ 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) { } } diff --git a/package-lock.json b/package-lock.json index 212a7f1..856faa9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index ca18dd0..7162ceb 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/scripts/download-yt-dlp.sh b/scripts/download-yt-dlp.sh index a6fb027..79cb31f 100644 --- a/scripts/download-yt-dlp.sh +++ b/scripts/download-yt-dlp.sh @@ -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;