Browse Source

Code cleanups. Remove pragma commands

1hitsong 2 years ago
parent
commit
c65819221d

+ 18 - 18
MediaBrowser.Controller/Lyrics/ILyricManager.cs

@@ -1,23 +1,23 @@
-#pragma warning disable CS1591
-
 using MediaBrowser.Controller.Entities;
 using MediaBrowser.Controller.Entities;
 
 
-namespace MediaBrowser.Controller.Lyrics
+namespace MediaBrowser.Controller.Lyrics;
+
+/// <summary>
+/// Interface ILyricManager.
+/// </summary>
+public interface ILyricManager
 {
 {
-    public interface ILyricManager
-    {
-        /// <summary>
-        /// Gets the lyrics.
-        /// </summary>
-        /// <param name="item">The media item.</param>
-        /// <returns>Lyrics for passed item.</returns>
-        LyricResponse GetLyrics(BaseItem item);
+    /// <summary>
+    /// Gets the lyrics.
+    /// </summary>
+    /// <param name="item">The media item.</param>
+    /// <returns>Lyrics for passed item.</returns>
+    LyricResponse GetLyrics(BaseItem item);
 
 
-        /// <summary>
-        /// Checks if requested item has a matching local lyric file.
-        /// </summary>
-        /// <param name="item">The media item.</param>
-        /// <returns>True if item has a matching lyric file; otherwise false.</returns>
-        bool HasLyricFile(BaseItem item);
-    }
+    /// <summary>
+    /// Checks if requested item has a matching local lyric file.
+    /// </summary>
+    /// <param name="item">The media item.</param>
+    /// <returns>True if item has a matching lyric file; otherwise false.</returns>
+    bool HasLyricFile(BaseItem item);
 }
 }

+ 19 - 20
MediaBrowser.Controller/Lyrics/ILyricProvider.cs

@@ -1,29 +1,28 @@
 using System.Collections.Generic;
 using System.Collections.Generic;
 using MediaBrowser.Controller.Entities;
 using MediaBrowser.Controller.Entities;
 
 
-namespace MediaBrowser.Controller.Lyrics
+namespace MediaBrowser.Controller.Lyrics;
+
+/// <summary>
+/// Interface ILyricsProvider.
+/// </summary>
+public interface ILyricProvider
 {
 {
     /// <summary>
     /// <summary>
-    /// Interface ILyricsProvider.
+    /// Gets a value indicating the provider name.
     /// </summary>
     /// </summary>
-    public interface ILyricProvider
-    {
-        /// <summary>
-        /// Gets a value indicating the provider name.
-        /// </summary>
-        string Name { get; }
+    string Name { get; }
 
 
-        /// <summary>
-        /// Gets the supported media types for this provider.
-        /// </summary>
-        /// <value>The supported media types.</value>
-        IEnumerable<string> SupportedMediaTypes { get; }
+    /// <summary>
+    /// Gets the supported media types for this provider.
+    /// </summary>
+    /// <value>The supported media types.</value>
+    IEnumerable<string> SupportedMediaTypes { get; }
 
 
-        /// <summary>
-        /// Gets the lyrics.
-        /// </summary>
-        /// <param name="item">The media item.</param>
-        /// <returns>If found, returns lyrics for passed item; otherwise, null.</returns>
-        LyricResponse? GetLyrics(BaseItem item);
-    }
+    /// <summary>
+    /// Gets the lyrics.
+    /// </summary>
+    /// <param name="item">The media item.</param>
+    /// <returns>If found, returns lyrics for passed item; otherwise, null.</returns>
+    LyricResponse? GetLyrics(BaseItem item);
 }
 }

+ 22 - 12
MediaBrowser.Controller/Lyrics/Lyric.cs

