Browse Source

add support m3u(8)

Coder 8 months atrás
parent
commit
7d73bf75ff
2 changed files with 19 additions and 12 deletions
  1. 12 10
      Bmp.Core/Playback/Inputs/InputSourceProvider.cs
  2. 7 2
      Bmp.WinForms/MainForm.cs

+ 12 - 10
Bmp.Core/Playback/Inputs/InputSourceProvider.cs

@@ -111,24 +111,28 @@ namespace Bmp.Core.Playback.Inputs
         {
             // TODO: InputSourceProvider::ExpandPath M3U(8) ISO ZIP RAR 7Z / InURL 
             // TODO: InputSourceProvider::ExpandPath EventBus for warn and err
-            // [http://]foo.bar/foo.zip?path/to/inner/01.flac
+            // [http[s]://foo.bar/]foo.zip?#path/to/inner/01.flac
 
             var (exists, size) = FileCheckSize(inputPath);
             if (exists)
             {
                 var ex = Path.GetExtension(inputPath).ToLower();
                 using var stream = ReadContentAsSeekableStream(inputPath);
+
                 // ------------ m3u/8 ------------
-                if (size.HasValue && size < 1024 * 1025 * 1) // < 1MB
+                if (size.HasValue && size > 1024 * 1024)
+                {
+                    // > 1MB may not playlist, skip
+                }
+                else
                 {
                     const string sign_ExtM3u = "#EXTM3U";
                     if (Encoding.ASCII.GetString(stream.ReadBytes(sign_ExtM3u.Length)) == sign_ExtM3u)
                     {
                         stream.Position = 0;
                         var lines = stream.ReadLines(ex == ".m3u8" ? Encoding.UTF8 : null);
-                        return lines.Where(p => p.StartsWith("#")).ToArray();
+                        return lines.Where(p => p.StartsWith("#") == false).ToArray();
                     }
-                    //TODO: Debug here
                 }
 
             }
@@ -178,13 +182,11 @@ namespace Bmp.Core.Playback.Inputs
             else
             {
                 using var client = new HttpClient();
-                var request = new HttpRequestMessage(HttpMethod.Head, urlOrPath);
-                var response = client.Send(request);
+                // use GET instead of HEAD for compatible
+                using var request = new HttpRequestMessage(HttpMethod.Get, urlOrPath);
+                using var response = client.Send(request, HttpCompletionOption.ResponseHeadersRead);
                 exists = response.IsSuccessStatusCode;
-                if (exists && response.Content.Headers.ContentLength.HasValue)
-                {
-                    size = response.Content.Headers.ContentLength.Value;
-                }
+                if (exists && response.Content.Headers.ContentLength.HasValue) size = response.Content.Headers.ContentLength.Value;
             }
 
             return (exists, size);

+ 7 - 2
Bmp.WinForms/MainForm.cs

@@ -468,8 +468,13 @@ namespace Bmp.WinForms
                     var item = new ListViewItem();
                     item.Name = path;
 
-                    item.Text = Path.GetFileName(path);
-                    if (string.IsNullOrWhiteSpace(item.Text)) item.Text = path;
+                    var localVarPath = path;
+                    if (Uri.TryCreate(path, UriKind.RelativeOrAbsolute, out var uri) && uri.IsFile==false) localVarPath = uri.ToString();
+
+                    item.ToolTipText = localVarPath;
+
+                    item.Text = Path.GetFileName(localVarPath);
+                    if (string.IsNullOrWhiteSpace(item.Text)) item.Text = localVarPath;
 
                     for (var i = 0; i < MainListView.Columns.Count - 1; i++) item.SubItems.Add("");