commit 1f14137c5b7559ca986a33db13c57afbd2807d98 Author: Garritt McCune Date: Thu Aug 31 15:35:53 2017 -0500 Initial Commit, batch meta data update functionality working. Fixed a bug where hyphens were stripped from episode names. diff --git a/MKVTest/.gitignore b/MKVTest/.gitignore new file mode 100644 index 0000000..b5c1ce4 --- /dev/null +++ b/MKVTest/.gitignore @@ -0,0 +1,7 @@ +!*.exe +packages/ +MKVTest/bin +MKVTest/obj +*.mkv +*.txt +MKVTest/.vs \ No newline at end of file diff --git a/MKVTest/MKVTest.sln b/MKVTest/MKVTest.sln new file mode 100644 index 0000000..2cc048c --- /dev/null +++ b/MKVTest/MKVTest.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26730.10 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MKVTest", "MKVTest\MKVTest.csproj", "{A750A634-6881-4083-B909-73EFE4C96802}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A750A634-6881-4083-B909-73EFE4C96802}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A750A634-6881-4083-B909-73EFE4C96802}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A750A634-6881-4083-B909-73EFE4C96802}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A750A634-6881-4083-B909-73EFE4C96802}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {1DE3F207-A6CC-4FE8-B26A-DFC0A7448E8D} + EndGlobalSection +EndGlobal diff --git a/MKVTest/MKVTest/App.config b/MKVTest/MKVTest/App.config new file mode 100644 index 0000000..731f6de --- /dev/null +++ b/MKVTest/MKVTest/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/MKVTest/MKVTest/Form1.Designer.cs b/MKVTest/MKVTest/Form1.Designer.cs new file mode 100644 index 0000000..d656758 --- /dev/null +++ b/MKVTest/MKVTest/Form1.Designer.cs @@ -0,0 +1,223 @@ +namespace MKVTest +{ + partial class Form1 + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.selectFolderButton = new System.Windows.Forms.Button(); + this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); + this.mainMenuStrip = new System.Windows.Forms.MenuStrip(); + this.fileMainMenu = new System.Windows.Forms.ToolStripMenuItem(); + this.openFolderFileMainMenu = new System.Windows.Forms.ToolStripMenuItem(); + this.selectFileMainMenu = new System.Windows.Forms.ToolStripMenuItem(); + this.inputFilesListView = new System.Windows.Forms.ListView(); + this.detailsGroupBox = new System.Windows.Forms.GroupBox(); + this.buttonPanel = new System.Windows.Forms.Panel(); + this.applyChangesButton = new System.Windows.Forms.Button(); + this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel(); + this.currentTitleLabel = new System.Windows.Forms.Label(); + this.tableLayoutPanel1.SuspendLayout(); + this.mainMenuStrip.SuspendLayout(); + this.detailsGroupBox.SuspendLayout(); + this.buttonPanel.SuspendLayout(); + this.flowLayoutPanel1.SuspendLayout(); + this.SuspendLayout(); + // + // selectFolderButton + // + this.selectFolderButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.selectFolderButton.Location = new System.Drawing.Point(2, 8); + this.selectFolderButton.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.selectFolderButton.Name = "selectFolderButton"; + this.selectFolderButton.Size = new System.Drawing.Size(80, 29); + this.selectFolderButton.TabIndex = 1; + this.selectFolderButton.Text = "Select Folder"; + this.selectFolderButton.UseVisualStyleBackColor = true; + this.selectFolderButton.Click += new System.EventHandler(this.button1_Click); + // + // tableLayoutPanel1 + // + this.tableLayoutPanel1.ColumnCount = 3; + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F)); + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 10F)); + this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 40F)); + this.tableLayoutPanel1.Controls.Add(this.mainMenuStrip, 0, 0); + this.tableLayoutPanel1.Controls.Add(this.inputFilesListView, 0, 1); + this.tableLayoutPanel1.Controls.Add(this.detailsGroupBox, 2, 1); + this.tableLayoutPanel1.Controls.Add(this.buttonPanel, 2, 4); + this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; + this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 0); + this.tableLayoutPanel1.Name = "tableLayoutPanel1"; + this.tableLayoutPanel1.RowCount = 5; + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 30F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 25.08529F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 37.45736F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 37.45736F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 43F)); + this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F)); + this.tableLayoutPanel1.Size = new System.Drawing.Size(560, 401); + this.tableLayoutPanel1.TabIndex = 2; + // + // mainMenuStrip + // + this.tableLayoutPanel1.SetColumnSpan(this.mainMenuStrip, 3); + this.mainMenuStrip.ImageScalingSize = new System.Drawing.Size(28, 28); + this.mainMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.fileMainMenu}); + this.mainMenuStrip.Location = new System.Drawing.Point(0, 0); + this.mainMenuStrip.Name = "mainMenuStrip"; + this.mainMenuStrip.Size = new System.Drawing.Size(560, 24); + this.mainMenuStrip.TabIndex = 2; + this.mainMenuStrip.Text = "menuStrip1"; + // + // fileMainMenu + // + this.fileMainMenu.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.openFolderFileMainMenu, + this.selectFileMainMenu}); + this.fileMainMenu.Name = "fileMainMenu"; + this.fileMainMenu.Size = new System.Drawing.Size(37, 20); + this.fileMainMenu.Text = "&File"; + // + // openFolderFileMainMenu + // + this.openFolderFileMainMenu.Name = "openFolderFileMainMenu"; + this.openFolderFileMainMenu.Size = new System.Drawing.Size(139, 22); + this.openFolderFileMainMenu.Text = "&Open Folder"; + // + // selectFileMainMenu + // + this.selectFileMainMenu.Name = "selectFileMainMenu"; + this.selectFileMainMenu.Size = new System.Drawing.Size(139, 22); + this.selectFileMainMenu.Text = "&Select File"; + // + // inputFilesListView + // + this.tableLayoutPanel1.SetColumnSpan(this.inputFilesListView, 2); + this.inputFilesListView.Dock = System.Windows.Forms.DockStyle.Fill; + this.inputFilesListView.LabelWrap = false; + this.inputFilesListView.Location = new System.Drawing.Point(3, 33); + this.inputFilesListView.Name = "inputFilesListView"; + this.tableLayoutPanel1.SetRowSpan(this.inputFilesListView, 4); + this.inputFilesListView.Size = new System.Drawing.Size(330, 365); + this.inputFilesListView.TabIndex = 3; + this.inputFilesListView.UseCompatibleStateImageBehavior = false; + this.inputFilesListView.View = System.Windows.Forms.View.Details; + // + // detailsGroupBox + // + this.detailsGroupBox.Controls.Add(this.flowLayoutPanel1); + this.detailsGroupBox.Dock = System.Windows.Forms.DockStyle.Fill; + this.detailsGroupBox.Location = new System.Drawing.Point(339, 33); + this.detailsGroupBox.Name = "detailsGroupBox"; + this.tableLayoutPanel1.SetRowSpan(this.detailsGroupBox, 3); + this.detailsGroupBox.Size = new System.Drawing.Size(218, 320); + this.detailsGroupBox.TabIndex = 5; + this.detailsGroupBox.TabStop = false; + this.detailsGroupBox.Text = "Details"; + // + // buttonPanel + // + this.buttonPanel.Controls.Add(this.applyChangesButton); + this.buttonPanel.Controls.Add(this.selectFolderButton); + this.buttonPanel.Dock = System.Windows.Forms.DockStyle.Fill; + this.buttonPanel.Location = new System.Drawing.Point(339, 359); + this.buttonPanel.Name = "buttonPanel"; + this.buttonPanel.Size = new System.Drawing.Size(218, 39); + this.buttonPanel.TabIndex = 8; + // + // applyChangesButton + // + this.applyChangesButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.applyChangesButton.Enabled = false; + this.applyChangesButton.Location = new System.Drawing.Point(112, 7); + this.applyChangesButton.Name = "applyChangesButton"; + this.applyChangesButton.Size = new System.Drawing.Size(102, 29); + this.applyChangesButton.TabIndex = 2; + this.applyChangesButton.Text = "Apply Changes"; + this.applyChangesButton.UseVisualStyleBackColor = true; + this.applyChangesButton.Click += new System.EventHandler(this.applyChangesButton_Click); + // + // flowLayoutPanel1 + // + this.flowLayoutPanel1.Controls.Add(this.currentTitleLabel); + this.flowLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; + this.flowLayoutPanel1.FlowDirection = System.Windows.Forms.FlowDirection.TopDown; + this.flowLayoutPanel1.Location = new System.Drawing.Point(3, 16); + this.flowLayoutPanel1.Name = "flowLayoutPanel1"; + this.flowLayoutPanel1.Size = new System.Drawing.Size(212, 301); + this.flowLayoutPanel1.TabIndex = 0; + // + // currentTitleLabel + // + this.currentTitleLabel.AutoSize = true; + this.currentTitleLabel.Location = new System.Drawing.Point(2, 0); + this.currentTitleLabel.Margin = new System.Windows.Forms.Padding(2, 0, 2, 0); + this.currentTitleLabel.Name = "currentTitleLabel"; + this.currentTitleLabel.Size = new System.Drawing.Size(67, 13); + this.currentTitleLabel.TabIndex = 11; + this.currentTitleLabel.Text = "Current Title:"; + // + // Form1 + // + this.AcceptButton = this.selectFolderButton; + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(560, 401); + this.Controls.Add(this.tableLayoutPanel1); + this.MainMenuStrip = this.mainMenuStrip; + this.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2); + this.Name = "Form1"; + this.Text = "Form1"; + this.tableLayoutPanel1.ResumeLayout(false); + this.tableLayoutPanel1.PerformLayout(); + this.mainMenuStrip.ResumeLayout(false); + this.mainMenuStrip.PerformLayout(); + this.detailsGroupBox.ResumeLayout(false); + this.buttonPanel.ResumeLayout(false); + this.flowLayoutPanel1.ResumeLayout(false); + this.flowLayoutPanel1.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + private System.Windows.Forms.Button selectFolderButton; + private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; + private System.Windows.Forms.MenuStrip mainMenuStrip; + private System.Windows.Forms.ToolStripMenuItem fileMainMenu; + private System.Windows.Forms.ToolStripMenuItem openFolderFileMainMenu; + private System.Windows.Forms.ToolStripMenuItem selectFileMainMenu; + private System.Windows.Forms.ListView inputFilesListView; + private System.Windows.Forms.GroupBox detailsGroupBox; + private System.Windows.Forms.Panel buttonPanel; + private System.Windows.Forms.Button applyChangesButton; + private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1; + private System.Windows.Forms.Label currentTitleLabel; + } +} + diff --git a/MKVTest/MKVTest/Form1.cs b/MKVTest/MKVTest/Form1.cs new file mode 100644 index 0000000..90b8a55 --- /dev/null +++ b/MKVTest/MKVTest/Form1.cs @@ -0,0 +1,238 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace MKVTest +{ + /* Call mkvpropedit.exe + * Edit "Title" detail property: --edit info --set "title=%TITLE%" %FILE% + * Edit video track one: --edit track:v1 --set "name(or language)="%VAR%" %FILE% + * Edit audio track one: --edit track:a1 --set "name(or language)="%VAR%" %FILE% + * To add simply replace "--set" with "--add". + */ + public partial class Form1 : Form + { + public static string Language = "eng"; + private static readonly ContextMenuStrip menu = new ContextMenuStrip(); + + public Form1() + { + InitializeComponent(); + inputFilesListView.ItemSelectionChanged += UpdateFilePropPrediction; + inputFilesListView.MouseClick += ShowMenu; + this.Resize += Form1_Resize; + + var item = new ToolStripMenuItem + { + Name = "RemoveItem", + Text = @"Remove" + }; + menu.Items.Add(item); + + var inputColumn = new ColumnHeader() + { + Text = @"Files", + Name = @"HeaderColumn", + Width = inputFilesListView.Width - 10 + }; + inputFilesListView.Columns.Add(inputColumn); + } + + private void ShowMenu(object sender, MouseEventArgs e) + { + if (e.Button == MouseButtons.Right) + { + if (inputFilesListView.FocusedItem.Bounds.Contains(e.Location) == true) + { + menu.Show(Cursor.Position); + } + } + } + + private void UpdateFilePropPrediction(object sender, ListViewItemSelectionChangedEventArgs e) + { + var info = new MkvFileInfo(); + var file = info.GetAttributes(e.Item.Name); + flowLayoutPanel1.Controls.Clear(); + flowLayoutPanel1.Invalidate(); + + var titleLabel = new Label() + { + Parent = flowLayoutPanel1, + Text = @"Current Title: " + file.SegementInformation?.Title, + AutoSize = true + }; + + flowLayoutPanel1.Container?.Add(titleLabel); + + var videoTrackNumber = 1; + var audioTrackNumber = 1; + + foreach (var fileTrack in file.Tracks) + { + if (fileTrack.Type == MkvTrack.TrackType.Video) + { + var nameLabel = new Label + { + AutoSize = true, + Text = @"Track:v" + videoTrackNumber + @" Name: " + fileTrack.Name, + Parent = flowLayoutPanel1 + }; + + var languageLabel = new Label + { + AutoSize = true, + Text = @"Track:v" + videoTrackNumber + @" Language: " + fileTrack.Language, + Parent = flowLayoutPanel1 + }; + videoTrackNumber++; + if (flowLayoutPanel1.Container != null) + { + flowLayoutPanel1.Container.Add(nameLabel); + flowLayoutPanel1.Container.Add(languageLabel); + } + } + + if (fileTrack.Type == MkvTrack.TrackType.Audio) + { + var nameLabel = new Label + { + AutoSize = true, + Text = @"Track:a" + audioTrackNumber + @" Name: " + fileTrack.Name, + Parent = flowLayoutPanel1 + }; + var languageLabel = new Label + { + AutoSize = true, + Text = @"Track:a" + audioTrackNumber + @" Language: " + fileTrack.Language, + Parent = flowLayoutPanel1 + }; + audioTrackNumber++; + if (flowLayoutPanel1.Container != null) + { + flowLayoutPanel1.Container.Add(nameLabel); + flowLayoutPanel1.Container.Add(languageLabel); + } + } + } + } + + /// + /// + /// + /// + /// + private string GetEpisodeName(string text) + { + var s = new StringBuilder(); + var hyphenCount = 0; + var index = 0; + var fileExtensionStartPoint = text.LastIndexOf(".", StringComparison.InvariantCulture); + foreach (var c in text) + { + if (c == '-' && hyphenCount != 2) + { + hyphenCount++; + index++; + continue; + } + + if (hyphenCount == 2) + { + if (c == '.' && index == fileExtensionStartPoint) + { + break; + } + s.Append(c); + } + + index++; + } + + return s.ToString().Trim(); + } + + private void ListFiles(string folderPath) + { + var dir = new DirectoryInfo(folderPath); + var files = dir.GetFiles("*.mkv", SearchOption.TopDirectoryOnly); + foreach (var file in files) + { + var node = new ListViewItem() + { + Tag = true, //Assume the file needs to be updated. + Name = file.FullName, + Text = file.Name + }; + inputFilesListView.Items.Add(node); + } + + if (inputFilesListView.Items.Count > 0) + { + applyChangesButton.Enabled = true; + } + } + + private void button1_Click(object sender, EventArgs e) + { + var d = new FolderBrowserDialog(); + if (d.ShowDialog() == DialogResult.OK) + { + ClearForm(); + ListFiles(d.SelectedPath); + } + } + + private void Form1_Resize(object sender, EventArgs e) + { + inputFilesListView.Columns[0].Width = inputFilesListView.Width - 10; + } + + private void applyChangesButton_Click(object sender, EventArgs e) + { + + foreach (ListViewItem node in inputFilesListView.Items) + { + //Check to see if the item has been modified. + if (node.Tag == null || (bool) node.Tag == false) continue; + if (!File.Exists(node.Name)) continue; + var command = "/C mkvpropedit.exe --edit info --set \"title=" + GetEpisodeName(node.Text) + + "\" --edit track:v1 --set \"name=" + GetEpisodeName(node.Text) + + "\" --edit track:v1 --set \"language=eng\" --edit track:a1 --set \"name=English\" --edit track:a1 --set \"language=eng\" \"" + node.Name + "\" > temp.txt"; + var process = new System.Diagnostics.Process(); + var startInfo = new System.Diagnostics.ProcessStartInfo + { + WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal, + FileName = "cmd.exe", + Arguments = command + }; + process.StartInfo = startInfo; + process.Start(); + while (!process.HasExited) + { + + } + if (process.ExitCode == 0) continue; + var error = File.ReadAllLines("temp.txt"); + MessageBox.Show(@"Error on node: " + node.Text + (error.Length > 0 ? Environment.NewLine + error[0] : string.Empty)); + break; + } + + File.Delete("temp.txt"); + } + + private void ClearForm() + { + inputFilesListView.Items.Clear(); + flowLayoutPanel1.Controls.Clear(); + flowLayoutPanel1.Invalidate(); + } + } +} diff --git a/MKVTest/MKVTest/Form1.resx b/MKVTest/MKVTest/Form1.resx new file mode 100644 index 0000000..f80b0f3 --- /dev/null +++ b/MKVTest/MKVTest/Form1.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/MKVTest/MKVTest/MKVTest.csproj b/MKVTest/MKVTest/MKVTest.csproj new file mode 100644 index 0000000..0b23721 --- /dev/null +++ b/MKVTest/MKVTest/MKVTest.csproj @@ -0,0 +1,95 @@ + + + + + Debug + AnyCPU + {A750A634-6881-4083-B909-73EFE4C96802} + WinExe + MKVTest + MKVTest + v4.6.1 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + Form + + + Form1.cs + + + + + + + + + + Form1.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + PreserveNewest + + + PreserveNewest + + + + \ No newline at end of file diff --git a/MKVTest/MKVTest/MkvFile.cs b/MKVTest/MKVTest/MkvFile.cs new file mode 100644 index 0000000..9d53df8 --- /dev/null +++ b/MKVTest/MKVTest/MkvFile.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MKVTest +{ + class MkvFile + { + public List Tracks; + public MkvSegmentInformation SegementInformation; + public string FullName; + public string FileName; + } +} diff --git a/MKVTest/MKVTest/MkvFileInfo.cs b/MKVTest/MKVTest/MkvFileInfo.cs new file mode 100644 index 0000000..d9e1b7f --- /dev/null +++ b/MKVTest/MKVTest/MkvFileInfo.cs @@ -0,0 +1,109 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace MKVTest +{ + class MkvFileInfo + { + + public MkvFile GetAttributes(string filePath) + { + var file = new MkvFile { Tracks = GetShit(filePath, out MkvSegmentInformation info), SegementInformation = info }; + return file; + } + + private static List GetShit(string filePath, out MkvSegmentInformation information) + { + var tracks = new List(); + information = null; + var command = "/C mkvinfo.exe \"" + filePath + "\" > info.txt"; + var process = new System.Diagnostics.Process(); + var startInfo = new System.Diagnostics.ProcessStartInfo + { + WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal, + FileName = "cmd.exe", + Arguments = command + }; + process.StartInfo = startInfo; + process.Start(); + while (!process.HasExited) + { + + } + var info = File.ReadAllLines("info.txt"); + var readingSegInfo = false; + var readingTrack = false; + var track = new MkvTrack(); + for (var i = 0; i < info.Length; i++) + { + if (info[i] == "|+ Segment information") + { + readingSegInfo = true; + readingTrack = false; + continue; + } + + if (info[i] == "| + A track") + { + readingTrack = true; + readingSegInfo = false; + if (track.Name == null && track.Language == null) continue; + tracks.Add(track); + track = new MkvTrack(); + } + + if (readingSegInfo) + { + if (info[i].Contains("Title:")) + { + var index = info[i].IndexOf(":", StringComparison.Ordinal) + 1; + var seg = new MkvSegmentInformation + { + Title = info[i].Substring(index, info[i].Length - index).Trim() + }; + information = seg; + } + } + + if (readingTrack) + { + if (info[i].Contains("Name:")) + { + var index = info[i].IndexOf(":", StringComparison.Ordinal) + 1; + track.Name = info[i].Substring(index, (info[i].Length - index)).Trim(); + } + + if (info[i].Contains("Language:")) + { + var index = info[i].IndexOf(":", StringComparison.Ordinal) + 1; + track.Language = info[i].Substring(index, (info[i].Length - index)).Trim(); + } + + if (info[i].Contains("Video track")) + { + track.Type = MkvTrack.TrackType.Video; + } + if (info[i].Contains("Audio track")) + { + track.Type = MkvTrack.TrackType.Audio; + } + if (info[i].Contains("Track type: subtitles")) + { + track.Type = MkvTrack.TrackType.Subtitle; + } + } + } + if (information == null) + { + information = new MkvSegmentInformation(); + } + + return tracks; + } + } +} diff --git a/MKVTest/MKVTest/MkvSegmentInformation.cs b/MKVTest/MKVTest/MkvSegmentInformation.cs new file mode 100644 index 0000000..c77d602 --- /dev/null +++ b/MKVTest/MKVTest/MkvSegmentInformation.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MKVTest +{ + class MkvSegmentInformation + { + public string Title; + } +} diff --git a/MKVTest/MKVTest/MkvTrack.cs b/MKVTest/MKVTest/MkvTrack.cs new file mode 100644 index 0000000..1bbb152 --- /dev/null +++ b/MKVTest/MKVTest/MkvTrack.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MKVTest +{ + class MkvTrack + { + public string Name; + public string Language; + public TrackType Type; + + + + public enum TrackType + { + Video = 1, + Audio = 2, + Subtitle = 3, + Unkown = 0 + } + } +} diff --git a/MKVTest/MKVTest/Program.cs b/MKVTest/MKVTest/Program.cs new file mode 100644 index 0000000..4b8be12 --- /dev/null +++ b/MKVTest/MKVTest/Program.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace MKVTest +{ + static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new Form1()); + } + } +} diff --git a/MKVTest/MKVTest/Properties/AssemblyInfo.cs b/MKVTest/MKVTest/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..7fcefa0 --- /dev/null +++ b/MKVTest/MKVTest/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("MKVTest")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("MKVTest")] +[assembly: AssemblyCopyright("Copyright © 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("a750a634-6881-4083-b909-73efe4c96802")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// 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")] diff --git a/MKVTest/MKVTest/Properties/Resources.Designer.cs b/MKVTest/MKVTest/Properties/Resources.Designer.cs new file mode 100644 index 0000000..c3b5087 --- /dev/null +++ b/MKVTest/MKVTest/Properties/Resources.Designer.cs @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace MKVTest.Properties +{ + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources + { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() + { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager + { + get + { + if ((resourceMan == null)) + { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("MKVTest.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture + { + get + { + return resourceCulture; + } + set + { + resourceCulture = value; + } + } + } +} diff --git a/MKVTest/MKVTest/Properties/Resources.resx b/MKVTest/MKVTest/Properties/Resources.resx new file mode 100644 index 0000000..af7dbeb --- /dev/null +++ b/MKVTest/MKVTest/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/MKVTest/MKVTest/Properties/Settings.Designer.cs b/MKVTest/MKVTest/Properties/Settings.Designer.cs new file mode 100644 index 0000000..3fe9777 --- /dev/null +++ b/MKVTest/MKVTest/Properties/Settings.Designer.cs @@ -0,0 +1,30 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace MKVTest.Properties +{ + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase + { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default + { + get + { + return defaultInstance; + } + } + } +} diff --git a/MKVTest/MKVTest/Properties/Settings.settings b/MKVTest/MKVTest/Properties/Settings.settings new file mode 100644 index 0000000..3964565 --- /dev/null +++ b/MKVTest/MKVTest/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/MKVTest/MKVTest/SerializeMkvInfo.cs b/MKVTest/MKVTest/SerializeMkvInfo.cs new file mode 100644 index 0000000..8fc6461 --- /dev/null +++ b/MKVTest/MKVTest/SerializeMkvInfo.cs @@ -0,0 +1,80 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MKVTest +{ + class SerializeMkvInfo + { + + public string Serialize(string filePath) + { + var file = File.ReadAllLines(filePath); + var depth = 0; + + foreach (var line in file) + { + + } + } + + private string + + private int GetDepth(string line) + { + var depth = -1; + + for (var i = 0; i < line.Length; i++) + { + if (char.IsPunctuation(line[i]) || char.IsWhiteSpace(line[i])) + { + depth++; + } + else + { + break; + } + } + + return depth; + } + + private bool IsClusterHead(string data) + { + var isClusterHeader = false; + + switch (data) + { + case "EBML head": + + break; + case "Chapters": + + break; + case "Segment": + + break; + case "Segment information": + + break; + case "Segment tracks": + + break; + case "A track": + + break; + case "Video track": + + break; + case "Audio track": + + break; + } + + return isClusterHeader; + } + } +} diff --git a/MKVTest/MKVTest/mkvinfo.exe b/MKVTest/MKVTest/mkvinfo.exe new file mode 100644 index 0000000..5f18ac3 Binary files /dev/null and b/MKVTest/MKVTest/mkvinfo.exe differ diff --git a/MKVTest/MKVTest/mkvpropedit.exe b/MKVTest/MKVTest/mkvpropedit.exe new file mode 100644 index 0000000..41ff850 Binary files /dev/null and b/MKVTest/MKVTest/mkvpropedit.exe differ