@@ -1,18 +1,28 @@
-namespace MediaBrowser.Controller.Lyrics
+namespace MediaBrowser.Controller.Lyrics;
+
+/// <summary>
+/// Lyric model.
+/// </summary>
+public class Lyric
 {
 {
     /// <summary>
     /// <summary>
-    /// Lyric model.
+    /// Initializes a new instance of the <see cref="Lyric"/> class.
     /// </summary>
     /// </summary>
-    public class Lyric
+    /// <param name="start">The lyric start time in ticks.</param>
+    /// <param name="text">The lyric text.</param>
+    public Lyric(string text, long? start = null)
     {
     {
-        /// <summary>
-        /// Gets or sets the start time in ticks.
-        /// </summary>
-        public long? Start { get; set; }
-
-        /// <summary>
-        /// Gets or sets the text.
-        /// </summary>
-        public string Text { get; set; } = string.Empty;
+        Start = start;
+        Text = text;
     }
     }
+
+    /// <summary>
+    /// Gets the start time in ticks.
+    /// </summary>
+    public long? Start { get; }
+
+    /// <summary>
+    /// Gets the text.
+    /// </summary>
+    public string Text { get; }
 }
 }

+ 17 - 22
MediaBrowser.Controller/Lyrics/LyricInfo.cs

@@ -1,34 +1,29 @@
 using System.IO;
 using System.IO;
-using System.Linq;
 
 
-namespace MediaBrowser.Controller.Lyrics
+namespace MediaBrowser.Controller.Lyrics;
+
+/// <summary>
+/// Lyric helper methods.
+/// </summary>
+public static class LyricInfo
 {
 {
     /// <summary>
     /// <summary>
-    /// Lyric helper methods.
+    /// Gets matching lyric file for a requested item.
     /// </summary>
     /// </summary>
-    public static class LyricInfo
+    /// <param name="lyricProvider">The lyricProvider interface to use.</param>
+    /// <param name="itemPath">Path of requested item.</param>
+    /// <returns>Lyric file path if passed lyric provider's supported media type is found; otherwise, null.</returns>
+    public static string? GetLyricFilePath(ILyricProvider lyricProvider, string itemPath)
     {
     {
-        /// <summary>
-        /// Gets matching lyric file for a requested item.
-        /// </summary>
-        /// <param name="lyricProvider">The lyricProvider interface to use.</param>
-        /// <param name="itemPath">Path of requested item.</param>
-        /// <returns>Lyric file path if passed lyric provider's supported media type is found; otherwise, null.</returns>
-        public static string? GetLyricFilePath(ILyricProvider lyricProvider, string itemPath)
+        foreach (string lyricFileExtension in lyricProvider.SupportedMediaTypes)
         {
         {
-            if (lyricProvider.SupportedMediaTypes.Any())
+            var lyricFilePath = Path.ChangeExtension(itemPath, lyricFileExtension);
+            if (File.Exists(lyricFilePath))
             {
             {
-                foreach (string lyricFileExtension in lyricProvider.SupportedMediaTypes)
-                {
-                    string lyricFilePath = @Path.ChangeExtension(itemPath, lyricFileExtension);
-                    if (System.IO.File.Exists(lyricFilePath))
-                    {
-                        return lyricFilePath;
-                    }
-                }
+                return lyricFilePath;
             }
             }
-
-            return null;
         }
         }
+
+        return null;
     }
     }
 }
 }

+ 12 - 15
MediaBrowser.Controller/Lyrics/LyricResponse.cs

@@ -1,22 +1,19 @@
-#nullable disable
-
 using System.Collections.Generic;
 using System.Collections.Generic;
 
 
-namespace MediaBrowser.Controller.Lyrics
+namespace MediaBrowser.Controller.Lyrics;
+
+/// <summary>
+/// LyricResponse model.
+/// </summary>
+public class LyricResponse
 {
 {
     /// <summary>
     /// <summary>
-    /// LyricResponse model.
+    /// Gets or sets Metadata.
     /// </summary>
     /// </summary>
-    public class LyricResponse
-    {
-        /// <summary>
-        /// Gets or sets Metadata.
-        /// </summary>
-        public IDictionary<string, string> Metadata { get; set; }
+    public IDictionary<string, string>? Metadata { get; set; }
 
 
-        /// <summary>
-        /// Gets or sets Lyrics.
-        /// </summary>
-        public IEnumerable<Lyric> Lyrics { get; set; }
-    }
+    /// <summary>
+    /// Gets or sets Lyrics.
+    /// </summary>
+    public IEnumerable<Lyric>? Lyrics { get; set; }
 }
 }

