Browse Source

Host: update taglib package and collect more field of meta; show bit and freq in file icon

HOME 2 years ago
parent
commit
08be6eeb73

+ 29 - 14
FNZCM/FNZCM.BlazorWasm/Helpers/FnzDataSetHelper.cs

@@ -4,6 +4,7 @@ using FNZCM.BlazorWasm.Utility;
 using FNZCM.Shared.Helpers;
 using FNZCM.Shared.MediaModels;
 using Newtonsoft.Json;
+using System.Text;
 
 namespace FNZCM.BlazorWasm.Helpers
 {
@@ -114,13 +115,7 @@ namespace FNZCM.BlazorWasm.Helpers
                                 Key = t.Key,
                                 Name = t.Value,
                                 Path = $"{apiBase}media/{lib.Key.UrlEscape()}/{disc.Key.UrlEscape()}/{t.Key.UrlEscape()}",
-                                Tag = mediaTag != null ? new FeMediaTag
-                                {
-                                    Title = mediaTag.Title,
-                                    Artist = mediaTag.Artist,
-                                    Duration = mediaTag.Duration,
-                                    Length = mediaTag.Length,
-                                } : null
+                                Tag = MappingTag(mediaTag)
                             };
                             lstAllTrack.Add(fet);
 
@@ -168,13 +163,7 @@ namespace FNZCM.BlazorWasm.Helpers
                                     Key = t.Key,
                                     Name = t.Value,
                                     Path = $"{apiBase}media/{lib.Key.UrlEscape()}/{disc.Key.UrlEscape()}/{tSubSet.Key.UrlEscape()}/{t.Key.UrlEscape()}",
-                                    Tag = mediaTag != null ? new FeMediaTag
-                                    {
-                                        Title = mediaTag.Title,
-                                        Artist = mediaTag.Artist,
-                                        Duration = mediaTag.Duration,
-                                        Length = mediaTag.Length,
-                                    } : null
+                                    Tag = MappingTag(mediaTag)
                                 };
                                 lstAllTrack.Add(fet);
                                 lstTracksOfTsSub.Add(fet);
@@ -225,5 +214,31 @@ namespace FNZCM.BlazorWasm.Helpers
             dataSet.AllDisc = lstAllDisc.ToArray();
             dataSet.AllLibrary = lstAllLibrry.ToArray();
         }
+
+        private static FeMediaTag MappingTag(MediaTag mediaTag)
+        {
+            if (mediaTag == null) return null;
+
+            var m = new FeMediaTag
+            {
+                Album = mediaTag.Album,
+                DiscNum = mediaTag.DiscNum,
+                TrackNum = mediaTag.DiscNum,
+                Title = mediaTag.Title,
+                Artist = mediaTag.Artist,
+                Duration = mediaTag.Duration,
+                Length = mediaTag.Length,
+                Bit = mediaTag.Bit,
+                Freq = mediaTag.Freq,
+            };
+
+            var lst = new List<string>();
+            if (m.Bit != 0) lst.Add($"{m.Bit}b");
+            if (m.Freq != 0) lst.Add($"{m.Freq / 100f}");
+
+            m.ParamDesc = string.Join("", lst);
+
+            return m;
+        }
     }
 }

+ 9 - 1
FNZCM/FNZCM.BlazorWasm/Models/FeMediaTag.cs

@@ -2,9 +2,17 @@
 {
     public class FeMediaTag
     {
+        public string Album { get; set; }
+        public int DiscNum { get; set; }
+        public int TrackNum { get; set; }
         public string Title { get; set; }
+        public string Artist { get; set; }
         public int Duration { get; set; }
         public long Length { get; set; }
-        public string Artist { get; set; }
+
+        public int Bit { get; set; }
+        public int Freq { get; set; }
+
+        public string ParamDesc { get; set; }
     }
 }

+ 1 - 1
FNZCM/FNZCM.BlazorWasm/UI/Components/DiscDialogTrackSetTable.razor

@@ -25,7 +25,7 @@
             {
                 <tr class="@(t.index%2==0?"":"table-primary") mouse-hilight">
                     <td scope="col" class="p-1 text-center">
-                        <FileIcon FileName="@t.item?.Key"></FileIcon>
+                        <FileIcon Track="@t.item"></FileIcon>
                     </td>
                     <td scope="row" class="p-0 text-nowrap">
                         <a href="@t.item?.Path" target="@FnzConst.PlayPageTarget">@t.item?.GetTitleOrFilename()</a>

+ 8 - 3
FNZCM/FNZCM.BlazorWasm/UI/Components/FileIcon.razor

@@ -1,11 +1,12 @@
 @code {
-    [Parameter, Required] public string FileName { get; set; }
+    [Parameter, Required] public FeTrack Track { get; set; }
+    [Parameter] public bool ShowParam { get; set; }
 }
 
 
-@if (FileName != null)
+@if (Track != null)
 {
-    var ex = Path.GetExtension(FileName?.ToLower());
+    var ex = Path.GetExtension(Track.Path?.ToLower());
     <span class="badge bg-secondary">
         @switch (ex)
         {
@@ -30,5 +31,9 @@
                 break;
         }
         @ex.Substring(1).ToUpper()
+        @if (ShowParam && Track.Tag?.ParamDesc != null)
+        {
+            <br>@Track.Tag.ParamDesc
+        }
     </span>
 }

+ 5 - 5
FNZCM/FNZCM.BlazorWasm/UI/Views/Default/Playlist/PlaylistTableItem.razor

@@ -29,7 +29,7 @@
                             }
                         </button>
                     </td>
