diff options
| author | 1hitsong <3330318+1hitsong@users.noreply.github.com> | 2022-09-15 19:45:26 -0400 |
|---|---|---|
| committer | 1hitsong <3330318+1hitsong@users.noreply.github.com> | 2022-09-15 19:45:26 -0400 |
| commit | d9be3874ba3842d5888c5cbbe583614ed990849e (patch) | |
| tree | f9a5264a402548f531e83891a70dd0a2bd7fc35d /Jellyfin.Api/Helpers/ItemHelper.cs | |
| parent | 7520a1998569f0ba58008016c10de21d66b6b836 (diff) | |
Auto stash before merge of "lyric-lrc-file-support" and "origin/lyric-lrc-file-support"
Diffstat (limited to 'Jellyfin.Api/Helpers/ItemHelper.cs')
| -rw-r--r-- | Jellyfin.Api/Helpers/ItemHelper.cs | 106 |
1 files changed, 0 insertions, 106 deletions
diff --git a/Jellyfin.Api/Helpers/ItemHelper.cs b/Jellyfin.Api/Helpers/ItemHelper.cs deleted file mode 100644 index 49bb8af8e..000000000 --- a/Jellyfin.Api/Helpers/ItemHelper.cs +++ /dev/null @@ -1,106 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Dynamic; -using System.Globalization; -using System.IO; -using System.Linq; -using Jellyfin.Api.Models.UserDtos; -using LrcParser.Model; -using LrcParser.Parser; -using MediaBrowser.Controller.Entities; - -namespace Jellyfin.Api.Helpers -{ - /// <summary> - /// Item helper. - /// </summary> - public static class ItemHelper - { - /// <summary> - /// Opens lyrics file, converts to a List of Lyrics, and returns it. - /// </summary> - /// <param name="item">Requested Item.</param> - /// <returns>Collection of Lyrics.</returns> - internal static object? GetLyricData(BaseItem item) - { - // Find all classes that implement ILyricsProvider Interface - var foundLyricProviders = System.Reflection.Assembly.GetExecutingAssembly() - .GetTypes() - .Where(type => typeof(ILyricsProvider).IsAssignableFrom(type) && !type.IsInterface); - - if (!foundLyricProviders.Any()) - { - return null; - } - - foreach (var provider in foundLyricProviders) - { - ILyricsProvider? newProvider = Activator.CreateInstance(provider) as ILyricsProvider; - if (newProvider is not null) - { - newProvider.Process(item); - if (newProvider.HasData) - { - return newProvider.Data; - } - } - } - - return null; - } - - /// <summary> - /// Checks if requested item has a matching lyric file. - /// </summary> - /// <param name="itemPath">Path of requested item.</param> - /// <returns>True if item has a matching lyrics file.</returns> - public static string? GetLyricFilePath(string itemPath) - { - // Find all classes that implement ILyricsProvider Interface - var foundLyricProviders = System.Reflection.Assembly.GetExecutingAssembly() - .GetTypes() - .Where(type => typeof(ILyricsProvider).IsAssignableFrom(type) && !type.IsInterface); - - if (!foundLyricProviders.Any()) - { - return null; - } - - // Iterate over all found lyric providers - foreach (var provider in foundLyricProviders) - { - ILyricsProvider? foundProvider = Activator.CreateInstance(provider) as ILyricsProvider; - if (foundProvider?.FileExtensions is null) - { - continue; - } - - if (foundProvider.FileExtensions.Any()) - { - foreach (string lyricFileExtension in foundProvider.FileExtensions) - { - string lyricFilePath = @Path.ChangeExtension(itemPath, lyricFileExtension); - if (System.IO.File.Exists(lyricFilePath)) - { - return lyricFilePath; - } - } - } - } - - return null; - } - - - /// <summary> - /// Checks if requested item has a matching local lyric file. - /// </summary> - /// <param name="itemPath">Path of requested item.</param> - /// <returns>True if item has a matching lyrics file; otherwise false.</returns> - public static bool HasLyricFile(string itemPath) - { - string? lyricFilePath = GetLyricFilePath(itemPath); - return !string.IsNullOrEmpty(lyricFilePath); - } - } -} |
