Feature: file name templating
Opened this issue · 5 comments
Hi, thanks for making this.
The current file name seems to be in the format (please correct me if I am wrong):
DISPLAY-YYYY-MM-DD_HH-MM-SS, where HHMMSS is the time started.
Is it possible to automatically save the file such that the file name includes the starting time and the ending time?
"templating" the file name is discussed here but it is closed, and doesn't seem to be a feature from what I can see.
Thanks again, and let me know if I can help or provide more information
I am not too sure about this. Time formats can be quite complex and I am not sure that I want to give people direct access to template strings. To me that seems kind of overwhelming and confusing.
What about an interface which is three dropdowns?
[Device][Start Time][End Time]
[Device]
Display #1
Dsp-1
..
[Start Time]
12/29/2024
29/12/2024
29/12
12/29
...
[End Time]
12/29/2024
29/12/2024
29/12
12/29
10hours
600minutes
...
Something where the format would be conveyed in the dropdowns?
I am not too sure about how this would be integrated which is why I closed #9.
Agreed that direct access to full templating is not required. I guess I just used the name becuase it was mentioned in #10
I think the interface you drafted is a great idea.
Personally though, all I wanted was to include the end time in the name of the file because it's difficult to keep track of whats going on after several recordings.
Any further formatting of the name can be easily modified by the user with basic bash once the essential data (which is , imo, display, start, end) is there, anyway.
As for implementation, a poor method I came up with was to just rename the file after saving. See example below.
let originalURL = writer.outputURL
let fileManager = FileManager.default
let fileExtension = originalURL.pathExtension
let baseName = originalURL.deletingPathExtension().lastPathComponent
// Format the current date and time
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd-HH-mm-ss"
let dateString = dateFormatter.string(from: Date())
let newName = "\(baseName)_\(dateString).\(fileExtension)"
let directory = originalURL.deletingLastPathComponent().path
let newURL = URL(fileURLWithPath: directory).appendingPathComponent(newName)
do {
try fileManager.moveItem(at: originalURL, to: newURL)
logger.log("File renamed to \(newName)")
} catch {
logger.error("Failed to rename file: \(error.localizedDescription)")
}
This can be used after within writer.finishWriting {}
and after sendNotification(title: "\(self) saved", body: "Saved video", url: writer.outputURL)
and logger.log("Saved video to \(writer.outputURL.absoluteString)")
.
This is probably very far from an optimal solution. I haven't done swe in awhile.
Thoughts?
Yeah, that would definitely be ideal. I currently resort to just showing the video in preview where you can resave, but I will see about adding a feature where it is more explicit and you can specify the name
I have been thinking about this more. I think I am going to change the default DISPLAY-YYYY-MM-DD_HH-MM-SS to make it a bit more compact (probably no need for seconds here). Then, I am going to make a screen which shows a preview of your video and asks you where you want to save it.
Eventually this could be a re-encoder as well if, for example, you wanted to create a ten-minute video or something.
I think this would be better for most people than a fixed template
Note: different languages expect different date formats. Specifying something like this may help localize the content
switch localeIdentifier {
case "en-US":
dateFormatter.dateFormat = "MM-dd-yyyy-HH-mm-ss"
case "en-GB":
dateFormatter.dateFormat = "dd-MM-yyyy-HH-mm-ss"
case "de-DE":
dateFormatter.dateFormat = "dd.MM.yyyy-HH-mm-ss"
case "zh-CN":
dateFormatter.dateFormat = "yyyy年MM月dd日-HH时mm分ss秒"
case "ja-JP":
dateFormatter.dateFormat = "yyyy年MM月dd日-HH時mm分ss秒"
default:
// Default format if locale is not specifically handled
dateFormatter.dateFormat = "yyyy-MM-dd-HH-mm-ss"
}