A Tool to Rename Media Files by Their Taken Date
.
- NuGet packages:
- Microsoft-WindowsAPICodePack-Shell
- MetadataExtractor
- MediaInfo.Wrapper.Core
- .Net 8.0
- MediaInfo: MediaInfo_Parameters_List.md
(Only Some Specific Types, You Should Also Check Your Own Files)
- Image: MetadataExtractor_Exif_Output.md
- Video: MediaInfo_Ouput.md
-
Image:
var directories = ImageMetadataReader.ReadMetadata(file.FullName); foreach (var t in directories) { Console.WriteLine(t.Name); for (var j = 0; j < t.TagCount; j++) { Console.WriteLine(t.Tags[j].ToString()); } }
-
Video:
var mi = new MediaInfo(); mi.Open(file.FullName);
- All Tags:
Console.WriteLine(mi.Inform());
- A Specific Tag:
- Encoded Time / Tagged Time:
strDt = MI.Get(StreamKind.Video, 0, "Encoded_Date");
- Recorded Time (in
General Stream
):strDt = MI.Get(StreamKind.General, 0, "Recorded_Date");
- Encoded Time / Tagged Time:
- All Tags:
- Refer to: Combined date and time representations in ISO 8601.
<date>T<time>
A single point in time can be represented by concatenating a complete date expression, the letter T as a delimiter, and a valid time expression. For example, "2007-04-05T14:30". If a time zone designator is required, it follows the combined date and time. For example, "2007-04-05T14:30Z" or " 2007-04-05T12:30-02:00".
const string strDtFormat = "yyyy-MM-ddTHH:mm:ssZ";
var dtUtc = DateTime.ParseExact(strDt, "yyyy:MM:dd HH:mm:ss", CultureInfo.InvariantCulture);
return dtUtc.ToString(strDtFormat);
ConvertTimeFromUtc(dtUtc, Local)
string strMD5;
using (var md5Instance = MD5.Create()) {
using (var stream = File.OpenRead(file.FullName)) {
var fileHash = md5Instance.ComputeHash(stream);
strMD5 = BitConverter.ToString(fileHash).Replace("-", "").ToUpperInvariant();
}
}
return strMD5[..3] + strMD5[^3..];