+ 71 - 81
MediaBrowser.Providers/Lyric/LrcLyricProvider.cs

@@ -1,112 +1,102 @@
 using System;
 using System;
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
 using System.Collections.ObjectModel;
-using System.Dynamic;
 using System.Globalization;
 using System.Globalization;
 using System.Linq;
 using System.Linq;
 using LrcParser.Model;
 using LrcParser.Model;
 using LrcParser.Parser;
 using LrcParser.Parser;
 using MediaBrowser.Controller.Entities;
 using MediaBrowser.Controller.Entities;
 using MediaBrowser.Controller.Lyrics;
 using MediaBrowser.Controller.Lyrics;
-using Swashbuckle.AspNetCore.SwaggerGen;
 
 
-namespace MediaBrowser.Providers.Lyric
+namespace MediaBrowser.Providers.Lyric;
+
+/// <summary>
+/// LRC Lyric Provider.
+/// </summary>
+public class LrcLyricProvider : ILyricProvider
 {
 {
-    /// <summary>
-    /// LRC Lyric Provider.
-    /// </summary>
-    public class LrcLyricProvider : ILyricProvider
-    {
-        /// <summary>
-        /// Initializes a new instance of the <see cref="LrcLyricProvider"/> class.
-        /// </summary>
-        public LrcLyricProvider()
-        {
-            Name = "LrcLyricProvider";
+    /// <inheritdoc />
+    public string Name { get; } = "LrcLyricProvider";
 
 
-            SupportedMediaTypes = new Collection<string>
+    /// <inheritdoc />
+    public IEnumerable<string> SupportedMediaTypes
+    {
+        get => new Collection<string>
             {
             {
                 "lrc"
                 "lrc"
             };
             };
-        }
+    }
 
 
-        /// <summary>
-        /// Gets a value indicating the provider name.
-        /// </summary>
-        public string Name { get; }
-
-        /// <summary>
-        /// Gets a value indicating the File Extenstions this provider supports.
-        /// </summary>
-        public IEnumerable<string> SupportedMediaTypes { get; }
-
-        /// <summary>
-        /// Opens lyric file for the requested item, and processes it for API return.
-        /// </summary>
-        /// <param name="item">The item to to process.</param>
-        /// <returns>If provider can determine lyrics, returns a <see cref="LyricResponse"/> with or without metadata; otherwise, null.</returns>
-        public LyricResponse? GetLyrics(BaseItem item)
-        {
-            string? lyricFilePath = LyricInfo.GetLyricFilePath(this, item.Path);
+    /// <summary>
+    /// Opens lyric file for the requested item, and processes it for API return.
+    /// </summary>
+    /// <param name="item">The item to to process.</param>
+    /// <returns>If provider can determine lyrics, returns a <see cref="LyricResponse"/> with or without metadata; otherwise, null.</returns>
+    public LyricResponse? GetLyrics(BaseItem item)
+    {
+        string? lyricFilePath = LyricInfo.GetLyricFilePath(this, item.Path);
 
 
-            if (string.IsNullOrEmpty(lyricFilePath))
-            {
-                return null;
-            }
+        if (string.IsNullOrEmpty(lyricFilePath))
+        {
+            return null;
+        }
 
 
-            List<Controller.Lyrics.Lyric> lyricList = new List<Controller.Lyrics.Lyric>();
-            List<LrcParser.Model.Lyric> sortedLyricData = new List<LrcParser.Model.Lyric>();
+        List<Controller.Lyrics.Lyric> lyricList = new List<Controller.Lyrics.Lyric>();
+        List<LrcParser.Model.Lyric> sortedLyricData = new List<LrcParser.Model.Lyric>();
 
 
-            IDictionary<string, string> metaData = new Dictionary<string, string>();
-            string lrcFileContent = System.IO.File.ReadAllText(lyricFilePath);
+        IDictionary<string, string> metaData = new Dictionary<string, string>();
+        string lrcFileContent = System.IO.File.ReadAllText(lyricFilePath);
 
 
-            try
+        try
+        {
+            // Parse and sort lyric rows
+            LyricParser lrcLyricParser = new LrcParser.Parser.Lrc.LrcParser();
+            Song lyricData = lrcLyricParser.Decode(lrcFileContent);
+            sortedLyricData = lyricData.Lyrics.Where(x => x.TimeTags.Count > 0).OrderBy(x => x.TimeTags.First().Value).ToList();
+
+            // Parse metadata rows
+            var metaDataRows = lyricData.Lyrics
+                .Where(x => x.TimeTags.Count == 0)
+                .Where(x => x.Text.StartsWith('[') && x.Text.EndsWith(']'))
+                .Select(x => x.Text)
+                .ToList();
+
+            foreach (string metaDataRow in metaDataRows)
             {
             {
-                // Parse and sort lyric rows
-                LyricParser lrcLyricParser = new LrcParser.Parser.Lrc.LrcParser();
-                Song lyricData = lrcLyricParser.Decode(lrcFileContent);
-                sortedLyricData = lyricData.Lyrics.Where(x => x.TimeTags.Count > 0).OrderBy(x => x.TimeTags.ToArray()[0].Value).ToList();
-
-                // Parse metadata rows
-                var metaDataRows = lyricData.Lyrics
-                    .Where(x => x.TimeTags.Count == 0)
-                    .Where(x => x.Text.StartsWith("[", StringComparison.Ordinal) && x.Text.EndsWith("]", StringComparison.Ordinal))
-                    .Select(x => x.Text)
-                    .ToList();
-
-                foreach (string metaDataRow in metaDataRows)
+                var metaDataField = metaDataRow.Split(':');
+                if (metaDataField.Length != 2)
                 {
                 {
-                    var metaDataField = metaDataRow.Split(":");
-
-                    string metaDataFieldName = metaDataField[0].Replace("[", string.Empty, StringComparison.Ordinal).Trim();
-                    string metaDataFieldValue = metaDataField[1].Replace("]", string.Empty, StringComparison.Ordinal).Trim();
-
-                    metaData.Add(metaDataFieldName, metaDataFieldValue);
+                    continue;
                 }
                 }
-            }
-            catch
-            {
-                return null;
-            }
 
 
-            if (!sortedLyricData.Any())
-            {
-                return null;
-            }
+                string metaDataFieldName = metaDataField[0][1..].Trim();
+                string metaDataFieldValue = metaDataField[1][..^1].Trim();
 
 
-            for (int i = 0; i < sortedLyricData.Count; i++)
-            {
-                var timeData = sortedLyricData[i].TimeTags.ToArray()[0].Value;
-                long ticks = Convert.ToInt64(timeData, new NumberFormatInfo()) * 10000;
-                lyricList.Add(new Controller.Lyrics.Lyric { Start = ticks, Text = sortedLyricData[i].Text });
+                metaData.Add(metaDataFieldName, metaDataFieldValue);
             }
             }
+        }
+        catch
+        {
+            return null;
+        }
 
 
-            if (metaData.Any())
-            {
-               return new LyricResponse { Metadata = metaData, Lyrics = lyricList };
-            }
+        if (sortedLyricData.Count == 0)
+        {
+            return null;
+        }
 
 
-            return new LyricResponse { Lyrics = lyricList };
+        for (int i = 0; i < sortedLyricData.Count; i++)
+        {
+            var timeData = sortedLyricData[i].TimeTags.ToArray()[0].Value;
+            long ticks = TimeSpan.FromMilliseconds((double)timeData).Ticks;
+            lyricList.Add(new Controller.Lyrics.Lyric(sortedLyricData[i].Text, ticks));
         }
         }
+
+        if (metaData.Any())
+        {
+           return new LyricResponse { Metadata = metaData, Lyrics = lyricList };
+        }
+
+        return new LyricResponse { Lyrics = lyricList };
     }
     }
 }
 }

