From d6b262127d9723b51c639387303f5e0373f1c6a8 Mon Sep 17 00:00:00 2001 From: datasone Date: Sat, 12 Mar 2022 18:40:12 +0800 Subject: [PATCH] Fix not working with web link Change media type to be inferred by lua script, small changes to protocol --- MPVMediaControl/MediaController.cs | 39 ++---------- MPVMediaControl/PipeServer.cs | 97 ++++++++++-------------------- notify_media.lua | 14 ++++- 3 files changed, 47 insertions(+), 103 deletions(-) diff --git a/MPVMediaControl/MediaController.cs b/MPVMediaControl/MediaController.cs index 4a09727..8160275 100644 --- a/MPVMediaControl/MediaController.cs +++ b/MPVMediaControl/MediaController.cs @@ -23,39 +23,7 @@ public class MCMediaFile public string Artist; public string Path; public string ShotPath; - - private static readonly string[] AudioFormats = - { - "m4a", "wma", "aac", "adt", "adts", "mp3", "wav", "ac3", "ec3", "flac", "ape", "tta", "tak", "ogg", - "opus", - }; - - private static readonly string[] VideoFormats = - { - "3g2", "3gp2", "3gp", "3gpp", "m4v", "mp4v", "mp4", "mov", "m2ts", "asf", "wmv", "avi", "mkv", - }; - - private static readonly string[] ImageFormats = - { - "tif", "tiff", "png", "jpg", "gif" - }; - - public MediaPlaybackType Type() - { - var fileName = Path.Split('\\').Last(); - if (fileName.Split('.').Length == 1) - return MediaPlaybackType.Unknown; - - var extName = fileName.Split('.').Last(); - if (AudioFormats.Contains(extName)) - return MediaPlaybackType.Music; - if (VideoFormats.Contains(extName)) - return MediaPlaybackType.Video; - if (ImageFormats.Contains(extName)) - return MediaPlaybackType.Image; - - return MediaPlaybackType.Unknown; - } + public MediaPlaybackType Type; public bool ThumbnailObtained = false; @@ -101,12 +69,13 @@ public MCMediaFile File _file.ThumbnailObtained = false; _file.Path = value.Path; _file.ShotPath = value.ShotPath.Replace('/', '\\'); + _file.Type = value.Type; _updater.ClearAll(); - _updater.Type = _file.Type(); + _updater.Type = _file.Type; - switch (_file.Type()) + switch (_file.Type) { case MediaPlaybackType.Image: _updater.ImageProperties.Title = _file.Title; diff --git a/MPVMediaControl/PipeServer.cs b/MPVMediaControl/PipeServer.cs index 2fa097a..10ee698 100644 --- a/MPVMediaControl/PipeServer.cs +++ b/MPVMediaControl/PipeServer.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Text; using System.Threading; +using Windows.Media; namespace MPVMediaControl { @@ -86,48 +87,6 @@ private static void ServerThread(object data) } } - private static string ParseEDL(string edlFilePath) - { - // Only select first file as syncing play time to decide file is too much for thumbnail generation. - var content = File.ReadAllLines(edlFilePath); - foreach (var line in content) - { - if (line.StartsWith("#")) continue; - if (line.StartsWith("%")) - { - var byteLenStr = line.Split('%')[1]; - var success = int.TryParse(byteLenStr, out var byteLength); - if (!success) - continue; - var restPart = line.Substring(2 + byteLenStr.Length); - var restPartInBytes = Encoding.UTF8.GetBytes(restPart); - var fileNameInBytes = restPartInBytes.Take(byteLength).ToArray(); - return Encoding.UTF8.GetString(fileNameInBytes); - } - else - { - return line.Split(',')[0]; - } - } - - return ""; - } - - private static string ParseCUE(string cueFilePath) - { - var parentPath = cueFilePath.Substring(0, cueFilePath.LastIndexOf(Path.DirectorySeparatorChar) + 1); - var content = File.ReadAllLines(cueFilePath); - foreach (var line in content) - { - if (!line.StartsWith("FILE")) continue; - var prefixLen = 6; // "FILE \"" - var suffixLen = line.Split('"').Last().Length + 1; - return parentPath + line.Substring(prefixLen, line.Length - prefixLen - suffixLen); - } - - return ""; - } - private static string FromHexString(string hexString) { var bytes = new byte[hexString.Length / 2]; @@ -143,8 +102,26 @@ private static void ParseFile(MediaController controller, Dictionary 1 then + return "video" + else + return "music" + end +end + +function notify_metadata_updated() metadata = mp.get_property_native("metadata") debug_log(metadata) if not metadata then @@ -132,7 +142,7 @@ function notify_current_file() shot_path = user_path .. "\\" .. pid .. ".jpg" save_shot(shot_path) - message_content = "^[setFile](pid=" .. pid .. ")(title=" .. title .. ")(artist=" .. artist .. ")(path=" .. path .. ")$" + message_content = "^[setFile](pid=" .. pid .. ")(title=" .. title .. ")(artist=" .. artist .. ")(path=" .. path .. ")(type=" .. media_type() .. ")$" write_to_socket(message_content) end