This commit is contained in:
stax76
2022-06-03 15:47:21 +02:00
parent e9df0f9f99
commit 971fe1fe7c
5 changed files with 369 additions and 412 deletions

View File

@@ -330,6 +330,9 @@ Shows media info in a messsge box.
**editor**
Shows media info in the text editor.
**osd**
Displays media info on screen.
**full**
Shows fully detailed media info.

View File

@@ -6,15 +6,15 @@ using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Interop;
using System.Windows.Media;
using WinForms = System.Windows.Forms;
using static mpvnet.Global;
using System.Windows.Media;
using System.Text.RegularExpressions;
namespace mpvnet
{
@@ -172,42 +172,65 @@ namespace mpvnet
if (CorePlayer.AudioTypes.Contains(path.Ext()))
{
using (MediaInfo mediaInfo = new MediaInfo(path))
if (App.MediaInfo)
{
performer = mediaInfo.GetInfo(MediaInfoStreamKind.General, "Performer");
title = mediaInfo.GetInfo(MediaInfoStreamKind.General, "Title");
album = mediaInfo.GetInfo(MediaInfoStreamKind.General, "Album");
genre = mediaInfo.GetInfo(MediaInfoStreamKind.General, "Genre");
date = mediaInfo.GetInfo(MediaInfoStreamKind.General, "Recorded_Date");
duration = mediaInfo.GetInfo(MediaInfoStreamKind.Audio, "Duration/String");
using (MediaInfo mediaInfo = new MediaInfo(path))
{
performer = mediaInfo.GetInfo(MediaInfoStreamKind.General, "Performer");
title = mediaInfo.GetInfo(MediaInfoStreamKind.General, "Title");
album = mediaInfo.GetInfo(MediaInfoStreamKind.General, "Album");
genre = mediaInfo.GetInfo(MediaInfoStreamKind.General, "Genre");
date = mediaInfo.GetInfo(MediaInfoStreamKind.General, "Recorded_Date");
duration = mediaInfo.GetInfo(MediaInfoStreamKind.Audio, "Duration/String");
if (performer != "") text += "Artist: " + performer + "\n";
if (title != "") text += "Title: " + title + "\n";
if (album != "") text += "Album: " + album + "\n";
if (genre != "") text += "Genre: " + genre + "\n";
if (date != "") text += "Year: " + date + "\n";
if (duration != "") text += "Length: " + duration + "\n";
if (performer != "") text += "Artist: " + performer + "\n";
if (title != "") text += "Title: " + title + "\n";
if (album != "") text += "Album: " + album + "\n";
if (genre != "") text += "Genre: " + genre + "\n";
if (date != "") text += "Year: " + date + "\n";
if (duration != "") text += "Length: " + duration + "\n";
text += "Size: " + mediaInfo.GetInfo(MediaInfoStreamKind.General, "FileSize/String") + "\n";
text += "Type: " + path.Ext().ToUpper();
Core.CommandV("show-text", text, "5000");
return;
text += "Size: " + mediaInfo.GetInfo(MediaInfoStreamKind.General, "FileSize/String") + "\n";
text += "Type: " + path.Ext().ToUpper();
}
}
else
{
text = "File: " + path.FileName() + "\n";
duration = TimeSpan.FromSeconds((int)Core.GetPropertyDouble("duration")).ToString();
if (duration != "") text += "Length: " + duration + "\n";
if (fileSize > 0) text += "Size: " + Convert.ToInt32(fileSize / 1024.0 / 1024.0) + " MB\n";
text += "Type: " + path.Ext().ToUpper();
}
Core.CommandV("show-text", text, "5000");
return;
}
else if (CorePlayer.ImageTypes.Contains(path.Ext()))
{
using (MediaInfo mediaInfo = new MediaInfo(path))
if (App.MediaInfo)
{
text =
"Width: " + mediaInfo.GetInfo(MediaInfoStreamKind.Image, "Width") + "\n" +
"Height: " + mediaInfo.GetInfo(MediaInfoStreamKind.Image, "Height") + "\n" +
"Size: " + mediaInfo.GetInfo(MediaInfoStreamKind.General, "FileSize/String") + "\n" +
"Type: " + path.Ext().ToUpper();
Core.CommandV("show-text", text, "5000");
return;
using (MediaInfo mediaInfo = new MediaInfo(path))
{
text = "Width: " + mediaInfo.GetInfo(MediaInfoStreamKind.Image, "Width") + "\n" +
"Height: " + mediaInfo.GetInfo(MediaInfoStreamKind.Image, "Height") + "\n" +
"Size: " + mediaInfo.GetInfo(MediaInfoStreamKind.General, "FileSize/String") + "\n" +
"Type: " + path.Ext().ToUpper();
}
}
else
{
text = "Width: " + Core.GetPropertyInt("width") + "\n" +
"Height: " + Core.GetPropertyInt("height") + "\n" +
"Size: " + Convert.ToInt32(fileSize / 1024.0) + " KB\n" +
"Type: " + path.Ext().ToUpper();
}
Core.CommandV("show-text", text, "5000");
return;
}
}
@@ -303,38 +326,30 @@ namespace mpvnet
public static void CycleAudio()
{
if (!App.MediaInfo)
Core.UpdateTrackData();
Core.UpdateExternalTracks();
var tracks = Core.MediaTracks.Where(track => track.Type == "a").ToArray();
if (App.MediaInfo)
lock (Core.MediaTracksLock)
{
var externalTracks = Core.GetExternalTracks().Where(track => track.Type == "a");
MediaTrack[] tracks = Core.MediaTracks.Where(track => track.Type == "a").ToArray();
if (externalTracks.Count() > 0)
tracks = tracks.Concat(externalTracks).ToArray();
if (tracks.Length < 1)
{
Core.CommandV("show-text", "No audio tracks");
return;
}
int aid = Core.GetPropertyInt("aid");
if (tracks.Length > 1)
{
if (++aid > tracks.Length)
aid = 1;
Core.CommandV("set", "aid", aid.ToString());
}
Core.CommandV("show-text", aid + "/" + tracks.Length + ": " + tracks[aid - 1].Text.Substring(3), "5000");
}
int len = tracks.Length;
if (len < 1)
{
Core.CommandV("show-text", "No audio tracks");
return;
}
int aid = Core.GetPropertyInt("aid");
if (len > 1)
{
if (++aid > len)
aid = 1;
Core.CommandV("set", "aid", aid.ToString());
}
Core.CommandV("show-text", aid + "/" + len + ": " + tracks[aid - 1].Text.Substring(3), "5000");
}
public static void ShowCommands()
@@ -388,6 +403,7 @@ namespace mpvnet
(string Name, string Value)[] pairs = {
("Show text box", "script-message mpv.net show-media-info default"),
("Show text editor", "script-message mpv.net show-media-info editor"),
("Show on screen", "script-message mpv.net show-media-info osd"),
("Show full", "script-message mpv.net show-media-info editor full"),
("Show raw", "script-message mpv.net show-media-info editor full raw") };
@@ -402,23 +418,32 @@ namespace mpvnet
if (File.Exists(path) && !path.Contains(@"\\.\pipe\"))
{
using (MediaInfo mediaInfo = new MediaInfo(path))
string text = "";
bool full = args.Contains("full");
bool raw = args.Contains("raw");
bool editor = args.Contains("editor");
bool osd = args.Contains("osd");
if (App.MediaInfo && !osd)
using (MediaInfo mediaInfo = new MediaInfo(path))
text = Regex.Replace(mediaInfo.GetSummary(full, raw), "Unique ID.+", "");
else
lock (Core.MediaTracksLock)
foreach (MediaTrack track in Core.MediaTracks)
text += track.Text + BR;
text = text.TrimEx();
if (editor)
ShowTextWithEditor("media-info", text);
else if (osd)
Core.CommandV("show-text", text.Replace("\r", ""), "5000");
else
{
bool full = args.Contains("full");
bool raw = args.Contains("raw");
bool editor = args.Contains("editor");
string text = mediaInfo.GetSummary(full, raw);
text = Regex.Replace(text, "Unique ID.+", "");
if (editor)
ShowTextWithEditor("media-info", text);
else
{
MsgBoxEx.MessageBoxEx.MsgFontFamily = new FontFamily("Consolas");
Msg.ShowInfo(text);
MsgBoxEx.MessageBoxEx.MsgFontFamily = new FontFamily("Segoe UI");
}
MsgBoxEx.MessageBoxEx.MsgFontFamily = new FontFamily("Consolas");
Msg.ShowInfo(text);
MsgBoxEx.MessageBoxEx.MsgFontFamily = new FontFamily("Segoe UI");
}
}
});
@@ -432,92 +457,81 @@ namespace mpvnet
public static void ShowAudioTracks() => App.InvokeOnMainThread(() =>
{
if (!App.MediaInfo)
Core.UpdateTrackData();
Core.UpdateExternalTracks();
var tracks = Core.MediaTracks.Where(track => track.Type == "a").ToArray();
if (App.MediaInfo)
lock (Core.MediaTracksLock)
{
var externalTracks = Core.GetExternalTracks().Where(track => track.Type == "a");
MediaTrack[] tracks = Core.MediaTracks.Where(track => track.Type == "a").ToArray();
if (externalTracks.Count() > 0)
tracks = tracks.Concat(externalTracks).ToArray();
}
if (tracks.Length < 1)
{
Core.CommandV("show-text", "No audio tracks");
return;
}
List<CommandPaletteItem> items = new List<CommandPaletteItem>();
foreach (MediaTrack i in tracks)
{
MediaTrack track = i;
CommandPaletteItem item = new CommandPaletteItem()
if (tracks.Length < 1)
{
Text = track.Text,
Action = () => {
Core.CommandV("set", "aid", track.ID.ToString());
Core.CommandV("show-text", track.ID + "/" + tracks.Length + ": " +
tracks[track.ID - 1].Text.Substring(3), "5000");
}
};
Core.CommandV("show-text", "No audio tracks");
return;
}
items.Add(item);
List<CommandPaletteItem> items = new List<CommandPaletteItem>();
foreach (MediaTrack i in tracks)
{
MediaTrack track = i;
CommandPaletteItem item = new CommandPaletteItem()
{
Text = track.Text,
Action = () => {
Core.CommandV("set", "aid", track.ID.ToString());
Core.CommandV("show-text", track.ID + "/" + tracks.Length + ": " +
tracks[track.ID - 1].Text.Substring(3), "5000");
}
};
items.Add(item);
}
CommandPalette.Instance.SetItems(items);
MainForm.Instance.ShowCommandPalette();
CommandPalette.Instance.SelectFirst();
}
CommandPalette.Instance.SetItems(items);
MainForm.Instance.ShowCommandPalette();
CommandPalette.Instance.SelectFirst();
});
public static void ShowSubtitleTracks() => App.InvokeOnMainThread(() =>
{
if (!App.MediaInfo)
Core.UpdateTrackData();
Core.UpdateExternalTracks();
var tracks = Core.MediaTracks.Where(track => track.Type == "s").ToArray();
if (App.MediaInfo)
lock (Core.MediaTracksLock)
{
var externalTracks = Core.GetExternalTracks().Where(track => track.Type == "s");
MediaTrack[] tracks = Core.MediaTracks.Where(track => track.Type == "s").ToArray();
if (externalTracks.Count() > 0)
tracks = tracks.Concat(externalTracks).ToArray();
}
if (tracks.Length < 1)
{
Core.CommandV("show-text", "No subtitle tracks");
return;
}
List<CommandPaletteItem> items = new List<CommandPaletteItem>();
foreach (MediaTrack i in tracks)
{
MediaTrack track = i;
CommandPaletteItem item = new CommandPaletteItem()
if (tracks.Length < 1)
{
Text = track.Text,
Action = () => {
Core.CommandV("set", "sid", track.ID.ToString());
Core.CommandV("show-text", track.ID + "/" + tracks.Length + ": " +
tracks[track.ID - 1].Text.Substring(3), "5000");
}
};
Core.CommandV("show-text", "No subtitle tracks");
return;
}
items.Add(item);
List<CommandPaletteItem> items = new List<CommandPaletteItem>();
foreach (MediaTrack i in tracks)
{
MediaTrack track = i;
CommandPaletteItem item = new CommandPaletteItem()
{
Text = track.Text,
Action = () => {
Core.CommandV("set", "sid", track.ID.ToString());
Core.CommandV("show-text", track.ID + "/" + tracks.Length + ": " +
tracks[track.ID - 1].Text.Substring(3), "5000");
}
};
items.Add(item);
}
CommandPalette.Instance.SetItems(items);
MainForm.Instance.ShowCommandPalette();
CommandPalette.Instance.SelectFirst();
}
CommandPalette.Instance.SetItems(items);
MainForm.Instance.ShowCommandPalette();
CommandPalette.Instance.SelectFirst();
});
public static void ShowPlaylist() => App.InvokeOnMainThread(() =>

View File

@@ -227,10 +227,9 @@ namespace mpvnet
void UpdateMenu()
{
if (!App.MediaInfo)
Core.UpdateTrackData();
Core.UpdateExternalTracks();
lock (Core.MediaTracks)
lock (Core.MediaTracksLock)
{
var trackMenuItem = FindMenuItem("Track");
@@ -243,23 +242,6 @@ namespace mpvnet
var vidTracks = Core.MediaTracks.Where(track => track.Type == "v");
var ediTracks = Core.MediaTracks.Where(track => track.Type == "e");
if (App.MediaInfo)
{
var externalTracks = Core.GetExternalTracks();
if (externalTracks.Count > 0)
{
var exAudTracks = externalTracks.Where(track => track.Type == "a");
var exSubTracks = externalTracks.Where(track => track.Type == "s");
if (exAudTracks.Count() > 0)
audTracks = audTracks.Concat(exAudTracks);
if (exSubTracks.Count() > 0)
subTracks = subTracks.Concat(exSubTracks);
}
}
foreach (MediaTrack track in vidTracks)
{
var mi = new WpfControls.MenuItem() { Header = track.Text };
@@ -748,14 +730,16 @@ namespace mpvnet
path = path + "|" + title;
}
if (App.Settings.RecentFiles.Contains(path))
App.Settings.RecentFiles.Remove(path);
if (!string.IsNullOrEmpty(path) && path != @"bd://" && path != @"dvd://")
{
if (App.Settings.RecentFiles.Contains(path))
App.Settings.RecentFiles.Remove(path);
if (path != @"bd://" && path != @"dvd://")
App.Settings.RecentFiles.Insert(0, path);
while (App.Settings.RecentFiles.Count > App.RecentCount)
App.Settings.RecentFiles.RemoveAt(App.RecentCount);
while (App.Settings.RecentFiles.Count > App.RecentCount)
App.Settings.RecentFiles.RemoveAt(App.RecentCount);
}
}
void SetTitle() => BeginInvoke(new Action(() => Text = Core.Expand(Title)));

View File

@@ -134,9 +134,10 @@ namespace mpvnet
public class MediaTrack
{
public int ID { get; set; }
public bool External { get; set; }
public string Text { get; set; }
public string Type { get; set; }
public int ID { get; set; }
}
public class CommandItem : INotifyPropertyChanged

View File

@@ -70,6 +70,7 @@ namespace mpvnet
public Dictionary<string, List<Action<string>>> StringPropChangeActions { get; set; } = new Dictionary<string, List<Action<string>>>();
public List<MediaTrack> MediaTracks { get; set; } = new List<MediaTrack>();
public object MediaTracksLock { get; } = new object();
public List<KeyValuePair<string, double>> Chapters { get; set; } = new List<KeyValuePair<string, double>>();
public List<TimeSpan> BluRayTitles { get; } = new List<TimeSpan>();
public IntPtr Handle { get; set; }
@@ -541,8 +542,7 @@ namespace mpvnet
VideoSizeAutoResetEvent.Set();
}
if (App.MediaInfo)
App.RunTask(new Action(() => UpdateTrackDataUsingMediaInfo()));
App.RunTask(new Action(() => UpdateTracks()));
App.RunTask(new Action(() => {
if (path.Contains("://"))
@@ -1377,10 +1377,31 @@ namespace mpvnet
string GetLanguage(string id)
{
foreach (CultureInfo ci in CultureInfo.GetCultures(CultureTypes.NeutralCultures))
if (ci.ThreeLetterISOLanguageName == id)
if (ci.ThreeLetterISOLanguageName == id || Convert(ci.ThreeLetterISOLanguageName) == id)
return ci.EnglishName;
return id;
string Convert(string id2)
{
switch (id2)
{
case "bng": return "ben";
case "ces": return "cze";
case "deu": return "ger";
case "ell": return "gre";
case "eus": return "baq";
case "fra": return "fre";
case "hye": return "arm";
case "isl": return "ice";
case "kat": return "geo";
case "mya": return "bur";
case "nld": return "dut";
case "sqi": return "alb";
case "zho": return "chi";
default: return id2;
}
}
}
public void RaiseScaleWindow(float value) => ScaleWindow(value);
@@ -1389,54 +1410,7 @@ namespace mpvnet
public void RaiseShowMenu() => ShowMenu();
public List<MediaTrack> GetExternalTracks()
{
List<MediaTrack> tracks = new List<MediaTrack>();
int count = GetPropertyInt("track-list/count");
for (int i = 0; i < count; i++)
{
bool external = GetPropertyBool($"track-list/{i}/external");
if (external)
{
string type = GetPropertyString($"track-list/{i}/type");
string filename = GetPropertyString($"filename/no-ext");
string title = GetPropertyString($"track-list/{i}/title").Replace(filename, "");
title = Regex.Replace(title, @"^[\._\-]", "").Replace("_", "__");
if (type == "audio")
{
MediaTrack track = new MediaTrack();
Add(track, GetLanguage(GetPropertyString($"track-list/{i}/lang")));
Add(track, GetPropertyString($"track-list/{i}/codec").ToUpperEx());
Add(track, GetPropertyInt($"track-list/{i}/audio-channels") + " channels");
Add(track, "External");
Add(track, title);
track.Text = "A: " + track.Text.Trim(' ', ',');
track.Type = "a";
track.ID = GetPropertyInt($"track-list/{i}/id");
tracks.Add(track);
}
else if (type == "sub")
{
MediaTrack track = new MediaTrack();
Add(track, GetLanguage(GetPropertyString($"track-list/{i}/lang")));
Add(track, GetPropertyString($"track-list/{i}/codec").ToUpperEx());
Add(track, "External");
Add(track, title);
track.Text = "S: " + track.Text.Trim(' ', ',');
track.Type = "s";
track.ID = GetPropertyInt($"track-list/{i}/id");
tracks.Add(track);
}
}
}
return tracks;
}
public void UpdateTrackData()
public void UpdateTracks()
{
string path = GetPropertyString("path");
@@ -1444,64 +1418,118 @@ namespace mpvnet
lock (BluRayTitles)
BluRayTitles.Clear();
lock (MediaTracks)
lock (MediaTracksLock)
{
MediaTracks.Clear();
if (App.MediaInfo && !path.Contains("://") && !path.Contains(@"\\.\pipe\") && File.Exists(path))
MediaTracks = GetMediaInfoTracks(path);
else
MediaTracks = GetTracks();
}
int trackListCount = GetPropertyInt("track-list/count");
lock (Chapters)
{
Chapters.Clear();
int count = GetPropertyInt("chapter-list/count");
for (int i = 0; i < trackListCount; i++)
for (int x = 0; x < count; x++)
{
string type = GetPropertyString($"track-list/{i}/type");
string filename = GetPropertyString($"filename/no-ext");
string title = GetPropertyString($"track-list/{i}/title").Replace(filename, "");
string text = GetPropertyString($"chapter-list/{x}/title");
double time = GetPropertyDouble($"chapter-list/{x}/time");
title = Regex.Replace(title, @"^[\._\-]", "").Replace("_", "__");
if (string.IsNullOrEmpty(text))
text = "Chapter " + (x + 1);
if (type == "video")
{
MediaTrack track = new MediaTrack();
Add(track, GetPropertyString($"track-list/{i}/codec").ToUpperEx());
Add(track, GetPropertyString($"track-list/{i}/demux-w") + "x" + GetPropertyString($"track-list/{i}/demux-h"));
Add(track, GetPropertyString($"track-list/{i}/demux-fps").Replace(".000000", "") + " FPS");
Add(track, GetPropertyBool($"track-list/{i}/default") ? "Default" : null);
track.Text = "V: " + track.Text.Trim(' ', ',');
track.Type = "v";
track.ID = GetPropertyInt($"track-list/{i}/id");
MediaTracks.Add(track);
}
else if (type == "audio")
{
MediaTrack track = new MediaTrack();
Add(track, GetLanguage(GetPropertyString($"track-list/{i}/lang")));
Add(track, GetPropertyString($"track-list/{i}/codec").ToUpperEx());
Add(track, GetPropertyInt($"track-list/{i}/audio-channels") + " channels");
Add(track, GetPropertyInt($"track-list/{i}/demux-samplerate") + " Hz");
Add(track, GetPropertyBool($"track-list/{i}/forced") ? "Forced" : null);
Add(track, GetPropertyBool($"track-list/{i}/default") ? "Default" : null);
Add(track, GetPropertyBool($"track-list/{i}/external") ? "External" : null);
Add(track, title);
track.Text = "A: " + track.Text.Trim(' ', ',');
track.Type = "a";
track.ID = GetPropertyInt($"track-list/{i}/id");
MediaTracks.Add(track);
}
else if (type == "sub")
{
MediaTrack track = new MediaTrack();
Add(track, GetLanguage(GetPropertyString($"track-list/{i}/lang")));
Add(track, GetPropertyString($"track-list/{i}/codec").ToUpperEx());
Add(track, GetPropertyBool($"track-list/{i}/forced") ? "Forced" : null);
Add(track, GetPropertyBool($"track-list/{i}/default") ? "Default" : null);
Add(track, GetPropertyBool($"track-list/{i}/external") ? "External" : null);
Add(track, title);
track.Text = "S: " + track.Text.Trim(' ', ',');
track.Type = "s";
track.ID = GetPropertyInt($"track-list/{i}/id");
MediaTracks.Add(track);
}
Chapters.Add(new KeyValuePair<string, double>(text, time));
}
}
}
public void UpdateExternalTracks()
{
int trackCount = GetPropertyInt("track-list/count");
int editionCount = GetPropertyInt("edition-list/count");
lock (MediaTracksLock)
{
if (MediaTracks.Count != (trackCount + editionCount))
{
MediaTracks = MediaTracks.Where(i => !i.External).ToList();
MediaTracks.AddRange(GetTracks(false));
}
}
}
public List<MediaTrack> GetTracks(bool includeInternal = true, bool includeExternal = true)
{
List<MediaTrack> tracks = new List<MediaTrack>();
int trackCount = GetPropertyInt("track-list/count");
for (int i = 0; i < trackCount; i++)
{
bool external = GetPropertyBool($"track-list/{i}/external");
if ((external && !includeExternal) || (!external && !includeInternal))
continue;
string type = GetPropertyString($"track-list/{i}/type");
string filename = GetPropertyString($"filename/no-ext");
string title = GetPropertyString($"track-list/{i}/title").Replace(filename, "");
title = Regex.Replace(title, @"^[\._\-]", "").Replace("_", "__");
if (type == "video")
{
MediaTrack track = new MediaTrack();
Add(track, GetPropertyString($"track-list/{i}/codec").ToUpperEx());
Add(track, GetPropertyString($"track-list/{i}/demux-w") + "x" + GetPropertyString($"track-list/{i}/demux-h"));
Add(track, GetPropertyString($"track-list/{i}/demux-fps").Replace(".000000", "") + " FPS");
Add(track, GetPropertyBool($"track-list/{i}/default") ? "Default" : null);
track.Text = "V: " + track.Text.Trim(' ', ',');
track.Type = "v";
track.ID = GetPropertyInt($"track-list/{i}/id");
tracks.Add(track);
}
else if (type == "audio")
{
MediaTrack track = new MediaTrack();
Add(track, GetLanguage(GetPropertyString($"track-list/{i}/lang")));
Add(track, GetPropertyString($"track-list/{i}/codec").ToUpperEx());
Add(track, GetPropertyInt($"track-list/{i}/audio-channels") + " channels");
Add(track, GetPropertyInt($"track-list/{i}/demux-samplerate") + " Hz");
Add(track, GetPropertyBool($"track-list/{i}/forced") ? "Forced" : null);
Add(track, GetPropertyBool($"track-list/{i}/default") ? "Default" : null);
Add(track, GetPropertyBool($"track-list/{i}/external") ? "External" : null);
Add(track, title);
track.Text = "A: " + track.Text.Trim(' ', ',');
track.Type = "a";
track.ID = GetPropertyInt($"track-list/{i}/id");
track.External = external;
tracks.Add(track);
}
else if (type == "sub")
{
string codec = GetPropertyString($"track-list/{i}/codec");
if (codec == "hdmv_pgs_subtitle")
codec = "pgs";
MediaTrack track = new MediaTrack();
Add(track, GetLanguage(GetPropertyString($"track-list/{i}/lang")));
Add(track, codec.ToUpperEx());
Add(track, GetPropertyBool($"track-list/{i}/forced") ? "Forced" : null);
Add(track, GetPropertyBool($"track-list/{i}/default") ? "Default" : null);
Add(track, GetPropertyBool($"track-list/{i}/external") ? "External" : null);
Add(track, title);
track.Text = "S: " + track.Text.Trim(' ', ',');
track.Type = "s";
track.ID = GetPropertyInt($"track-list/{i}/id");
track.External = external;
tracks.Add(track);
Debug.WriteLine(GetPropertyString($"track-list/{i}/codec"));
}
}
if (includeInternal)
{
int editionCount = GetPropertyInt("edition-list/count");
for (int i = 0; i < editionCount; i++)
@@ -1513,164 +1541,91 @@ namespace mpvnet
track.Text = "E: " + title;
track.Type = "e";
track.ID = i;
MediaTracks.Add(track);
tracks.Add(track);
}
}
lock (Chapters)
{
Chapters.Clear();
int count = GetPropertyInt("chapter-list/count");
for (int x = 0; x < count; x++)
{
string text = GetPropertyString($"chapter-list/{x}/title");
double time = GetPropertyDouble($"chapter-list/{x}/time");
if (string.IsNullOrEmpty(text))
text = "Chapter " + (x + 1);
Chapters.Add(new KeyValuePair<string, double>(text, time));
}
}
return tracks;
}
public void UpdateTrackDataUsingMediaInfo()
public List<MediaTrack> GetMediaInfoTracks(string path)
{
string path = GetPropertyString("path");
List<MediaTrack> tracks = new List<MediaTrack>();
if (!path.ToLowerEx().StartsWithEx("bd://"))
lock (BluRayTitles)
BluRayTitles.Clear();
lock (MediaTracks)
using (MediaInfo mi = new MediaInfo(path))
{
MediaTracks.Clear();
int videoCount = mi.GetCount(MediaInfoStreamKind.Video);
if (path.ToLowerEx().Contains("://"))
for (int i = 0; i < videoCount; i++)
{
int trackListCount = GetPropertyInt("track-list/count");
for (int i = 0; i < trackListCount; i++)
{
string type = GetPropertyString($"track-list/{i}/type");
if (type == "audio")
{
MediaTrack track = new MediaTrack();
Add(track, GetLanguage(GetPropertyString($"track-list/{i}/lang")));
Add(track, GetPropertyString($"track-list/{i}/codec").ToUpperEx());
Add(track, GetPropertyInt($"track-list/{i}/audio-channels") + " channels");
track.Text = "A: " + track.Text.Trim(' ', ',');
track.Type = "a";
track.ID = GetPropertyInt($"track-list/{i}/id");
MediaTracks.Add(track);
}
else if (type == "sub")
{
MediaTrack track = new MediaTrack();
Add(track, GetLanguage(GetPropertyString($"track-list/{i}/lang")));
Add(track, GetPropertyString($"track-list/{i}/codec").ToUpperEx());
track.Text = "S: " + track.Text.Trim(' ', ',');
track.Type = "s";
track.ID = GetPropertyInt($"track-list/{i}/id");
MediaTracks.Add(track);
}
}
MediaTrack track = new MediaTrack();
Add(track, mi.GetVideo(i, "Format"));
Add(track, mi.GetVideo(i, "Format_Profile"));
Add(track, mi.GetVideo(i, "Width") + "x" + mi.GetVideo(i, "Height"));
Add(track, mi.GetVideo(i, "FrameRate") + " FPS");
Add(track, mi.GetVideo(i, "Language/String"));
Add(track, mi.GetVideo(i, "Forced") == "Yes" ? "Forced" : "");
Add(track, mi.GetVideo(i, "Default") == "Yes" ? "Default" : "");
Add(track, mi.GetVideo(i, "Title"));
track.Text = "V: " + track.Text.Trim(' ', ',');
track.Type = "v";
track.ID = i + 1;
tracks.Add(track);
}
else if (File.Exists(path) && !path.Contains(@"\\.\pipe\"))
int audioCount = mi.GetCount(MediaInfoStreamKind.Audio);
for (int i = 0; i < audioCount; i++)
{
using (MediaInfo mi = new MediaInfo(path))
{
int videoCount = mi.GetCount(MediaInfoStreamKind.Video);
MediaTrack track = new MediaTrack();
Add(track, mi.GetAudio(i, "Language/String"));
Add(track, mi.GetAudio(i, "Format"));
Add(track, mi.GetAudio(i, "Format_Profile"));
Add(track, mi.GetAudio(i, "BitRate/String"));
Add(track, mi.GetAudio(i, "Channel(s)/String"));
Add(track, mi.GetAudio(i, "SamplingRate/String"));
Add(track, mi.GetAudio(i, "Forced") == "Yes" ? "Forced" : "");
Add(track, mi.GetAudio(i, "Default") == "Yes" ? "Default" : "");
Add(track, mi.GetAudio(i, "Title"));
track.Text = "A: " + track.Text.Trim(' ', ',');
track.Type = "a";
track.ID = i + 1;
tracks.Add(track);
}
for (int i = 0; i < videoCount; i++)
{
MediaTrack track = new MediaTrack();
Add(track, mi.GetVideo(i, "Format"));
Add(track, mi.GetVideo(i, "Format_Profile"));
Add(track, mi.GetVideo(i, "Width") + "x" + mi.GetVideo(i, "Height"));
Add(track, mi.GetVideo(i, "FrameRate") + " FPS");
Add(track, mi.GetVideo(i, "Language/String"));
Add(track, mi.GetVideo(i, "Forced") == "Yes" ? "Forced" : "");
Add(track, mi.GetVideo(i, "Default") == "Yes" ? "Default" : "");
Add(track, mi.GetVideo(i, "Title"));
track.Text = "V: " + track.Text.Trim(' ', ',');
track.Type = "v";
track.ID = i + 1;
MediaTracks.Add(track);
}
int subCount = mi.GetCount(MediaInfoStreamKind.Text);
int audioCount = mi.GetCount(MediaInfoStreamKind.Audio);
for (int i = 0; i < audioCount; i++)
{
MediaTrack track = new MediaTrack();
Add(track, mi.GetAudio(i, "Language/String"));
Add(track, mi.GetAudio(i, "Format"));
Add(track, mi.GetAudio(i, "Format_Profile"));
Add(track, mi.GetAudio(i, "BitRate/String"));
Add(track, mi.GetAudio(i, "Channel(s)/String"));
Add(track, mi.GetAudio(i, "SamplingRate/String"));
Add(track, mi.GetAudio(i, "Forced") == "Yes" ? "Forced" : "");
Add(track, mi.GetAudio(i, "Default") == "Yes" ? "Default" : "");
Add(track, mi.GetAudio(i, "Title"));
track.Text = "A: " + track.Text.Trim(' ', ',');
track.Type = "a";
track.ID = i + 1;
MediaTracks.Add(track);
}
int subCount = mi.GetCount(MediaInfoStreamKind.Text);
for (int i = 0; i < subCount; i++)
{
MediaTrack track = new MediaTrack();
Add(track, mi.GetText(i, "Language/String"));
Add(track, mi.GetText(i, "Format"));
Add(track, mi.GetText(i, "Format_Profile"));
Add(track, mi.GetText(i, "Forced") == "Yes" ? "Forced" : "");
Add(track, mi.GetText(i, "Default") == "Yes" ? "Default" : "");
Add(track, mi.GetText(i, "Title"));
track.Text = "S: " + track.Text.Trim(' ', ',');
track.Type = "s";
track.ID = i + 1;
MediaTracks.Add(track);
}
int editionCount = GetPropertyInt("edition-list/count");
for (int i = 0; i < editionCount; i++)
{
string title = GetPropertyString($"edition-list/{i}/title");
if (string.IsNullOrEmpty(title))
title = "Edition " + i;
MediaTrack track = new MediaTrack();
track.Text = "E: " + title;
track.Type = "e";
track.ID = i;
MediaTracks.Add(track);
}
}
for (int i = 0; i < subCount; i++)
{
MediaTrack track = new MediaTrack();
Add(track, mi.GetText(i, "Language/String"));
Add(track, mi.GetText(i, "Format"));
Add(track, mi.GetText(i, "Format_Profile"));
Add(track, mi.GetText(i, "Forced") == "Yes" ? "Forced" : "");
Add(track, mi.GetText(i, "Default") == "Yes" ? "Default" : "");
Add(track, mi.GetText(i, "Title"));
track.Text = "S: " + track.Text.Trim(' ', ',');
track.Type = "s";
track.ID = i + 1;
tracks.Add(track);
}
}
lock (Chapters)
int editionCount = GetPropertyInt("edition-list/count");
for (int i = 0; i < editionCount; i++)
{
Chapters.Clear();
int count = GetPropertyInt("chapter-list/count");
for (int x = 0; x < count; x++)
{
string text = GetPropertyString($"chapter-list/{x}/title");
double time = GetPropertyDouble($"chapter-list/{x}/time");
if (string.IsNullOrEmpty(text))
text = "Chapter " + (x + 1);
Chapters.Add(new KeyValuePair<string, double>(text, time));
}
string title = GetPropertyString($"edition-list/{i}/title");
if (string.IsNullOrEmpty(title))
title = "Edition " + i;
MediaTrack track = new MediaTrack();
track.Text = "E: " + title;
track.Type = "e";
track.ID = i;
tracks.Add(track);
}
return tracks;
}
void Add(MediaTrack track, object value)