This commit is contained in:
Frank Skare
2019-03-21 18:30:10 +01:00
parent fc3dd45b72
commit 4366c47a09
9 changed files with 189 additions and 164 deletions

View File

@@ -65,20 +65,8 @@ namespace mpvnet
Process.Start(mp.InputConfPath);
}
private static void CreateMpvConf()
{
if (!File.Exists(mp.mpvConfPath))
{
if (!Directory.Exists(mp.mpvConfFolderPath))
Directory.CreateDirectory(mp.mpvConfFolderPath);
File.WriteAllText(mp.mpvConfPath, "# https://mpv.io/manual/master/#configuration-files");
}
}
public static void show_prefs(string[] args)
{
CreateMpvConf();
Process.Start(mp.mpvConfPath);
}
@@ -89,7 +77,7 @@ namespace mpvnet
if (File.Exists(fp))
Process.Start(fp);
else
if (MsgQuestion("Create history.txt file in config folder?\r\n\r\nmpv.net will write the date, time and filename of opened files to it.") == DialogResult.OK)
if (MsgQuestion("Create history.txt file in config folder?\n\nmpv.net will write the date, time and filename of opened files to it.") == DialogResult.OK)
File.WriteAllText(fp, "");
}
@@ -100,8 +88,6 @@ namespace mpvnet
public static void set_setting(string[] args)
{
CreateMpvConf();
bool changed = false;
string fp = mp.mpvConfPath;
var confLines = File.ReadAllLines(fp);
@@ -116,51 +102,67 @@ namespace mpvnet
}
if (changed)
{
File.WriteAllText(fp, String.Join(Environment.NewLine, confLines));
}
else
{
File.WriteAllText(fp,
File.ReadAllText(fp) + Environment.NewLine + args[0] + "=" + args[1]);
}
File.WriteAllText(fp, File.ReadAllText(fp) + Environment.NewLine + args[0] + "=" + args[1]);
MsgInfo("Please restart mpv.net");
}
public static void show_info(string[] args)
{
var fi = new FileInfo(mp.GetStringProp("path"));
var fileInfo = new FileInfo(mp.get_property_string("path"));
using (var mi = new MediaInfo(fi.FullName))
using (var mediaInfo = new MediaInfo(fileInfo.FullName))
{
var w = mi.GetInfo(MediaInfoStreamKind.Video, "Width");
var h = mi.GetInfo(MediaInfoStreamKind.Video, "Height");
var pos = TimeSpan.FromSeconds(mp.GetIntProp("time-pos"));
var dur = TimeSpan.FromSeconds(mp.GetIntProp("duration"));
string mibr = mi.GetInfo(MediaInfoStreamKind.Video, "BitRate");
string width = mediaInfo.GetInfo(MediaInfoStreamKind.Video, "Width");
if (mibr == "")
mibr = "0";
if (width == "")
{
string performer = mediaInfo.GetInfo(MediaInfoStreamKind.General, "Performer");
string title = mediaInfo.GetInfo(MediaInfoStreamKind.General, "Title");
string album = mediaInfo.GetInfo(MediaInfoStreamKind.General, "Album");
string genre = mediaInfo.GetInfo(MediaInfoStreamKind.General, "Genre");
string date = mediaInfo.GetInfo(MediaInfoStreamKind.General, "Recorded_Date");
string duration = mediaInfo.GetInfo(MediaInfoStreamKind.Audio, "Duration/String");
var br = Convert.ToInt32(mibr) / 1000.0 / 1000.0;
var vf = mp.GetStringProp("video-format").ToUpper();
var fn = fi.Name;
string text = "";
if (fn.Length > 60)
fn = fn.Insert(59, "\r\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";
var info =
FormatTime(pos.TotalMinutes) + ":" +
FormatTime(pos.Seconds) + " / " +
FormatTime(dur.TotalMinutes) + ":" +
FormatTime(dur.Seconds) + "\n" +
((int)(fi.Length / 1024 / 1024)).ToString() +
$" MB - {w} x {h}\n{vf} - {br.ToString("f1")} Mb/s" + "\n" + fn;
mp.commandv("show-text", text, "5000");
}
else
{
string height = mediaInfo.GetInfo(MediaInfoStreamKind.Video, "Height");
TimeSpan position = TimeSpan.FromSeconds(mp.get_property_number("time-pos"));
TimeSpan duration = TimeSpan.FromSeconds(mp.get_property_number("duration"));
string bitrate = mediaInfo.GetInfo(MediaInfoStreamKind.Video, "BitRate");
mp.Command("show-text", info, "5000");
if (bitrate == "")
bitrate = "0";
string FormatTime(double value) => ((int)(Math.Floor(value))).ToString("00");
var bitrate2 = Convert.ToDouble(bitrate) / 1000.0 / 1000.0;
var format = mp.get_property_string("video-format").ToUpper();
var filename = fileInfo.Name;
var text =
FormatTime(position.TotalMinutes) + ":" +
FormatTime(position.Seconds) + " / " +
FormatTime(duration.TotalMinutes) + ":" +
FormatTime(duration.Seconds) + "\n" +
Convert.ToInt32(fileInfo.Length / 1024 / 1024).ToString() +
$" MB - {width} x {height}\n{format} - {bitrate2.ToString("f1")} Mb/s" + "\n" + filename;
mp.commandv("show-text", text, "5000");
}
string FormatTime(double value) => ((int)value).ToString("00");
}
}
}