Skip to content

Commit

Permalink
Adds video inspection support
Browse files Browse the repository at this point in the history
  • Loading branch information
replaysMike committed Mar 25, 2020
1 parent 2880b36 commit 3608fd8
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 60 deletions.
1 change: 1 addition & 0 deletions AssemblyInfo/AssemblyInfo/AssemblyInfo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
<Compile Include="Options.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="MediaInspector.cs" />
<EmbeddedResource Include="AssemlyInfoWindow.resx">
<DependentUpon>AssemlyInfoWindow.cs</DependentUpon>
</EmbeddedResource>
Expand Down
60 changes: 4 additions & 56 deletions AssemblyInfo/AssemblyInfo/AssemblyInspector.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
using AssemblyInfo.Extensions;
using MetadataExtractor;
using MetadataExtractor.Formats.Bmp;
using MetadataExtractor.Formats.Exif;
using MetadataExtractor.Formats.FileType;
using MetadataExtractor.Formats.Gif;
using MetadataExtractor.Formats.Iptc;
using MetadataExtractor.Formats.Jpeg;
using MetadataExtractor.Formats.Png;
using MetadataExtractor.Formats.QuickTime;
using System;
using System.Collections.Generic;
using System.Diagnostics;
Expand Down Expand Up @@ -60,7 +51,7 @@ private AssemblyData InspectAssembly(string filename)
case ".qt":
case ".mpeg":
case ".m4v":
return InspectImage(filename);
return new MediaInspector().InspectMedia(InspectFile(filename), filename);
default:
assembly = Assembly.LoadFrom(filename);
break;
Expand All @@ -78,49 +69,6 @@ private AssemblyData InspectAssembly(string filename)
return InspectAssembly(assembly);
}

private AssemblyData InspectImage(string filename)
{
var data = InspectFile(filename);
var sb = new StringBuilder();
var directories = ImageMetadataReader.ReadMetadata(filename);
var subIfdDirectory = directories.OfType<ExifSubIfdDirectory>().FirstOrDefault();
var dateTime = subIfdDirectory?.GetDescription(ExifDirectoryBase.TagDateTime);
var creditDirectory = directories.OfType<IptcDirectory>().FirstOrDefault();
var credit = creditDirectory?.GetDescription(IptcDirectory.TagCredit);
var types = directories.Select(x => x.GetType()).ToList();
var movieHeaderDirectory = (MetadataExtractor.Directory)directories.OfType<QuickTimeMovieHeaderDirectory>().Where(x => x.Name == "QuickTime Movie Header").FirstOrDefault();
var fileTypeDirectory = (MetadataExtractor.Directory)directories.OfType<FileTypeDirectory>().Where(x => x.Name == "File Type").FirstOrDefault();
var codec = fileTypeDirectory?.Tags.Where(x => x.Name == "Detected File Type Name").Select(x => x.Description).FirstOrDefault();
var durationTime = movieHeaderDirectory?.Tags.Where(x => x.Name == "Duration").Select(x => x.Description).FirstOrDefault();
var createdOn = movieHeaderDirectory?.Tags.Where(x => x.Name == "Created").Select(x => x.Description).FirstOrDefault();
var dimensionDirectory = (MetadataExtractor.Directory)directories.OfType<PngDirectory>().Where(x => x.Name == "PNG-IHDR").FirstOrDefault()
?? (MetadataExtractor.Directory)directories.OfType<JpegDirectory>().Where(x => x.Name == "JPEG").FirstOrDefault()
?? (MetadataExtractor.Directory)directories.OfType<GifHeaderDirectory>().Where(x => x.Name == "GIF Header").FirstOrDefault()
?? (MetadataExtractor.Directory)directories.OfType<BmpHeaderDirectory>().Where(x => x.Name == "BMP Header").FirstOrDefault()
?? (MetadataExtractor.Directory)directories.OfType<QuickTimeTrackHeaderDirectory>().Where(x => x.Name == "QuickTime Track Header").FirstOrDefault();
var width = dimensionDirectory?.Tags.Where(x => x.Name == "Image Width").Select(x => x.Description).FirstOrDefault()
?? dimensionDirectory?.Tags.Where(x => x.Name == "Width").Select(x => x.Description).FirstOrDefault();
var height = dimensionDirectory?.Tags.Where(x => x.Name == "Image Height").Select(x => x.Description).FirstOrDefault()
?? dimensionDirectory?.Tags.Where(x => x.Name == "Height").Select(x => x.Description).FirstOrDefault();
var dimensions = $"{width} x {height}";
var duration = $"{durationTime}";
foreach (var directory in directories)
{
foreach(var tag in directory.Tags)
{
sb.AppendLine($"[{directory.Name}] {tag.Name}={tag.Description}");
}
}
data.Metadata = sb.ToString();
data.InformationalVersion = dateTime?.ToString();
data.Copyright = credit;
data.ProductName = dimensions;
data.FileDescription = duration;
data.Description = createdOn;
data.InformationalVersion = codec;
return data;
}

