Browse Source

add error handle

HOME 1 year ago
parent
commit
e403fa67ce
1 changed files with 18 additions and 12 deletions
  1. 18 12
      FNZCM/FNZCM.ConHost/Ver2/Program2.cs

+ 18 - 12
FNZCM/FNZCM.ConHost/Ver2/Program2.cs

@@ -1,16 +1,14 @@
-using Microsoft.VisualBasic.FileIO;
+using FNZCM.Core;
+using Microsoft.VisualBasic.FileIO;
 using System;
 using System.Collections.Concurrent;
 using System.Collections.Generic;
-using System.Dynamic;
 using System.IO;
 using System.Linq;
 using System.Net;
-using System.Reflection.Emit;
 using System.Text;
 using System.Threading;
 using System.Threading.Tasks;
-using FNZCM.Core;
 using SearchOption = Microsoft.VisualBasic.FileIO.SearchOption;
 
 namespace FNZCM.ConHost.Ver2
@@ -103,7 +101,7 @@ namespace FNZCM.ConHost.Ver2
 
                                 PathMapping[$"/media/{libPath}/{discPath}/{trackPath}"] = mainTrackFile;
                             }
-                            
+
                             if (Directory.Exists(bkDir))
                             {
                                 var bkFiles = FileSystem.GetFiles(bkDir, SearchOption.SearchTopLevelOnly, ConfigFile.Instance.BkFilePattern);
@@ -822,13 +820,21 @@ namespace FNZCM.ConHost.Ver2
             {
                 if (false == MediaTags.TryGetValue(internalPath, out var mediaTag) && PathMapping.TryGetValue(internalPath, out var mediaFilePath))
                 {
-                    var fi = new FileInfo(mediaFilePath);
-                    using var tagLib = TagLib.File.Create(mediaFilePath);
-                    mediaTag = MediaTags[internalPath] = new MediaTag2(
-                        $"{string.Join(";", tagLib.Tag.Performers)} - {tagLib.Tag.Title}",
-                        (int)tagLib.Properties.Duration.TotalSeconds,
-                        fi.Length
-                    );
+                    try
+                    {
+                        var fi = new FileInfo(mediaFilePath);
+                        using var tagLib = TagLib.File.Create(mediaFilePath);
+                        mediaTag = MediaTags[internalPath] = new MediaTag2(
+                            $"{string.Join(";", tagLib.Tag.Performers)} - {tagLib.Tag.Title}",
+                            (int)tagLib.Properties.Duration.TotalSeconds,
+                            fi.Length
+                        );
+                    }
+                    catch (Exception e)
+                    {
+                        Console.WriteLine($"ERROR on lookup tags: {mediaFilePath}{Environment.NewLine}  {e.Message}");
+                        return null;
+                    }
                 }
 
                 return mediaTag;