+ 37 - 35
MediaBrowser.Providers/Lyric/LyricManager.cs

@@ -1,55 +1,57 @@
-#nullable disable
-
-#pragma warning disable CS1591
-
 using System.Collections.Generic;
 using System.Collections.Generic;
 using System.Linq;
 using System.Linq;
 using MediaBrowser.Controller.Entities;
 using MediaBrowser.Controller.Entities;
 using MediaBrowser.Controller.Lyrics;
 using MediaBrowser.Controller.Lyrics;
 
 
-namespace MediaBrowser.Providers.Lyric
+namespace MediaBrowser.Providers.Lyric;
+
+/// <summary>
+/// Lyric Manager.
+/// </summary>
+public class LyricManager : ILyricManager
 {
 {
-    public class LyricManager : ILyricManager
-    {
-        private readonly ILyricProvider[] _lyricProviders;
+    private readonly ILyricProvider[] _lyricProviders;
 
 
-        public LyricManager(IEnumerable<ILyricProvider> lyricProviders)
-        {
-            _lyricProviders = lyricProviders.ToArray();
-        }
+    /// <summary>
+    /// Initializes a new instance of the <see cref="LyricManager"/> class.
+    /// </summary>
+    /// <param name="lyricProviders">All found lyricProviders.</param>
+    public LyricManager(IEnumerable<ILyricProvider> lyricProviders)
+    {
+        _lyricProviders = lyricProviders.ToArray();
+    }
 
 
-        /// <inheritdoc />
-        public LyricResponse GetLyrics(BaseItem item)
+    /// <inheritdoc />
+    public LyricResponse GetLyrics(BaseItem item)
+    {
+        foreach (ILyricProvider provider in _lyricProviders)
         {
         {
-            foreach (ILyricProvider provider in _lyricProviders)
+            var results = provider.GetLyrics(item);
+            if (results is not null)
             {
             {
-                var results = provider.GetLyrics(item);
-                if (results is not null)
-                {
-                    return results;
-                }
+                return results;
             }
             }
-
-            return null;
         }
         }
 
 
-        /// <inheritdoc />
-        public bool HasLyricFile(BaseItem item)
+        return null;
+    }
+
+    /// <inheritdoc />
+    public bool HasLyricFile(BaseItem item)
+    {
+        foreach (ILyricProvider provider in _lyricProviders)
         {
         {
-            foreach (ILyricProvider provider in _lyricProviders)
+            if (item is null)
             {
             {
-                if (item is null)
-                {
-                    continue;
-                }
-
-                if (LyricInfo.GetLyricFilePath(provider, item.Path) is not null)
-                {
-                    return true;
-                }
+                continue;
             }
             }
 
 
-            return false;
+            if (LyricInfo.GetLyricFilePath(provider, item.Path) is not null)
+            {
+                return true;
+            }
         }
         }
+
+        return false;
     }
     }
 }
 }

