Skip to content

Commit 4d3bd94

Browse files
committed
Add downloadCaptions extra config
1 parent 412fe1e commit 4d3bd94

File tree

5 files changed

+27
-9
lines changed

5 files changed

+27
-9
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "floatplane-plex-downloader",
3-
"version": "5.17.0",
3+
"version": "5.18.0",
44
"private": true,
55
"type": "module",
66
"scripts": {

src/lib/Video.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,10 @@ export class Video extends Attachment {
112112
await this.saveNfo().catch(withContext(`Saving .nfo file`)).catch(this.onError);
113113
}
114114
if (settings.extras.downloadArtwork) {
115-
await this.downloadArtwork().catch(withContext(`Saving artwork`)).catch(this.onError);
115+
await this.downloadArtwork().catch(withContext(`Downloading artwork`)).catch(this.onError);
116+
}
117+
if (settings.extras.downloadCaptions) {
118+
await this.downloadCaptions().catch(withContext(`Downloading captions`)).catch(this.onError);
116119
}
117120
if ((await this.getState()) === Video.State.Muxed) {
118121
this.logger.done(chalk`{green Exists! Skipping}`);
@@ -291,17 +294,21 @@ export class Video extends Attachment {
291294
this.logger.log("Saved artwork");
292295
}
293296

294-
private async downloadCaptions() {
297+
private *captionsFiles() {
295298
if (this.textTracks === undefined) return;
296299
const captions = this.textTracks.filter((track) => track.kind === "captions");
297300
if (captions.length === 0) return;
298-
this.logger.log("Saving captions");
299-
300301
for (const caption of captions) {
301-
const captionPath = `${this.filePath}${caption.language ? `.${caption.language}` : ""}.vtt`;
302-
if (await fileExists(captionPath)) continue;
303-
const captionContent = await fetch(caption.src).then((res) => res.text());
304-
await writeFile(captionPath, captionContent, "utf8");
302+
const path = `${this.filePath}${caption.language ? `.${caption.language}` : ""}.vtt`;
303+
yield { ...caption, path };
304+
}
305+
}
306+
private async downloadCaptions() {
307+
this.logger.log("Saving captions");
308+
for (const { path, src } of this.captionsFiles()) {
309+
if (await fileExists(path)) continue;
310+
const captionContent = await fetch(src).then((res) => res.text());
311+
await writeFile(path, captionContent, "utf8");
305312
}
306313
this.logger.log("Saved captions");
307314
}

src/lib/defaults.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export const defaultSettings: Settings = {
5858
extras: {
5959
stripSubchannelPrefix: true,
6060
downloadArtwork: true,
61+
downloadCaptions: true,
6162
saveNfo: true,
6263
considerAllNonPartialDownloaded: false,
6364
},

src/lib/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export type PartialArgs = Partial<Args & Settings>;
4343
export interface Extras extends Record<string, boolean> {
4444
stripSubchannelPrefix: boolean;
4545
downloadArtwork: boolean;
46+
downloadCaptions: boolean;
4647
saveNfo: boolean;
4748
considerAllNonPartialDownloaded: boolean;
4849
}

wiki/settings.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,15 @@ Saves video thubnails alongside each video. These are required for nice thumbnai
145145

146146
<br>
147147

148+
**extras.downloadCaptions**:
149+
Saves video captions alongside each video.
150+
151+
```json
152+
"extras": {
153+
"downloadCaptions": true
154+
}
155+
```
156+
148157
**extras.safeNfo**:
149158
Saves video metadata to nfo files alongside each video.
150159

0 commit comments

Comments
 (0)