private AssemblyData InspectMsi(string filename)
{
var data = InspectFile(filename);
Expand Down Expand Up @@ -263,17 +211,17 @@ private void ComputeHash(AssemblyData data, string filename)
using (var sha = SHA256.Create())
{
var sha256Hash = sha.ComputeHash(bytes);
data.Sha256 = AssemblyInfo.Extensions.ByteConverter.ToHex(sha256Hash);
data.Sha256 = AssemblyInfo.Extensions.ByteConverter.ToHex(sha256Hash).ToUpper();
}
using (var sha = SHA1.Create())
{
var shaHash = sha.ComputeHash(bytes);
data.Sha = AssemblyInfo.Extensions.ByteConverter.ToHex(shaHash);
data.Sha = AssemblyInfo.Extensions.ByteConverter.ToHex(shaHash).ToUpper();
}
using (var md5 = MD5.Create())
{
var md5Hash = md5.ComputeHash(bytes);
data.Md5 = AssemblyInfo.Extensions.ByteConverter.ToHex(md5Hash);
data.Md5 = AssemblyInfo.Extensions.ByteConverter.ToHex(md5Hash).ToUpper();
}
}
}
Expand Down
59 changes: 59 additions & 0 deletions AssemblyInfo/AssemblyInfo/MediaInspector.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using MetadataExtractor;
using MetadataExtractor.Formats.Bmp;
using MetadataExtractor.Formats.Exif;
using MetadataExtractor.Formats.FileType;
using MetadataExtractor.Formats.Gif;
using MetadataExtractor.Formats.Iptc;
using MetadataExtractor.Formats.Jpeg;
using MetadataExtractor.Formats.Png;
using MetadataExtractor.Formats.QuickTime;
using System.Linq;
using System.Text;

namespace AssemblyInfo
{
public class MediaInspector
{
public AssemblyData InspectMedia(AssemblyData data, string filename)
{
var sb = new StringBuilder();
var directories = ImageMetadataReader.ReadMetadata(filename);
var subIfdDirectory = directories.OfType<ExifSubIfdDirectory>().FirstOrDefault();
var dateTime = subIfdDirectory?.GetDescription(ExifDirectoryBase.TagDateTime);
var creditDirectory = directories.OfType<IptcDirectory>().FirstOrDefault();
var credit = creditDirectory?.GetDescription(IptcDirectory.TagCredit);
var types = directories.Select(x => x.GetType()).ToList();
var movieHeaderDirectory = (MetadataExtractor.Directory)directories.OfType<QuickTimeMovieHeaderDirectory>().Where(x => x.Name == "QuickTime Movie Header").FirstOrDefault();
var fileTypeDirectory = (MetadataExtractor.Directory)directories.OfType<FileTypeDirectory>().Where(x => x.Name == "File Type").FirstOrDefault();
var codec = fileTypeDirectory?.Tags.Where(x => x.Name == "Detected File Type Name").Select(x => x.Description).FirstOrDefault();
var durationTime = movieHeaderDirectory?.Tags.Where(x => x.Name == "Duration").Select(x => x.Description).FirstOrDefault();
var createdOn = movieHeaderDirectory?.Tags.Where(x => x.Name == "Created").Select(x => x.Description).FirstOrDefault();
var dimensionDirectory = (MetadataExtractor.Directory)directories.OfType<PngDirectory>().Where(x => x.Name == "PNG-IHDR").FirstOrDefault()
?? (MetadataExtractor.Directory)directories.OfType<JpegDirectory>().Where(x => x.Name == "JPEG").FirstOrDefault()
?? (MetadataExtractor.Directory)directories.OfType<GifHeaderDirectory>().Where(x => x.Name == "GIF Header").FirstOrDefault()
?? (MetadataExtractor.Directory)directories.OfType<BmpHeaderDirectory>().Where(x => x.Name == "BMP Header").FirstOrDefault()
?? (MetadataExtractor.Directory)directories.OfType<QuickTimeTrackHeaderDirectory>().Where(x => x.Name == "QuickTime Track Header").FirstOrDefault();
var width = dimensionDirectory?.Tags.Where(x => x.Name == "Image Width").Select(x => x.Description).FirstOrDefault()
?? dimensionDirectory?.Tags.Where(x => x.Name == "Width").Select(x => x.Description).FirstOrDefault();
var height = dimensionDirectory?.Tags.Where(x => x.Name == "Image Height").Select(x => x.Description).FirstOrDefault()
?? dimensionDirectory?.Tags.Where(x => x.Name == "Height").Select(x => x.Description).FirstOrDefault();
var dimensions = $"{width} x {height}";
var duration = $"{durationTime}";
foreach (var directory in directories)
{
foreach (var tag in directory.Tags)
{
sb.AppendLine($"[{directory.Name}] {tag.Name}={tag.Description}");
}
}
data.Metadata = sb.ToString();
data.InformationalVersion = dateTime?.ToString();
data.Copyright = credit;
data.ProductName = dimensions;
data.FileDescription = duration;
data.Description = createdOn;
data.InformationalVersion = codec;
return data;
}
}
}
4 changes: 2 additions & 2 deletions AssemblyInfo/AssemblyInfo/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")]
4 changes: 2 additions & 2 deletions AssemblyInfo/AssemblyInfoInstaller/Product.wxs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="AssemblyInfo" Language="1033" Codepage="1252" Version="1.0.0.0" Manufacturer="Refactor Software" UpgradeCode="30d3e037-13d8-40b4-9cd5-ac36d54e376c">
<Product Id="*" Name="AssemblyInfo" Language="1033" Codepage="1252" Version="1.1.0.0" Manufacturer="Refactor Software" UpgradeCode="30d3e037-13d8-40b4-9cd5-ac36d54e376c">
<Package Id="*"
Keywords="Installer"
InstallerVersion="200"
Expand All @@ -19,7 +19,7 @@
<Icon Id="AssemblyInfo_128.ico" SourceFile="$(var.AssemblyInfo.ProjectDir)AssemblyInfo_128.ico"/>
<Property Id="ARPPRODUCTICON" Value="AssemblyInfo_128.ico" />
<Feature Id="Complete"
Title="AssemblyInfo 1.0"
Title="AssemblyInfo 1.1"
Description="AssemblyInfo application"
Level="1"
Display="expand"
Expand Down

0 comments on commit 3608fd8

Please sign in to comment.