/MediaRenamer

MediaRenamer: A Tool to Rename Media Files by Their Taken Date.

Primary LanguageC#GNU General Public License v3.0GPL-3.0

MediaRenamer

A Tool to Rename Media Files by Their Taken Date.

Third-party Usage

Framework Targeting

  • .Net 8.0

Parameters List

Metadata Sample

(Only Some Specific Types, You Should Also Check Your Own Files)

Implementation

Metadata Querying

  • 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");

Date/Time

Formatting Standard

  • 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);

Timezone Conversion

ConvertTimeFromUtc(dtUtc, Local)

MD5

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..];