-                    <td class="text-left w-100 align-middle" @onclick="()=>{IsExpand=!IsExpand;}" colspan="2">
+                    <td class="text-left w-100 align-middle" @onclick="()=>{IsExpand=!IsExpand;}" colspan="3">
                         <div class="text-nowrap">@Playlist.Value.Value</div>
                         <div class="text-nowrap text-muted">
                             (@arr.Count)
@@ -67,11 +67,11 @@
                                     <td colspan="2" style="width:0">
                                         <img src="@track.Disc.CoverPath" style="height:50px" />
                                     </td>
+                                    <td class="align-middle">
+                                        <FileIcon Track="@track" ShowParam="true"></FileIcon>
+                                    </td>
                                     <td class="align-middle w-100">
-                                        <div class="text-nowrap">
-                                            <FileIcon FileName="@track.Name"></FileIcon>
-                                            @track.GetTitleOrFilename()
-                                        </div>
+                                        <div class="text-nowrap">@track.GetTitleOrFilename()</div>
                                         <div class="text-nowrap text-muted"> @track.Tag?.Artist</div>
                                     </td>
                                     <td class="text-center" colspan="2">

+ 1 - 1
FNZCM/FNZCM.BlazorWasm/UI/Views/Default/Search/SearchView.razor

@@ -122,7 +122,7 @@
                                 @foreach (var tr in item.OrderBy(p => p.Name))
                                 {
                                     <tr class="mouse-hilight">
-                                        <td><FileIcon FileName="@tr.Key"></FileIcon></td>
+                                        <td class="align-middle"><FileIcon Track="@tr" ShowParam="true"></FileIcon></td>
                                         <td class="w-100 text-nowrap">
                                             <div>
                                                 <a href="@tr.Path" target="@FnzConst.PlayPageTarget">

+ 1 - 1
FNZCM/FNZCM.ConHost/FNZCM.ConHost.csproj

@@ -10,7 +10,7 @@
     <PackageReference Include="K4os.Compression.LZ4" Version="1.2.16" />
     <PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
     <PackageReference Include="SharpCompress" Version="0.32.2" />
-    <PackageReference Include="taglib-sharp-netstandard2.0" Version="2.1.0" />
+    <PackageReference Include="TagLibSharp" Version="2.3.0" />
   </ItemGroup>
 
   <ItemGroup>

+ 10 - 5
FNZCM/FNZCM.ConHost/HostProgram.cs

@@ -1253,12 +1253,17 @@ namespace FNZCM.ConHost
             try
             {
                 var fi = new FileInfo(mediaFilePath);
-                using var tagLib = TagLib.File.Create(mediaFilePath);
+                using var tagLib = TagLib.File.Create(mediaFilePath, TagLib.ReadStyle.Average);
                 mediaTag = MediaTags[internalPath] = new MediaTag(
-                    $"{tagLib.Tag.Title}",
-                    (int)tagLib.Properties.Duration.TotalSeconds,
-                    fi.Length,
-                    string.Join(";", tagLib.Tag.Performers)
+                    tagLib.Tag.Album,
+                    (int)tagLib.Tag.Disc,
+                    (int)tagLib.Tag.Track,
+                    tagLib.Tag.Title,
+                    string.Join(";", tagLib.Tag.Performers??new string[0]),
+                    tagLib.Properties?.BitsPerSample ?? 0,
+                    tagLib.Properties?.AudioSampleRate ?? 0,
+                    (int)(tagLib.Properties?.Duration.TotalSeconds ?? 0),
+                    fi.Length
                 );
             }
             catch (Exception e)

+ 1 - 1
FNZCM/FNZCM.Core/config.json

@@ -8,7 +8,7 @@
   "Title": "FNZ Cloud Music",
   "AdminPassword": "",
   "Libraries": {
-    //"A_Featured": "X:/音乐库/F_Temp"
+    "E_Videos": "X:/音乐库/E_Videos"
   },
   "MediaFilePattern": [
     "*.flac",

+ 12 - 2
FNZCM/FNZCM.Shared/MediaModels/MediaTag.cs

@@ -2,17 +2,27 @@
 {
     public class MediaTag
     {
-        public MediaTag(string title, int duration, long length, string artist)
+        public MediaTag(string album,int discNum,int trackNum, string title, string artist,int bit,int freq, int duration, long length)
         {
+            Album = album;
+            DiscNum = discNum;
+            TrackNum = trackNum;
             Title = title;
             Duration = duration;
             Length = length;
             Artist = artist;
+            Bit = bit;
+            Freq = freq;
         }
 
+        public string Album { get; }
+        public int DiscNum { get; }
+        public int TrackNum { get; }
         public string Title { get; }
+        public string Artist { get; }
+        public int Bit { get; }
+        public int Freq { get; }
         public int Duration { get; }
         public long Length { get; }
-        public string Artist { get; }
     }
 }