+ 35 - 51
MediaBrowser.Providers/Lyric/TxtLyricProvider.cs

@@ -5,69 +5,53 @@ using System.Linq;
 using MediaBrowser.Controller.Entities;
 using MediaBrowser.Controller.Entities;
 using MediaBrowser.Controller.Lyrics;
 using MediaBrowser.Controller.Lyrics;
 
 
-namespace MediaBrowser.Providers.Lyric
+namespace MediaBrowser.Providers.Lyric;
+
+/// <summary>
+/// TXT Lyric Provider.
+/// </summary>
+public class TxtLyricProvider : ILyricProvider
 {
 {
-    /// <summary>
-    /// TXT Lyric Provider.
-    /// </summary>
-    public class TxtLyricProvider : ILyricProvider
-    {
-        /// <summary>
-        /// Initializes a new instance of the <see cref="TxtLyricProvider"/> class.
-        /// </summary>
-        public TxtLyricProvider()
-        {
-            Name = "TxtLyricProvider";
+    /// <inheritdoc />
+    public string Name { get; } = "TxtLyricProvider";
 
 
-            SupportedMediaTypes = new Collection<string>
+    /// <inheritdoc />
+    public IEnumerable<string> SupportedMediaTypes
+    {
+        get => new Collection<string>
             {
             {
                 "lrc", "txt"
                 "lrc", "txt"
             };
             };
-        }
-
-        /// <summary>
-        /// Gets a value indicating the provider name.
-        /// </summary>
-        public string Name { get; }
+    }
 
 
-        /// <summary>
-        /// Gets a value indicating the File Extenstions this provider supports.
-        /// </summary>
-        public IEnumerable<string> SupportedMediaTypes { get; }
+    /// <summary>
+    /// Opens lyric file for the requested item, and processes it for API return.
+    /// </summary>
+    /// <param name="item">The item to to process.</param>
+    /// <returns>If provider can determine lyrics, returns a <see cref="LyricResponse"/>; otherwise, null.</returns>
+    public LyricResponse? GetLyrics(BaseItem item)
+    {
+        string? lyricFilePath = LyricInfo.GetLyricFilePath(this, item.Path);
 
 
-        /// <summary>
-        /// Opens lyric file for the requested item, and processes it for API return.
-        /// </summary>
-        /// <param name="item">The item to to process.</param>
-        /// <returns>If provider can determine lyrics, returns a <see cref="LyricResponse"/>; otherwise, null.</returns>
-        public LyricResponse? GetLyrics(BaseItem item)
+        if (string.IsNullOrEmpty(lyricFilePath))
         {
         {
-            string? lyricFilePath = LyricInfo.GetLyricFilePath(this, item.Path);
-
-            if (string.IsNullOrEmpty(lyricFilePath))
-            {
-                return null;
-            }
-
-            List<Controller.Lyrics.Lyric> lyricList = new List<Controller.Lyrics.Lyric>();
-
-            string lyricData = System.IO.File.ReadAllText(lyricFilePath);
+            return null;
+        }
 
 
-            // Splitting on Environment.NewLine caused some new lines to be missed in Windows.
-            char[] newLineDelims = new[] { '\r', '\n' };
-            string[] lyricTextLines = lyricData.Split(newLineDelims, StringSplitOptions.RemoveEmptyEntries);
+        string[] lyricTextLines = System.IO.File.ReadAllLines(lyricFilePath);
 
 
-            if (!lyricTextLines.Any())
-            {
-                return null;
-            }
+        List<Controller.Lyrics.Lyric> lyricList = new List<Controller.Lyrics.Lyric>();
 
 
-            foreach (string lyricTextLine in lyricTextLines)
-            {
-                lyricList.Add(new Controller.Lyrics.Lyric { Text = lyricTextLine });
-            }
+        if (lyricTextLines.Length == 0)
+        {
+            return null;
+        }
 
 
-            return new LyricResponse { Lyrics = lyricList };
+        foreach (string lyricTextLine in lyricTextLines)
+        {
+            lyricList.Add(new Controller.Lyrics.Lyric(lyricTextLine));
         }
         }
+
+        return new LyricResponse { Lyrics = lyricList };
     }
     }
 }
 }

+ 0 - 1
MediaBrowser.Providers/MediaBrowser.Providers.csproj

@@ -6,7 +6,6 @@
   </PropertyGroup>
   </PropertyGroup>
 
 
   <ItemGroup>
   <ItemGroup>
-    <ProjectReference Include="..\Jellyfin.Api\Jellyfin.Api.csproj" />
     <ProjectReference Include="..\MediaBrowser.Controller\MediaBrowser.Controller.csproj" />
     <ProjectReference Include="..\MediaBrowser.Controller\MediaBrowser.Controller.csproj" />
     <ProjectReference Include="..\MediaBrowser.Model\MediaBrowser.Model.csproj" />
     <ProjectReference Include="..\MediaBrowser.Model\MediaBrowser.Model.csproj" />
     <ProjectReference Include="..\DvdLib\DvdLib.csproj" />
     <ProjectReference Include="..\DvdLib\DvdLib.csproj" />