Skip to content

Commit

Permalink
Improve filePath sanitization & ffmpeg metadata filename length saveg…
Browse files Browse the repository at this point in the history
…uards
  • Loading branch information
Inrixia committed Apr 18, 2024
1 parent 97db39b commit 8affc37
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
9 changes: 3 additions & 6 deletions src/lib/Attachment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ export class Attachment implements AttachmentAttributes {
this.releaseDate = releaseDate;
this.videoTitle = videoTitle;

this.filePath = this.formatFilePath(settings.filePathFormatting)
.split("/")
.map((pathPart) => (pathPart.startsWith(".") ? pathPart : sanitize(pathPart)))
.join("/");
this.filePath = this.formatFilePath(settings.filePathFormatting);

// Ensure filePath is not exceeding maximum length
if (this.filePath.length > 250) this.filePath = this.filePath.substring(0, 250);
Expand Down Expand Up @@ -94,14 +91,14 @@ export class Attachment implements AttachmentAttributes {
public static FilePathOptions = ["%channelTitle%", "%year%", "%month%", "%day%", "%hour%", "%minute%", "%second%", "%videoTitle%"] as const;
protected formatFilePath(string: string): string {
const formatLookup: Record<ValueOfA<typeof Attachment.FilePathOptions>, string> = {
"%channelTitle%": this.channelTitle,
"%channelTitle%": sanitize(this.channelTitle),
"%year%": this.releaseDate.getFullYear().toString(),
"%month%": nPad(this.releaseDate.getMonth() + 1),
"%day%": nPad(this.releaseDate.getDate()),
"%hour%": nPad(this.releaseDate.getHours()),
"%minute%": nPad(this.releaseDate.getMinutes()),
"%second%": nPad(this.releaseDate.getSeconds()),
"%videoTitle%": this.videoTitle.replace(/ - /g, " ").replace(/\//g, " ").replace(/\\/g, " "),
"%videoTitle%": sanitize(this.videoTitle.replace(/ - /g, " ").replace(/\//g, " ").replace(/\\/g, " ")),
};

for (const [match, value] of Object.entries(formatLookup)) {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ export class Video extends Attachment {
description: description,
synopsis: description,
};
const metadataFilePath = `${this.muxedPath}.metadata.txt`;
const metadataFilePath = `${this.muxedPath}.ffmeta`;
const metadataContent = Object.entries(metadata)
.map(([key, value]) => `${key}=${value.replaceAll(/\n/g, "\\\n")}`)
.join("\n");
Expand Down

0 comments on commit 8affc37

Please sign in to comment.