Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option for post-processing command/script #78

Merged
merged 2 commits into from Jul 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 21 additions & 5 deletions src/lib/Video.ts
@@ -1,4 +1,4 @@
import { execFile } from 'child_process';
import { exec, execFile } from 'child_process';
import { createWriteStream } from 'fs';
import fs from 'fs/promises';

Expand Down Expand Up @@ -38,7 +38,7 @@ export default class Video {
this.thumbnail = video.thumbnail;
}

private get fullPath(): string {
private formatString(string: string): string {
const formatLookup: FilePathFormattingOptions = {
'%channelTitle%': this.channel.title,
'%episodeNumber%': this.channel.lookupVideoDB(this.guid).episodeNo.toString(),
Expand All @@ -51,12 +51,15 @@ export default class Video {
'%videoTitle%': this.title.replace(/ - /g, ' ').replace(/\//g, ' ').replace(/\\/g, ' '),
};

let fullPath = settings.filePathFormatting;
for (const [match, value] of Object.entries(formatLookup)) {
fullPath = fullPath.replace(new RegExp(match, 'g'), value);
string = string.replace(new RegExp(match, 'g'), value);
}

return fullPath;
return string;
}

private get fullPath(): string {
return this.formatString(settings.filePathFormatting);
}

private get folderPath(): string {
Expand Down Expand Up @@ -193,8 +196,21 @@ export default class Video {
);
this.expectedSize = await this.muxedBytes();
await this.markCompleted();
await this.postProcessingCommand();
await fs.unlink(`${this.filePath}.partial`);
// Set the files update time to when the video was released
await fs.utimes(`${this.filePath}.mp4`, new Date(), this.releaseDate);
}

public async postProcessingCommand(): Promise<void> {
const command = this.formatString(settings.postProcessingCommand);
await new Promise((resolve, reject) =>
exec(command,
(error, stdout) => {
if (error !== null) reject(error);
else resolve(stdout);
}
)
);
}
}
1 change: 1 addition & 0 deletions src/lib/defaults.ts
Expand Up @@ -174,4 +174,5 @@ export const defaultSettings: Settings = {
'ltt supporter plus': 'Linus Tech Tips',
},
subscriptions: {},
postProcessingCommand: '',
};
1 change: 1 addition & 0 deletions src/lib/types.ts
Expand Up @@ -86,4 +86,5 @@ export type Settings = {
[key: string]: SubscriptionSettings;
};
plex: PlexSettings;
postProcessingCommand: string;
};
11 changes: 11 additions & 0 deletions wiki/settings.md
Expand Up @@ -122,6 +122,17 @@ Added for Kodi support as Kodi looks for artwork in the format `VideoName-thumb.

<br>

**postProcessingCommand**:<br>
A command to run after a video has sucessfully downloaded.<br>
You can refer to `_filePathFormattingOPTIONS` for options on what can be used.<br>
Strings surounded by % will be replaced with their respective values.<br>

```json
"postProcessingCommand": ""
```

<br>

## Plex

Use **quickstartPrompts** to easily set plex settings.
Expand Down