From 54b3debd2774caedf92a531a2461b42d7bb37af1 Mon Sep 17 00:00:00 2001
From: Joseph <1315585+joseph39@users.noreply.github.com>
Date: Mon, 18 Jul 2022 23:30:27 -0700
Subject: Add referer parameter to ffmpeg
As of https://trac.ffmpeg.org/ticket/2179, ffmpeg supports referer parameter which injects Referer header to the HTTP request for remote content. Have EncodingHelper pass this in if it's included in RemoteHttpHeaders.
---
.../MediaEncoding/EncodingHelper.cs | 24 ++++++++++++++++++++++
1 file changed, 24 insertions(+)
(limited to 'MediaBrowser.Controller')
diff --git a/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs b/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs
index 6fb5c88740..ab2daf7a50 100644
--- a/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs
+++ b/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs
@@ -255,6 +255,21 @@ namespace MediaBrowser.Controller.MediaEncoding
return string.Empty;
}
+ ///
+ /// Gets the referer param.
+ ///
+ /// The state.
+ /// System.String.
+ public string GetRefererParam(EncodingJobInfo state)
+ {
+ if (state.RemoteHttpHeaders.TryGetValue("Referer", out string referer))
+ {
+ return "-referer \"" + referer + "\"";
+ }
+
+ return string.Empty;
+ }
+
public static string GetInputFormat(string container)
{
if (string.IsNullOrEmpty(container))
@@ -4962,6 +4977,15 @@ namespace MediaBrowser.Controller.MediaEncoding
inputModifier = inputModifier.Trim();
+ var refererParam = GetRefererParam(state);
+
+ if (!string.IsNullOrEmpty(refererParam))
+ {
+ inputModifier += " " + refererParam;
+ }
+
+ inputModifier = inputModifier.Trim();
+
inputModifier += " " + GetFastSeekCommandLineParameter(state, encodingOptions, segmentContainer);
inputModifier = inputModifier.Trim();
--
cgit v1.2.3
From 9ec2870b1034e0b64ebde3e29a3779c7f6bb2ac4 Mon Sep 17 00:00:00 2001
From: luz paz
Date: Mon, 15 Aug 2022 06:48:34 -0400
Subject: Fix various typos
Found via `codespell -q 3 -S ./Emby.Server.Implementations/Localization -L allready,doesnt,inh,receivedfrom,whoknows`
---
Emby.Dlna/Didl/DidlBuilder.cs | 2 +-
Emby.Dlna/DlnaManager.cs | 2 +-
Emby.Dlna/IDlnaEventManager.cs | 4 ++--
Emby.Server.Implementations/Library/LibraryManager.cs | 2 +-
.../Library/Resolvers/Movies/MovieResolver.cs | 2 +-
Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs | 2 +-
Emby.Server.Implementations/Session/SessionManager.cs | 2 +-
.../Session/SessionWebSocketListener.cs | 2 +-
Jellyfin.Api/Controllers/AudioController.cs | 2 +-
Jellyfin.Api/Controllers/DynamicHlsController.cs | 4 ++--
Jellyfin.Api/Controllers/SearchController.cs | 6 +++---
Jellyfin.Api/Controllers/UserController.cs | 2 +-
Jellyfin.Api/Models/StreamingDtos/StreamState.cs | 2 +-
.../Models/SyncPlayDtos/RemoveFromPlaylistRequestDto.cs | 4 ++--
Jellyfin.Drawing.Skia/SkiaHelper.cs | 2 +-
Jellyfin.Networking/Configuration/NetworkConfiguration.cs | 2 +-
Jellyfin.Networking/Manager/NetworkManager.cs | 2 +-
MediaBrowser.Controller/Entities/TV/Season.cs | 2 +-
MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs | 4 ++--
.../SyncPlay/GroupStates/WaitingGroupState.cs | 2 +-
.../PlaybackRequests/RemoveFromPlaylistGroupRequest.cs | 4 ++--
MediaBrowser.Controller/SyncPlay/Queue/PlayQueueManager.cs | 4 ++--
MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs | 4 ++--
MediaBrowser.Model/Dlna/ContentFeatureBuilder.cs | 2 +-
MediaBrowser.Model/Dto/BaseItemDto.cs | 6 +++---
MediaBrowser.Model/Entities/MediaStream.cs | 2 +-
MediaBrowser.Model/SyncPlay/GroupStateType.cs | 2 +-
MediaBrowser.Model/Tasks/ITaskManager.cs | 10 +++++-----
MediaBrowser.Model/Tasks/ITaskTrigger.cs | 4 ++--
MediaBrowser.Providers/Manager/ProviderManager.cs | 2 +-
.../Plugins/MusicBrainz/MusicBrainzAlbumProvider.cs | 2 +-
MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs | 2 +-
src/Jellyfin.Extensions/SplitStringExtensions.cs | 2 +-
src/Jellyfin.Extensions/StringExtensions.cs | 2 +-
tests/Jellyfin.Model.Tests/Cryptography/PasswordHashTests.cs | 6 +++---
tests/Jellyfin.Networking.Tests/NetworkParseTests.cs | 2 +-
.../LiveTv/SchedulesDirect/SchedulesDirectDeserializeTests.cs | 2 +-
.../Test Data/Updates/manifest-stable.json | 2 +-
38 files changed, 56 insertions(+), 56 deletions(-)
(limited to 'MediaBrowser.Controller')
diff --git a/Emby.Dlna/Didl/DidlBuilder.cs b/Emby.Dlna/Didl/DidlBuilder.cs
index df6539a5a6..8e3a335c66 100644
--- a/Emby.Dlna/Didl/DidlBuilder.cs
+++ b/Emby.Dlna/Didl/DidlBuilder.cs
@@ -446,7 +446,7 @@ namespace Emby.Dlna.Didl
///
///
/// If context is a season, this will return a string containing just episode number and name.
- /// Otherwise the result will include series nams and season number.
+ /// Otherwise the result will include series names and season number.
///
/// The episode.
/// Current context.
diff --git a/Emby.Dlna/DlnaManager.cs b/Emby.Dlna/DlnaManager.cs
index fe78d74ee7..74624334bb 100644
--- a/Emby.Dlna/DlnaManager.cs
+++ b/Emby.Dlna/DlnaManager.cs
@@ -123,7 +123,7 @@ namespace Emby.Dlna
///
/// Attempts to match a device with a profile.
/// Rules:
- /// - If the profile field has no value, the field matches irregardless of its contents.
+ /// - If the profile field has no value, the field matches regardless of its contents.
/// - the profile field can be an exact match, or a reg exp.
///
/// The of the device.
diff --git a/Emby.Dlna/IDlnaEventManager.cs b/Emby.Dlna/IDlnaEventManager.cs
index 33cf0896ba..eea030d6d1 100644
--- a/Emby.Dlna/IDlnaEventManager.cs
+++ b/Emby.Dlna/IDlnaEventManager.cs
@@ -16,7 +16,7 @@ namespace Emby.Dlna
///
/// The subscription identifier.
/// The notification type.
- /// The requested timeout as a sting.
+ /// The requested timeout as a string.
/// The callback url.
/// The response.
EventSubscriptionResponse RenewEventSubscription(string subscriptionId, string notificationType, string requestedTimeoutString, string callbackUrl);
@@ -25,7 +25,7 @@ namespace Emby.Dlna
/// Creates the event subscription.
///
/// The notification type.
- /// The requested timeout as a sting.
+ /// The requested timeout as a string.
/// The callback url.
/// The response.
EventSubscriptionResponse CreateEventSubscription(string notificationType, string requestedTimeoutString, string callbackUrl);
diff --git a/Emby.Server.Implementations/Library/LibraryManager.cs b/Emby.Server.Implementations/Library/LibraryManager.cs
index 2843fb8f83..6796845525 100644
--- a/Emby.Server.Implementations/Library/LibraryManager.cs
+++ b/Emby.Server.Implementations/Library/LibraryManager.cs
@@ -2529,7 +2529,7 @@ namespace Emby.Server.Implementations.Library
}
catch (Exception ex)
{
- _logger.LogError(ex, "Error reading the episode informations with ffprobe. Episode: {EpisodeInfo}", episodeInfo.Path);
+ _logger.LogError(ex, "Error reading the episode information with ffprobe. Episode: {EpisodeInfo}", episodeInfo.Path);
}
var changed = false;
diff --git a/Emby.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs b/Emby.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs
index a60251dacd..b2f388a667 100644
--- a/Emby.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs
+++ b/Emby.Server.Implementations/Library/Resolvers/Movies/MovieResolver.cs
@@ -387,7 +387,7 @@ namespace Emby.Server.Implementations.Library.Resolvers.Movies
if (!string.IsNullOrEmpty(item.Path))
{
- // check for imdb id - we use full media path, as we can assume, that this will match in any use case (wither id in parent dir or in file name)
+ // check for imdb id - we use full media path, as we can assume, that this will match in any use case (either id in parent dir or in file name)
var imdbid = item.Path.AsSpan().GetAttributeValue("imdbid");
if (!string.IsNullOrWhiteSpace(imdbid))
diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs
index 708ff52d79..be06356a4f 100644
--- a/Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs
+++ b/Emby.Server.Implementations/LiveTv/TunerHosts/M3uParser.cs
@@ -199,7 +199,7 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts
if (string.IsNullOrWhiteSpace(numberString))
{
// Using this as a fallback now as this leads to Problems with channels like "5 USA"
- // where 5 isn't ment to be the channel number
+ // where 5 isn't meant to be the channel number
// Check for channel number with the format from SatIp
// #EXTINF:0,84. VOX Schweiz
// #EXTINF:0,84.0 - VOX Schweiz
diff --git a/Emby.Server.Implementations/Session/SessionManager.cs b/Emby.Server.Implementations/Session/SessionManager.cs
index d25376297f..7f927e2709 100644
--- a/Emby.Server.Implementations/Session/SessionManager.cs
+++ b/Emby.Server.Implementations/Session/SessionManager.cs
@@ -1242,7 +1242,7 @@ namespace Emby.Server.Implementations.Session
if (item == null)
{
- _logger.LogError("A non-existant item Id {0} was passed into TranslateItemForPlayback", id);
+ _logger.LogError("A non-existent item Id {0} was passed into TranslateItemForPlayback", id);
return Array.Empty();
}
diff --git a/Emby.Server.Implementations/Session/SessionWebSocketListener.cs b/Emby.Server.Implementations/Session/SessionWebSocketListener.cs
index a085ee546d..fccf50f60f 100644
--- a/Emby.Server.Implementations/Session/SessionWebSocketListener.cs
+++ b/Emby.Server.Implementations/Session/SessionWebSocketListener.cs
@@ -37,7 +37,7 @@ namespace Emby.Server.Implementations.Session
private const float ForceKeepAliveFactor = 0.75f;
///
- /// Lock used for accesing the KeepAlive cancellation token.
+ /// Lock used for accessing the KeepAlive cancellation token.
///
private readonly object _keepAliveLock = new object();
diff --git a/Jellyfin.Api/Controllers/AudioController.cs b/Jellyfin.Api/Controllers/AudioController.cs
index 54ac06276e..94f7a7b827 100644
--- a/Jellyfin.Api/Controllers/AudioController.cs
+++ b/Jellyfin.Api/Controllers/AudioController.cs
@@ -207,7 +207,7 @@ namespace Jellyfin.Api.Controllers
/// Optional. The dlna device profile id to utilize.
/// The play session id.
/// The segment container.
- /// The segment lenght.
+ /// The segment length.
/// The minimum number of segments.
/// The media version id, if playing an alternate version.
/// The device id of the client requesting. Used to stop encoding processes when needed.
diff --git a/Jellyfin.Api/Controllers/DynamicHlsController.cs b/Jellyfin.Api/Controllers/DynamicHlsController.cs
index 1e8d038751..3ed80f6621 100644
--- a/Jellyfin.Api/Controllers/DynamicHlsController.cs
+++ b/Jellyfin.Api/Controllers/DynamicHlsController.cs
@@ -121,7 +121,7 @@ namespace Jellyfin.Api.Controllers
/// Optional. The dlna device profile id to utilize.
/// The play session id.
/// The segment container.
- /// The segment lenght.
+ /// The segment length.
/// The minimum number of segments.
/// The media version id, if playing an alternate version.
/// The device id of the client requesting. Used to stop encoding processes when needed.
@@ -1832,7 +1832,7 @@ namespace Jellyfin.Api.Controllers
// Set the key frame params for video encoding to match the hls segment time.
args += _encodingHelper.GetHlsVideoKeyFrameArguments(state, codec, state.SegmentLength, isEventPlaylist, startNumber);
- // Currenly b-frames in libx265 breaks the FMP4-HLS playback on iOS, disable it for now.
+ // Currently b-frames in libx265 breaks the FMP4-HLS playback on iOS, disable it for now.
if (string.Equals(codec, "libx265", StringComparison.OrdinalIgnoreCase))
{
args += " -bf 0";
diff --git a/Jellyfin.Api/Controllers/SearchController.cs b/Jellyfin.Api/Controllers/SearchController.cs
index 07e113ad3e..3b1f7a52ab 100644
--- a/Jellyfin.Api/Controllers/SearchController.cs
+++ b/Jellyfin.Api/Controllers/SearchController.cs
@@ -60,9 +60,9 @@ namespace Jellyfin.Api.Controllers
/// Optional. The maximum number of records to return.
/// Optional. Supply a user id to search within a user's library or omit to search all.
/// The search term to filter on.
- /// If specified, only results with the specified item types are returned. This allows multiple, comma delimeted.
- /// If specified, results with these item types are filtered out. This allows multiple, comma delimeted.
- /// If specified, only results with the specified media types are returned. This allows multiple, comma delimeted.
+ /// If specified, only results with the specified item types are returned. This allows multiple, comma delimited.
+ /// If specified, results with these item types are filtered out. This allows multiple, comma delimited.
+ /// If specified, only results with the specified media types are returned. This allows multiple, comma delimited.
/// If specified, only children of the parent are returned.
/// Optional filter for movies.
/// Optional filter for series.
diff --git a/Jellyfin.Api/Controllers/UserController.cs b/Jellyfin.Api/Controllers/UserController.cs
index 82c8563a80..d1109bebc8 100644
--- a/Jellyfin.Api/Controllers/UserController.cs
+++ b/Jellyfin.Api/Controllers/UserController.cs
@@ -502,7 +502,7 @@ namespace Jellyfin.Api.Controllers
if (isLocal)
{
- _logger.LogWarning("Password reset proccess initiated from outside the local network with IP: {IP}", ip);
+ _logger.LogWarning("Password reset process initiated from outside the local network with IP: {IP}", ip);
}
var result = await _userManager.StartForgotPasswordProcess(forgotPasswordRequest.EnteredUsername, isLocal).ConfigureAwait(false);
diff --git a/Jellyfin.Api/Models/StreamingDtos/StreamState.cs b/Jellyfin.Api/Models/StreamingDtos/StreamState.cs
index 192f33ebd1..8182e3c9e8 100644
--- a/Jellyfin.Api/Models/StreamingDtos/StreamState.cs
+++ b/Jellyfin.Api/Models/StreamingDtos/StreamState.cs
@@ -169,7 +169,7 @@ namespace Jellyfin.Api.Models.StreamingDtos
///
/// Disposes the stream state.
///
- /// Whether the object is currently beeing disposed.
+ /// Whether the object is currently being disposed.
protected virtual void Dispose(bool disposing)
{
if (_disposed)
diff --git a/Jellyfin.Api/Models/SyncPlayDtos/RemoveFromPlaylistRequestDto.cs b/Jellyfin.Api/Models/SyncPlayDtos/RemoveFromPlaylistRequestDto.cs
index 02ce5a0488..226a584e1d 100644
--- a/Jellyfin.Api/Models/SyncPlayDtos/RemoveFromPlaylistRequestDto.cs
+++ b/Jellyfin.Api/Models/SyncPlayDtos/RemoveFromPlaylistRequestDto.cs
@@ -17,9 +17,9 @@ namespace Jellyfin.Api.Models.SyncPlayDtos
}
///
- /// Gets or sets the playlist identifiers ot the items. Ignored when clearing the playlist.
+ /// Gets or sets the playlist identifiers of the items. Ignored when clearing the playlist.
///
- /// The playlist identifiers ot the items.
+ /// The playlist identifiers of the items.
public IReadOnlyList PlaylistItemIds { get; set; }
///
diff --git a/Jellyfin.Drawing.Skia/SkiaHelper.cs b/Jellyfin.Drawing.Skia/SkiaHelper.cs
index c001c32b8c..0478fc7c31 100644
--- a/Jellyfin.Drawing.Skia/SkiaHelper.cs
+++ b/Jellyfin.Drawing.Skia/SkiaHelper.cs
@@ -13,7 +13,7 @@ namespace Jellyfin.Drawing.Skia
///
/// The current skia encoder.
/// The list of image paths.
- /// The current checked indes.
+ /// The current checked index.
/// The new index.
/// A valid bitmap, or null if no bitmap exists after currentIndex.
public static SKBitmap? GetNextValidImage(SkiaEncoder skiaEncoder, IReadOnlyList paths, int currentIndex, out int newIndex)
diff --git a/Jellyfin.Networking/Configuration/NetworkConfiguration.cs b/Jellyfin.Networking/Configuration/NetworkConfiguration.cs
index 61db223d92..361dbc8142 100644
--- a/Jellyfin.Networking/Configuration/NetworkConfiguration.cs
+++ b/Jellyfin.Networking/Configuration/NetworkConfiguration.cs
@@ -193,7 +193,7 @@ namespace Jellyfin.Networking.Configuration
public bool AutoDiscovery { get; set; } = true;
///
- /// Gets or sets the filter for remote IP connectivity. Used in conjuntion with .
+ /// Gets or sets the filter for remote IP connectivity. Used in conjunction with .
///
public string[] RemoteIPFilter { get; set; } = Array.Empty();
diff --git a/Jellyfin.Networking/Manager/NetworkManager.cs b/Jellyfin.Networking/Manager/NetworkManager.cs
index 4b7b87814c..fd0665dbdd 100644
--- a/Jellyfin.Networking/Manager/NetworkManager.cs
+++ b/Jellyfin.Networking/Manager/NetworkManager.cs
@@ -944,7 +944,7 @@ namespace Jellyfin.Networking.Manager
// Add virtual machine interface names to the list of bind exclusions, so that they are auto-excluded.
if (config.IgnoreVirtualInterfaces)
{
- // each virtual interface name must be pre-pended with the exclusion symbol !
+ // each virtual interface name must be prepended with the exclusion symbol !
var virtualInterfaceNames = config.VirtualInterfaceNames.Split(',').Select(p => "!" + p).ToArray();
if (lanAddresses.Length > 0)
{
diff --git a/MediaBrowser.Controller/Entities/TV/Season.cs b/MediaBrowser.Controller/Entities/TV/Season.cs
index bd8df2facb..599d35da64 100644
--- a/MediaBrowser.Controller/Entities/TV/Season.cs
+++ b/MediaBrowser.Controller/Entities/TV/Season.cs
@@ -244,7 +244,7 @@ namespace MediaBrowser.Controller.Entities.TV
///
/// This is called before any metadata refresh and returns true or false indicating if changes were made.
///
- /// true to replace metdata, false to not.
+ /// true to replace metadata, false to not.
/// true if XXXX, false otherwise.
public override bool BeforeMetadataRefresh(bool replaceAllMetadata)
{
diff --git a/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs b/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs
index e5aae620ac..17e410fe13 100644
--- a/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs
+++ b/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs
@@ -194,7 +194,7 @@ namespace MediaBrowser.Controller.MediaEncoding
///
/// Gets the name of the output video codec.
///
- /// Encording state.
+ /// Encoding state.
/// Encoding options.
/// Encoder string.
public string GetVideoEncoder(EncodingJobInfo state, EncodingOptions encodingOptions)
@@ -1980,7 +1980,7 @@ namespace MediaBrowser.Controller.MediaEncoding
}
}
- // Cap the max target bitrate to intMax/2 to satisify the bufsize=bitrate*2.
+ // Cap the max target bitrate to intMax/2 to satisfy the bufsize=bitrate*2.
return Math.Min(bitrate ?? 0, int.MaxValue / 2);
}
diff --git a/MediaBrowser.Controller/SyncPlay/GroupStates/WaitingGroupState.cs b/MediaBrowser.Controller/SyncPlay/GroupStates/WaitingGroupState.cs
index a0c38b3097..2164945560 100644
--- a/MediaBrowser.Controller/SyncPlay/GroupStates/WaitingGroupState.cs
+++ b/MediaBrowser.Controller/SyncPlay/GroupStates/WaitingGroupState.cs
@@ -549,7 +549,7 @@ namespace MediaBrowser.Controller.SyncPlay.GroupStates
if (InitialState.Equals(GroupStateType.Playing))
{
- // Group went from playing to waiting state and a pause request occured while waiting.
+ // Group went from playing to waiting state and a pause request occurred while waiting.
var pauseRequest = new PauseGroupRequest();
pausedState.HandleRequest(pauseRequest, context, Type, session, cancellationToken);
}
diff --git a/MediaBrowser.Controller/SyncPlay/PlaybackRequests/RemoveFromPlaylistGroupRequest.cs b/MediaBrowser.Controller/SyncPlay/PlaybackRequests/RemoveFromPlaylistGroupRequest.cs
index 2f38d6adc3..619294e957 100644
--- a/MediaBrowser.Controller/SyncPlay/PlaybackRequests/RemoveFromPlaylistGroupRequest.cs
+++ b/MediaBrowser.Controller/SyncPlay/PlaybackRequests/RemoveFromPlaylistGroupRequest.cs
@@ -27,9 +27,9 @@ namespace MediaBrowser.Controller.SyncPlay.PlaybackRequests
}
///
- /// Gets the playlist identifiers ot the items.
+ /// Gets the playlist identifiers of the items.
///
- /// The playlist identifiers ot the items.
+ /// The playlist identifiers of the items.
public IReadOnlyList PlaylistItemIds { get; }
///
diff --git a/MediaBrowser.Controller/SyncPlay/Queue/PlayQueueManager.cs b/MediaBrowser.Controller/SyncPlay/Queue/PlayQueueManager.cs
index f49876cca4..3a7685f347 100644
--- a/MediaBrowser.Controller/SyncPlay/Queue/PlayQueueManager.cs
+++ b/MediaBrowser.Controller/SyncPlay/Queue/PlayQueueManager.cs
@@ -102,7 +102,7 @@ namespace MediaBrowser.Controller.SyncPlay.Queue
}
///
- /// Appends new items to the playlist. The specified order is mantained.
+ /// Appends new items to the playlist. The specified order is maintained.
///
/// The items to add to the playlist.
public void Queue(IReadOnlyList items)
@@ -197,7 +197,7 @@ namespace MediaBrowser.Controller.SyncPlay.Queue
}
///
- /// Adds new items to the playlist right after the playing item. The specified order is mantained.
+ /// Adds new items to the playlist right after the playing item. The specified order is maintained.
///
/// The items to add to the playlist.
public void QueueNext(IReadOnlyList items)
diff --git a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs
index 77b97c9b48..7f301a9d8b 100644
--- a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs
+++ b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs
@@ -619,9 +619,9 @@ namespace MediaBrowser.MediaEncoding.Encoder
Video3DFormat.HalfSideBySide => "crop=iw/2:ih:0:0,scale=(iw*2):ih,setdar=dar=a,crop=min(iw\\,ih*dar):min(ih\\,iw/dar):(iw-min(iw\\,iw*sar))/2:(ih - min (ih\\,ih/sar))/2,setsar=sar=1",
// fsbs crop width in half,set the display aspect,crop out any black bars we may have made
Video3DFormat.FullSideBySide => "crop=iw/2:ih:0:0,setdar=dar=a,crop=min(iw\\,ih*dar):min(ih\\,iw/dar):(iw-min(iw\\,iw*sar))/2:(ih - min (ih\\,ih/sar))/2,setsar=sar=1",
- // htab crop heigh in half,scale to correct size, set the display aspect,crop out any black bars we may have made
+ // htab crop height in half,scale to correct size, set the display aspect,crop out any black bars we may have made
Video3DFormat.HalfTopAndBottom => "crop=iw:ih/2:0:0,scale=(iw*2):ih),setdar=dar=a,crop=min(iw\\,ih*dar):min(ih\\,iw/dar):(iw-min(iw\\,iw*sar))/2:(ih - min (ih\\,ih/sar))/2,setsar=sar=1",
- // ftab crop heigt in half, set the display aspect,crop out any black bars we may have made
+ // ftab crop height in half, set the display aspect,crop out any black bars we may have made
Video3DFormat.FullTopAndBottom => "crop=iw:ih/2:0:0,setdar=dar=a,crop=min(iw\\,ih*dar):min(ih\\,iw/dar):(iw-min(iw\\,iw*sar))/2:(ih - min (ih\\,ih/sar))/2,setsar=sar=1",
_ => "scale=trunc(iw*sar):ih"
};
diff --git a/MediaBrowser.Model/Dlna/ContentFeatureBuilder.cs b/MediaBrowser.Model/Dlna/ContentFeatureBuilder.cs
index 47c36494bd..c32c1c108c 100644
--- a/MediaBrowser.Model/Dlna/ContentFeatureBuilder.cs
+++ b/MediaBrowser.Model/Dlna/ContentFeatureBuilder.cs
@@ -157,7 +157,7 @@ namespace MediaBrowser.Model.Dlna
flagValue |= DlnaFlags.ByteBasedSeek;
}
- // Time based seek is curently disabled when streaming. On LG CX3 adding DlnaFlags.TimeBasedSeek and orgPn causes the DLNA playback to fail (format not supported). Further investigations are needed before enabling the remaining code paths.
+ // Time based seek is currently disabled when streaming. On LG CX3 adding DlnaFlags.TimeBasedSeek and orgPn causes the DLNA playback to fail (format not supported). Further investigations are needed before enabling the remaining code paths.
// else if (runtimeTicks.HasValue)
// {
// flagValue = flagValue | DlnaFlags.TimeBasedSeek;
diff --git a/MediaBrowser.Model/Dto/BaseItemDto.cs b/MediaBrowser.Model/Dto/BaseItemDto.cs
index 094dc73b27..fdb84fa320 100644
--- a/MediaBrowser.Model/Dto/BaseItemDto.cs
+++ b/MediaBrowser.Model/Dto/BaseItemDto.cs
@@ -294,13 +294,13 @@ namespace MediaBrowser.Model.Dto
public NameGuidPair[] GenreItems { get; set; }
///
- /// Gets or sets wether the item has a logo, this will hold the Id of the Parent that has one.
+ /// Gets or sets whether the item has a logo, this will hold the Id of the Parent that has one.
///
/// The parent logo item id.
public Guid? ParentLogoItemId { get; set; }
///
- /// Gets or sets wether the item has any backdrops, this will hold the Id of the Parent that has one.
+ /// Gets or sets whether the item has any backdrops, this will hold the Id of the Parent that has one.
///
/// The parent backdrop item id.
public Guid? ParentBackdropItemId { get; set; }
@@ -506,7 +506,7 @@ namespace MediaBrowser.Model.Dto
public string ParentLogoImageTag { get; set; }
///
- /// Gets or sets wether the item has fan art, this will hold the Id of the Parent that has one.
+ /// Gets or sets whether the item has fan art, this will hold the Id of the Parent that has one.
///
/// The parent art item id.
public Guid? ParentArtItemId { get; set; }
diff --git a/MediaBrowser.Model/Entities/MediaStream.cs b/MediaBrowser.Model/Entities/MediaStream.cs
index ae8f3b0edf..90a60cf470 100644
--- a/MediaBrowser.Model/Entities/MediaStream.cs
+++ b/MediaBrowser.Model/Entities/MediaStream.cs
@@ -606,7 +606,7 @@ namespace MediaBrowser.Model.Entities
<= 1024 when Height <= 576 => IsInterlaced ? "576i" : "576p",
// 1280x720
<= 1280 when Height <= 962 => IsInterlaced ? "720i" : "720p",
- // 2560x1080 (FHD ultra wide 21:9) using 1440px width to accomodate WQHD
+ // 2560x1080 (FHD ultra wide 21:9) using 1440px width to accommodate WQHD
<= 2560 when Height <= 1440 => IsInterlaced ? "1080i" : "1080p",
// 4K
<= 4096 when Height <= 3072 => "4K",
diff --git a/MediaBrowser.Model/SyncPlay/GroupStateType.cs b/MediaBrowser.Model/SyncPlay/GroupStateType.cs
index 7aa454f928..96364cacc7 100644
--- a/MediaBrowser.Model/SyncPlay/GroupStateType.cs
+++ b/MediaBrowser.Model/SyncPlay/GroupStateType.cs
@@ -11,7 +11,7 @@ namespace MediaBrowser.Model.SyncPlay
Idle = 0,
///
- /// The group is in wating state. Playback is paused. Will start playing when users are ready.
+ /// The group is in waiting state. Playback is paused. Will start playing when users are ready.
///
Waiting = 1,
diff --git a/MediaBrowser.Model/Tasks/ITaskManager.cs b/MediaBrowser.Model/Tasks/ITaskManager.cs
index a86bf2a1c8..13bebc479e 100644
--- a/MediaBrowser.Model/Tasks/ITaskManager.cs
+++ b/MediaBrowser.Model/Tasks/ITaskManager.cs
@@ -22,7 +22,7 @@ namespace MediaBrowser.Model.Tasks
///
/// Cancels if running and queue.
///
- /// An implementatin of .
+ /// An implementation of .
/// Task options.
void CancelIfRunningAndQueue(TaskOptions options)
where T : IScheduledTask;
@@ -30,21 +30,21 @@ namespace MediaBrowser.Model.Tasks
///
/// Cancels if running and queue.
///
- /// An implementatin of .
+ /// An implementation of .
void CancelIfRunningAndQueue()
where T : IScheduledTask;
///
/// Cancels if running.
///
- /// An implementatin of .
+ /// An implementation of .
void CancelIfRunning()
where T : IScheduledTask;
///
/// Queues the scheduled task.
///
- /// An implementatin of .
+ /// An implementation of .
/// Task options.
void QueueScheduledTask(TaskOptions options)
where T : IScheduledTask;
@@ -52,7 +52,7 @@ namespace MediaBrowser.Model.Tasks
///
/// Queues the scheduled task.
///
- /// An implementatin of .
+ /// An implementation of .
void QueueScheduledTask()
where T : IScheduledTask;
diff --git a/MediaBrowser.Model/Tasks/ITaskTrigger.cs b/MediaBrowser.Model/Tasks/ITaskTrigger.cs
index 8c3ec6626c..0536f4ef77 100644
--- a/MediaBrowser.Model/Tasks/ITaskTrigger.cs
+++ b/MediaBrowser.Model/Tasks/ITaskTrigger.cs
@@ -21,10 +21,10 @@ namespace MediaBrowser.Model.Tasks
///
/// Stars waiting for the trigger action.
///
- /// Result of the last run triggerd task.
+ /// Result of the last run triggered task.
/// The .
/// The name of the task.
- /// Wheter or not this is is fired during startup.
+ /// Whether or not this is is fired during startup.
void Start(TaskResult? lastResult, ILogger logger, string taskName, bool isApplicationStartup);
///
diff --git a/MediaBrowser.Providers/Manager/ProviderManager.cs b/MediaBrowser.Providers/Manager/ProviderManager.cs
index 01ff473f0c..bbb33ddf0e 100644
--- a/MediaBrowser.Providers/Manager/ProviderManager.cs
+++ b/MediaBrowser.Providers/Manager/ProviderManager.cs
@@ -926,7 +926,7 @@ namespace MediaBrowser.Providers.Manager
}
catch (Exception ex)
{
- _logger.LogError(ex, "Error in {0}.Suports", i.GetType().Name);
+ _logger.LogError(ex, "Error in {0}.Supports", i.GetType().Name);
return false;
}
});
diff --git a/MediaBrowser.Providers/Plugins/MusicBrainz/MusicBrainzAlbumProvider.cs b/MediaBrowser.Providers/Plugins/MusicBrainz/MusicBrainzAlbumProvider.cs
index 4bf66c0988..915fb97fd2 100644
--- a/MediaBrowser.Providers/Plugins/MusicBrainz/MusicBrainzAlbumProvider.cs
+++ b/MediaBrowser.Providers/Plugins/MusicBrainz/MusicBrainzAlbumProvider.cs
@@ -36,7 +36,7 @@ namespace MediaBrowser.Providers.Music
///
/// The Jellyfin user-agent is unrestricted but source IP must not exceed
/// one request per second, therefore we rate limit to avoid throttling.
- /// Be prudent, use a value slightly above the minimun required.
+ /// Be prudent, use a value slightly above the minimum required.
/// https://musicbrainz.org/doc/XML_Web_Service/Rate_Limiting.
///
private readonly long _musicBrainzQueryIntervalMs;
diff --git a/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs b/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs
index 09ff84044d..da348239a1 100644
--- a/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs
+++ b/MediaBrowser.XbmcMetadata/Parsers/BaseNfoParser.cs
@@ -1330,7 +1330,7 @@ namespace MediaBrowser.XbmcMetadata.Parsers
};
///
- /// Used to split names of comma or pipe delimeted genres and people.
+ /// Used to split names of comma or pipe delimited genres and people.
///
/// The value.
/// IEnumerable{System.String}.
diff --git a/src/Jellyfin.Extensions/SplitStringExtensions.cs b/src/Jellyfin.Extensions/SplitStringExtensions.cs
index 1d1c377f56..a4dc9fc6b1 100644
--- a/src/Jellyfin.Extensions/SplitStringExtensions.cs
+++ b/src/Jellyfin.Extensions/SplitStringExtensions.cs
@@ -55,7 +55,7 @@ namespace Jellyfin.Extensions
public static Enumerator Split(this ReadOnlySpan str, char separator) => new(str, separator);
///
- /// Provides an enumerator for the substrings seperated by the separator.
+ /// Provides an enumerator for the substrings separated by the separator.
///
[StructLayout(LayoutKind.Auto)]
public ref struct Enumerator
diff --git a/src/Jellyfin.Extensions/StringExtensions.cs b/src/Jellyfin.Extensions/StringExtensions.cs
index dadc9f1d5c..59fb038a75 100644
--- a/src/Jellyfin.Extensions/StringExtensions.cs
+++ b/src/Jellyfin.Extensions/StringExtensions.cs
@@ -40,7 +40,7 @@ namespace Jellyfin.Extensions
}
///
- /// Checks wether or not the specified string has diacritics in it.
+ /// Checks whether or not the specified string has diacritics in it.
///
/// The string to check.
/// True if the string has diacritics, false otherwise.
diff --git a/tests/Jellyfin.Model.Tests/Cryptography/PasswordHashTests.cs b/tests/Jellyfin.Model.Tests/Cryptography/PasswordHashTests.cs
index 6948280a3d..162f53e567 100644
--- a/tests/Jellyfin.Model.Tests/Cryptography/PasswordHashTests.cs
+++ b/tests/Jellyfin.Model.Tests/Cryptography/PasswordHashTests.cs
@@ -152,9 +152,9 @@ namespace Jellyfin.Model.Tests.Cryptography
[InlineData("$PBKDF2$$62FBA410AFCA5B4475F35137AB2E8596B127E4D927BA23F6CC05C067E897042D")] // Empty segment
[InlineData("$PBKDF2$iterations=1000$$62FBA410AFCA5B4475F35137AB2E8596B127E4D927BA23F6CC05C067E897042D")] // Empty salt segment
[InlineData("$PBKDF2$iterations=1000$69F420$")] // Empty hash segment
- [InlineData("$PBKDF2$=$62FBA410AFCA5B4475F35137AB2E8596B127E4D927BA23F6CC05C067E897042D")] // Invalid parmeter
- [InlineData("$PBKDF2$=1000$62FBA410AFCA5B4475F35137AB2E8596B127E4D927BA23F6CC05C067E897042D")] // Invalid parmeter
- [InlineData("$PBKDF2$iterations=$62FBA410AFCA5B4475F35137AB2E8596B127E4D927BA23F6CC05C067E897042D")] // Invalid parmeter
+ [InlineData("$PBKDF2$=$62FBA410AFCA5B4475F35137AB2E8596B127E4D927BA23F6CC05C067E897042D")] // Invalid parameter
+ [InlineData("$PBKDF2$=1000$62FBA410AFCA5B4475F35137AB2E8596B127E4D927BA23F6CC05C067E897042D")] // Invalid parameter
+ [InlineData("$PBKDF2$iterations=$62FBA410AFCA5B4475F35137AB2E8596B127E4D927BA23F6CC05C067E897042D")] // Invalid parameter
[InlineData("$PBKDF2$iterations=1000$62FBA410AFCA5B4475F35137AB2E8596B127E4D927BA23F6CC05C067E897042D$")] // Ends on $
[InlineData("$PBKDF2$iterations=1000$69F420$62FBA410AFCA5B4475F35137AB2E8596B127E4D927BA23F6CC05C067E897042D$")] // Extra segment
[InlineData("$PBKDF2$iterations=1000$69F420$62FBA410AFCA5B4475F35137AB2E8596B127E4D927BA23F6CC05C067E897042D$anotherone")] // Extra segment
diff --git a/tests/Jellyfin.Networking.Tests/NetworkParseTests.cs b/tests/Jellyfin.Networking.Tests/NetworkParseTests.cs
index 6b93974373..52b0e5a955 100644
--- a/tests/Jellyfin.Networking.Tests/NetworkParseTests.cs
+++ b/tests/Jellyfin.Networking.Tests/NetworkParseTests.cs
@@ -393,7 +393,7 @@ namespace Jellyfin.Networking.Tests
// User on external network, internal binding only - so assumption is a proxy forward, return external override.
[InlineData("jellyfin.org", "192.168.1.0/24", "eth16", false, "0.0.0.0=http://helloworld.com", "http://helloworld.com")]
- // User on external network, no binding - so result is the 1st external which is overriden.
+ // User on external network, no binding - so result is the 1st external which is overridden.
[InlineData("jellyfin.org", "192.168.1.0/24", "", false, "0.0.0.0 = http://helloworld.com", "http://helloworld.com")]
// User assumed to be internal, no binding - so result is the 1st internal.
diff --git a/tests/Jellyfin.Server.Implementations.Tests/LiveTv/SchedulesDirect/SchedulesDirectDeserializeTests.cs b/tests/Jellyfin.Server.Implementations.Tests/LiveTv/SchedulesDirect/SchedulesDirectDeserializeTests.cs
index 3b3e38bd1f..e1d2bb2d58 100644
--- a/tests/Jellyfin.Server.Implementations.Tests/LiveTv/SchedulesDirect/SchedulesDirectDeserializeTests.cs
+++ b/tests/Jellyfin.Server.Implementations.Tests/LiveTv/SchedulesDirect/SchedulesDirectDeserializeTests.cs
@@ -18,7 +18,7 @@ namespace Jellyfin.Server.Implementations.Tests.LiveTv.SchedulesDirect
}
///
- /// /token reponse.
+ /// /token response.
///
[Fact]
public void Deserialize_Token_Response_Live_Success()
diff --git a/tests/Jellyfin.Server.Implementations.Tests/Test Data/Updates/manifest-stable.json b/tests/Jellyfin.Server.Implementations.Tests/Test Data/Updates/manifest-stable.json
index b766e668e3..fa8fbd8d2c 100644
--- a/tests/Jellyfin.Server.Implementations.Tests/Test Data/Updates/manifest-stable.json
+++ b/tests/Jellyfin.Server.Implementations.Tests/Test Data/Updates/manifest-stable.json
@@ -253,7 +253,7 @@
"versions": [
{
"version": "5.0.0.0",
- "changelog": "Updated to use NextPVR API v5, no longer compatable with API v4.\n",
+ "changelog": "Updated to use NextPVR API v5, no longer compatible with API v4.\n",
"targetAbi": "10.7.0.0",
"sourceUrl": "https://repo.jellyfin.org/releases/plugin/nextpvr/nextpvr_5.0.0.0.zip",
"checksum": "d70f694d14bf9462ba2b2ebe110068d3",
--
cgit v1.2.3
From 5036afd69127cc6f6b0801329b2b04f21aee71f5 Mon Sep 17 00:00:00 2001
From: Bond_009
Date: Fri, 12 Aug 2022 20:37:31 +0200
Subject: Minor cleanup
---
.../AppBase/BaseConfigurationManager.cs | 12 ++---------
Jellyfin.Api/Attributes/HttpSubscribeAttribute.cs | 7 +-----
.../Attributes/HttpUnsubscribeAttribute.cs | 7 +-----
.../Controllers/DisplayPreferencesController.cs | 7 ++----
Jellyfin.Drawing.Skia/SkiaEncoder.cs | 6 ++++--
.../Users/DisplayPreferencesManager.cs | 2 +-
.../SymlinkFollowingPhysicalFileResultExecutor.cs | 11 ++--------
.../Configuration/ConfigurationUpdateEventArgs.cs | 25 ++++++++++++++++------
.../Configuration/IApplicationPaths.cs | 2 --
.../Entities/BasePluginFolder.cs | 4 +---
MediaBrowser.Controller/Entities/Extensions.cs | 8 +++----
.../IDisplayPreferencesManager.cs | 6 ++----
12 files changed, 38 insertions(+), 59 deletions(-)
(limited to 'MediaBrowser.Controller')
diff --git a/Emby.Server.Implementations/AppBase/BaseConfigurationManager.cs b/Emby.Server.Implementations/AppBase/BaseConfigurationManager.cs
index 2a4a8fb132..c42cec593a 100644
--- a/Emby.Server.Implementations/AppBase/BaseConfigurationManager.cs
+++ b/Emby.Server.Implementations/AppBase/BaseConfigurationManager.cs
@@ -365,11 +365,7 @@ namespace Emby.Server.Implementations.AppBase
validatingStore.Validate(currentConfiguration, configuration);
}
- NamedConfigurationUpdating?.Invoke(this, new ConfigurationUpdateEventArgs
- {
- Key = key,
- NewConfiguration = configuration
- });
+ NamedConfigurationUpdating?.Invoke(this, new ConfigurationUpdateEventArgs(key, configuration));
_configurations.AddOrUpdate(key, configuration, (_, _) => configuration);
@@ -391,11 +387,7 @@ namespace Emby.Server.Implementations.AppBase
/// The old configuration.
protected virtual void OnNamedConfigurationUpdated(string key, object configuration)
{
- NamedConfigurationUpdated?.Invoke(this, new ConfigurationUpdateEventArgs
- {
- Key = key,
- NewConfiguration = configuration
- });
+ NamedConfigurationUpdated?.Invoke(this, new ConfigurationUpdateEventArgs(key, configuration));
}
///
diff --git a/Jellyfin.Api/Attributes/HttpSubscribeAttribute.cs b/Jellyfin.Api/Attributes/HttpSubscribeAttribute.cs
index af8727552c..7ac089a344 100644
--- a/Jellyfin.Api/Attributes/HttpSubscribeAttribute.cs
+++ b/Jellyfin.Api/Attributes/HttpSubscribeAttribute.cs
@@ -25,11 +25,6 @@ namespace Jellyfin.Api.Attributes
/// The route template. May not be null.
public HttpSubscribeAttribute(string template)
: base(_supportedMethods, template)
- {
- if (template == null)
- {
- throw new ArgumentNullException(nameof(template));
- }
- }
+ => ArgumentNullException.ThrowIfNull(template, nameof(template));
}
}
diff --git a/Jellyfin.Api/Attributes/HttpUnsubscribeAttribute.cs b/Jellyfin.Api/Attributes/HttpUnsubscribeAttribute.cs
index 1c0b70e719..16b3d08160 100644
--- a/Jellyfin.Api/Attributes/HttpUnsubscribeAttribute.cs
+++ b/Jellyfin.Api/Attributes/HttpUnsubscribeAttribute.cs
@@ -25,11 +25,6 @@ namespace Jellyfin.Api.Attributes
/// The route template. May not be null.
public HttpUnsubscribeAttribute(string template)
: base(_supportedMethods, template)
- {
- if (template == null)
- {
- throw new ArgumentNullException(nameof(template));
- }
- }
+ => ArgumentNullException.ThrowIfNull(template, nameof(template));
}
}
diff --git a/Jellyfin.Api/Controllers/DisplayPreferencesController.cs b/Jellyfin.Api/Controllers/DisplayPreferencesController.cs
index 27eb223390..64ee5680ce 100644
--- a/Jellyfin.Api/Controllers/DisplayPreferencesController.cs
+++ b/Jellyfin.Api/Controllers/DisplayPreferencesController.cs
@@ -89,12 +89,9 @@ namespace Jellyfin.Api.Controllers
// Load all custom display preferences
var customDisplayPreferences = _displayPreferencesManager.ListCustomItemDisplayPreferences(displayPreferences.UserId, itemId, displayPreferences.Client);
- if (customDisplayPreferences != null)
+ foreach (var (key, value) in customDisplayPreferences)
{
- foreach (var (key, value) in customDisplayPreferences)
- {
- dto.CustomPrefs.TryAdd(key, value);
- }
+ dto.CustomPrefs.TryAdd(key, value);
}
// This will essentially be a noop if no changes have been made, but new prefs must be saved at least.
diff --git a/Jellyfin.Drawing.Skia/SkiaEncoder.cs b/Jellyfin.Drawing.Skia/SkiaEncoder.cs
index 6875282318..13f155f357 100644
--- a/Jellyfin.Drawing.Skia/SkiaEncoder.cs
+++ b/Jellyfin.Drawing.Skia/SkiaEncoder.cs
@@ -145,9 +145,11 @@ namespace Jellyfin.Drawing.Skia
/// The file at the specified path could not be used to generate a codec.
public string GetImageBlurHash(int xComp, int yComp, string path)
{
- if (path == null)
+ ArgumentNullException.ThrowIfNull(path, nameof(path));
+
+ if (path.Length == 0)
{
- throw new ArgumentNullException(nameof(path));
+ throw new ArgumentException("String can't be empty", nameof(path));
}
var extension = Path.GetExtension(path.AsSpan()).TrimStart('.');
diff --git a/Jellyfin.Server.Implementations/Users/DisplayPreferencesManager.cs b/Jellyfin.Server.Implementations/Users/DisplayPreferencesManager.cs
index f5d38db20f..65edb30ad2 100644
--- a/Jellyfin.Server.Implementations/Users/DisplayPreferencesManager.cs
+++ b/Jellyfin.Server.Implementations/Users/DisplayPreferencesManager.cs
@@ -79,7 +79,7 @@ namespace Jellyfin.Server.Implementations.Users
}
///
- public void SetCustomItemDisplayPreferences(Guid userId, Guid itemId, string client, Dictionary customPreferences)
+ public void SetCustomItemDisplayPreferences(Guid userId, Guid itemId, string client, Dictionary customPreferences)
{
var existingPrefs = _dbContext.CustomItemDisplayPreferences
.AsQueryable()
diff --git a/Jellyfin.Server/Infrastructure/SymlinkFollowingPhysicalFileResultExecutor.cs b/Jellyfin.Server/Infrastructure/SymlinkFollowingPhysicalFileResultExecutor.cs
index 7e7e4ca95b..28ed3894fd 100644
--- a/Jellyfin.Server/Infrastructure/SymlinkFollowingPhysicalFileResultExecutor.cs
+++ b/Jellyfin.Server/Infrastructure/SymlinkFollowingPhysicalFileResultExecutor.cs
@@ -69,15 +69,8 @@ namespace Jellyfin.Server.Infrastructure
///
protected override Task WriteFileAsync(ActionContext context, PhysicalFileResult result, RangeItemHeaderValue? range, long rangeLength)
{
- if (context == null)
- {
- throw new ArgumentNullException(nameof(context));
- }
-
- if (result == null)
- {
- throw new ArgumentNullException(nameof(result));
- }
+ ArgumentNullException.ThrowIfNull(context, nameof(context));
+ ArgumentNullException.ThrowIfNull(result, nameof(result));
if (range != null && rangeLength == 0)
{
diff --git a/MediaBrowser.Common/Configuration/ConfigurationUpdateEventArgs.cs b/MediaBrowser.Common/Configuration/ConfigurationUpdateEventArgs.cs
index 2df87d8792..90b1ff70c2 100644
--- a/MediaBrowser.Common/Configuration/ConfigurationUpdateEventArgs.cs
+++ b/MediaBrowser.Common/Configuration/ConfigurationUpdateEventArgs.cs
@@ -1,22 +1,33 @@
-#nullable disable
-#pragma warning disable CS1591
-
using System;
namespace MediaBrowser.Common.Configuration
{
+ ///
+ /// for the ConfigurationUpdated event.
+ ///
public class ConfigurationUpdateEventArgs : EventArgs
{
///
- /// Gets or sets the key.
+ /// Initializes a new instance of the class.
+ ///
+ /// The configuration key.
+ /// The new configuration.
+ public ConfigurationUpdateEventArgs(string key, object newConfiguration)
+ {
+ Key = key;
+ NewConfiguration = newConfiguration;
+ }
+
+ ///
+ /// Gets the key.
///
/// The key.
- public string Key { get; set; }
+ public string Key { get; }
///
- /// Gets or sets the new configuration.
+ /// Gets the new configuration.
///
/// The new configuration.
- public object NewConfiguration { get; set; }
+ public object NewConfiguration { get; }
}
}
diff --git a/MediaBrowser.Common/Configuration/IApplicationPaths.cs b/MediaBrowser.Common/Configuration/IApplicationPaths.cs
index 1370e6d79e..57c6546675 100644
--- a/MediaBrowser.Common/Configuration/IApplicationPaths.cs
+++ b/MediaBrowser.Common/Configuration/IApplicationPaths.cs
@@ -1,5 +1,3 @@
-#nullable disable
-
namespace MediaBrowser.Common.Configuration
{
///
diff --git a/MediaBrowser.Controller/Entities/BasePluginFolder.cs b/MediaBrowser.Controller/Entities/BasePluginFolder.cs
index 272a37df1b..afafaf1c24 100644
--- a/MediaBrowser.Controller/Entities/BasePluginFolder.cs
+++ b/MediaBrowser.Controller/Entities/BasePluginFolder.cs
@@ -1,5 +1,3 @@
-#nullable disable
-
#pragma warning disable CS1591
using System.Text.Json.Serialization;
@@ -13,7 +11,7 @@ namespace MediaBrowser.Controller.Entities
public abstract class BasePluginFolder : Folder, ICollectionFolder
{
[JsonIgnore]
- public virtual string CollectionType => null;
+ public virtual string? CollectionType => null;
[JsonIgnore]
public override bool SupportsInheritedParentImages => false;
diff --git a/MediaBrowser.Controller/Entities/Extensions.cs b/MediaBrowser.Controller/Entities/Extensions.cs
index 9ce8eebe34..14534aa50b 100644
--- a/MediaBrowser.Controller/Entities/Extensions.cs
+++ b/MediaBrowser.Controller/Entities/Extensions.cs
@@ -1,5 +1,3 @@
-#nullable disable
-
using System;
using System.Linq;
using Jellyfin.Extensions;
@@ -19,9 +17,11 @@ namespace MediaBrowser.Controller.Entities
/// Trailer URL.
public static void AddTrailerUrl(this BaseItem item, string url)
{
- if (string.IsNullOrEmpty(url))
+ ArgumentNullException.ThrowIfNull(url, nameof(url));
+
+ if (url.Length == 0)
{
- throw new ArgumentNullException(nameof(url));
+ throw new ArgumentException("String can't be empty", nameof(url));
}
var current = item.RemoteTrailers.FirstOrDefault(i => string.Equals(i.Url, url, StringComparison.OrdinalIgnoreCase));
diff --git a/MediaBrowser.Controller/IDisplayPreferencesManager.cs b/MediaBrowser.Controller/IDisplayPreferencesManager.cs
index 1678d50675..10c0f56e09 100644
--- a/MediaBrowser.Controller/IDisplayPreferencesManager.cs
+++ b/MediaBrowser.Controller/IDisplayPreferencesManager.cs
@@ -1,5 +1,3 @@
-#nullable disable
-
using System;
using System.Collections.Generic;
using Jellyfin.Data.Entities;
@@ -50,7 +48,7 @@ namespace MediaBrowser.Controller
/// The item id.
/// The client string.
/// The dictionary of custom item display preferences.
- Dictionary ListCustomItemDisplayPreferences(Guid userId, Guid itemId, string client);
+ Dictionary ListCustomItemDisplayPreferences(Guid userId, Guid itemId, string client);
///
/// Sets the custom item display preference for the user and client.
@@ -59,7 +57,7 @@ namespace MediaBrowser.Controller
/// The item id.
/// The client id.
/// A dictionary of custom item display preferences.
- void SetCustomItemDisplayPreferences(Guid userId, Guid itemId, string client, Dictionary customPreferences);
+ void SetCustomItemDisplayPreferences(Guid userId, Guid itemId, string client, Dictionary customPreferences);
///
/// Saves changes made to the database.
--
cgit v1.2.3
From 61fa325ef05daac7c5105623d2de435ec94ef6a7 Mon Sep 17 00:00:00 2001
From: Shadowghost
Date: Mon, 28 Mar 2022 23:11:21 +0200
Subject: Extend music parsing
---
Emby.Naming/Common/NamingOptions.cs | 23 ++++
.../Library/Resolvers/Audio/MusicAlbumResolver.cs | 11 +-
.../Entities/Audio/MusicAlbum.cs | 2 +-
.../MediaBrowser.Providers.csproj | 1 +
.../MediaInfo/FFProbeAudioInfo.cs | 119 +++++++++-------
.../Music/AlbumMetadataService.cs | 152 +++++++++++++++++++--
.../Music/AudioMetadataService.cs | 40 ++++++
7 files changed, 287 insertions(+), 61 deletions(-)
(limited to 'MediaBrowser.Controller')
diff --git a/Emby.Naming/Common/NamingOptions.cs b/Emby.Naming/Common/NamingOptions.cs
index e016d7e51f..ddeec679d4 100644
--- a/Emby.Naming/Common/NamingOptions.cs
+++ b/Emby.Naming/Common/NamingOptions.cs
@@ -181,6 +181,24 @@ namespace Emby.Naming.Common
"volume"
};
+ ArtistSubfolders = new[]
+ {
+ "albums",
+ "broadcasts",
+ "bootlegs",
+ "compilations",
+ "dj-mixes",
+ "eps",
+ "live",
+ "mixtapes",
+ "others",
+ "remixes",
+ "singles",
+ "soundtracks",
+ "spokenwords",
+ "streets"
+ };
+
AudioFileExtensions = new[]
{
".669",
@@ -732,6 +750,11 @@ namespace Emby.Naming.Common
///
public string[] AlbumStackingPrefixes { get; set; }
+ ///
+ /// Gets or sets list of artist subfolders.
+ ///
+ public string[] ArtistSubfolders { get; set; }
+
///
/// Gets or sets list of subtitle file extensions.
///
diff --git a/Emby.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs b/Emby.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs
index da00b9cfa8..5e05ddfb16 100644
--- a/Emby.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs
+++ b/Emby.Server.Implementations/Library/Resolvers/Audio/MusicAlbumResolver.cs
@@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
+using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
@@ -98,7 +99,15 @@ namespace Emby.Server.Implementations.Library.Resolvers.Audio
// Args points to an album if parent is an Artist folder or it directly contains music
if (args.IsDirectory)
{
- // if (args.Parent is MusicArtist) return true; // saves us from testing children twice
+ foreach (var subfolder in _namingOptions.ArtistSubfolders)
+ {
+ if (Path.GetDirectoryName(args.Path.AsSpan()).Equals(subfolder, StringComparison.OrdinalIgnoreCase))
+ {
+ _logger.LogDebug("Found release folder: {Path}", args.Path);
+ return false;
+ }
+ }
+
if (ContainsMusic(args.FileSystemChildren, true, args.DirectoryService))
{
return true;
diff --git a/MediaBrowser.Controller/Entities/Audio/MusicAlbum.cs b/MediaBrowser.Controller/Entities/Audio/MusicAlbum.cs
index bd397bdd13..6555de8554 100644
--- a/MediaBrowser.Controller/Entities/Audio/MusicAlbum.cs
+++ b/MediaBrowser.Controller/Entities/Audio/MusicAlbum.cs
@@ -54,7 +54,7 @@ namespace MediaBrowser.Controller.Entities.Audio
public string AlbumArtist => AlbumArtists.FirstOrDefault();
[JsonIgnore]
- public override bool SupportsPeople => false;
+ public override bool SupportsPeople => true;
///
/// Gets the tracks.
diff --git a/MediaBrowser.Providers/MediaBrowser.Providers.csproj b/MediaBrowser.Providers/MediaBrowser.Providers.csproj
index 9864db9ac2..459045dffc 100644
--- a/MediaBrowser.Providers/MediaBrowser.Providers.csproj
+++ b/MediaBrowser.Providers/MediaBrowser.Providers.csproj
@@ -22,6 +22,7 @@
+
diff --git a/MediaBrowser.Providers/MediaInfo/FFProbeAudioInfo.cs b/MediaBrowser.Providers/MediaInfo/FFProbeAudioInfo.cs
index f22965436f..e801a20efb 100644
--- a/MediaBrowser.Providers/MediaInfo/FFProbeAudioInfo.cs
+++ b/MediaBrowser.Providers/MediaInfo/FFProbeAudioInfo.cs
@@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
+using System.Globalization;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
@@ -17,6 +18,7 @@ using MediaBrowser.Model.Dlna;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.MediaInfo;
+using TagLib;
namespace MediaBrowser.Providers.MediaInfo
{
@@ -93,7 +95,7 @@ namespace MediaBrowser.Providers.MediaInfo
// var extension = (Path.GetExtension(audio.Path) ?? string.Empty).TrimStart('.');
// audio.Container = extension;
- FetchDataFromTags(audio, mediaInfo);
+ FetchDataFromTags(audio);
_itemRepo.SaveMediaStreams(audio.Id, mediaInfo.MediaStreams, cancellationToken);
}
@@ -102,71 +104,90 @@ namespace MediaBrowser.Providers.MediaInfo
/// Fetches data from the tags dictionary.
///
/// The audio.
- /// The data.
- private void FetchDataFromTags(Audio audio, Model.MediaInfo.MediaInfo data)
+ private void FetchDataFromTags(Audio audio)
{
- // Only set Name if title was found in the dictionary
- if (!string.IsNullOrEmpty(data.Name))
+ var file = TagLib.File.Create(audio.Path);
+ var tagTypes = file.TagTypesOnDisk;
+ Tag tags = null;
+
+ if (tagTypes.HasFlag(TagTypes.Id3v2))
{
- audio.Name = data.Name;
+ tags = file.GetTag(TagTypes.Id3v2);
}
-
- if (!string.IsNullOrEmpty(data.ForcedSortName))
+ else if (tagTypes.HasFlag(TagTypes.Ape))
{
- audio.ForcedSortName = data.ForcedSortName;
+ tags = file.GetTag(TagTypes.Ape);
}
-
- if (audio.SupportsPeople && !audio.LockedFields.Contains(MetadataField.Cast))
+ else if (tagTypes.HasFlag(TagTypes.FlacMetadata))
{
- var people = new List();
+ tags = file.GetTag(TagTypes.FlacMetadata);
+ }
+ else if (tagTypes.HasFlag(TagTypes.Id3v1))
+ {
+ tags = file.GetTag(TagTypes.Id3v1);
+ }
- foreach (var person in data.People)
+ if (tags != null)
+ {
+ if (audio.SupportsPeople && !audio.LockedFields.Contains(MetadataField.Cast))
{
- PeopleHelper.AddPerson(people, new PersonInfo
+ var people = new List();
+ var albumArtists = tags.AlbumArtists;
+ foreach (var albumArtist in albumArtists)
{
- Name = person.Name,
- Type = person.Type,
- Role = person.Role
- });
- }
-
- _libraryManager.UpdatePeople(audio, people);
- }
+ PeopleHelper.AddPerson(people, new PersonInfo
+ {
+ Name = albumArtist,
+ Type = "AlbumArtist"
+ });
+ }
- audio.Album = data.Album;
- audio.Artists = data.Artists;
- audio.AlbumArtists = data.AlbumArtists;
- audio.IndexNumber = data.IndexNumber;
- audio.ParentIndexNumber = data.ParentIndexNumber;
- audio.ProductionYear = data.ProductionYear;
- audio.PremiereDate = data.PremiereDate;
+ var performers = tags.Performers;
+ foreach (var performer in performers)
+ {
+ PeopleHelper.AddPerson(people, new PersonInfo
+ {
+ Name = performer,
+ Type = "Artist"
+ });
+ }
- // If we don't have a ProductionYear try and get it from PremiereDate
- if (audio.PremiereDate.HasValue && !audio.ProductionYear.HasValue)
- {
- audio.ProductionYear = audio.PremiereDate.Value.ToLocalTime().Year;
- }
+ foreach (var composer in tags.Composers)
+ {
+ PeopleHelper.AddPerson(people, new PersonInfo
+ {
+ Name = composer,
+ Type = "Composer"
+ });
+ }
+
+ _libraryManager.UpdatePeople(audio, people);
+ audio.Artists = performers;
+ audio.AlbumArtists = albumArtists;
+ }
- if (!audio.LockedFields.Contains(MetadataField.Genres))
- {
- audio.Genres = Array.Empty();
+ audio.Name = tags.Title;
+ audio.Album = tags.Album;
+ audio.IndexNumber = Convert.ToInt32(tags.Track);
+ audio.ParentIndexNumber = Convert.ToInt32(tags.Disc);
+ if(tags.Year != 0)
+ {
+ var year = Convert.ToInt32(tags.Year);
+ audio.ProductionYear = year;
+ audio.PremiereDate = new DateTime(year, 01, 01);
+ }
- foreach (var genre in data.Genres)
+ if (!audio.LockedFields.Contains(MetadataField.Genres))
{
- audio.AddGenre(genre);
+ audio.Genres = tags.Genres.Distinct(StringComparer.OrdinalIgnoreCase).ToArray();
}
- }
- if (!audio.LockedFields.Contains(MetadataField.Studios))
- {
- audio.SetStudios(data.Studios);
+ audio.SetProviderId(MetadataProvider.MusicBrainzArtist, tags.MusicBrainzArtistId);
+ audio.SetProviderId(MetadataProvider.MusicBrainzAlbumArtist, tags.MusicBrainzReleaseArtistId);
+ audio.SetProviderId(MetadataProvider.MusicBrainzAlbum, tags.MusicBrainzReleaseId);
+ audio.SetProviderId(MetadataProvider.MusicBrainzReleaseGroup, tags.MusicBrainzReleaseGroupId);
+ audio.SetProviderId(MetadataProvider.MusicBrainzTrack, tags.MusicBrainzTrackId);
}
-
- audio.SetProviderId(MetadataProvider.MusicBrainzAlbumArtist, data.GetProviderId(MetadataProvider.MusicBrainzAlbumArtist));
- audio.SetProviderId(MetadataProvider.MusicBrainzArtist, data.GetProviderId(MetadataProvider.MusicBrainzArtist));
- audio.SetProviderId(MetadataProvider.MusicBrainzAlbum, data.GetProviderId(MetadataProvider.MusicBrainzAlbum));
- audio.SetProviderId(MetadataProvider.MusicBrainzReleaseGroup, data.GetProviderId(MetadataProvider.MusicBrainzReleaseGroup));
- audio.SetProviderId(MetadataProvider.MusicBrainzTrack, data.GetProviderId(MetadataProvider.MusicBrainzTrack));
}
}
}
diff --git a/MediaBrowser.Providers/Music/AlbumMetadataService.cs b/MediaBrowser.Providers/Music/AlbumMetadataService.cs
index 7743d3b27b..b8426f31c1 100644
--- a/MediaBrowser.Providers/Music/AlbumMetadataService.cs
+++ b/MediaBrowser.Providers/Music/AlbumMetadataService.cs
@@ -61,40 +61,61 @@ namespace MediaBrowser.Providers.Music
var songs = children.Cast
/// The args.
- /// true if [is music album] [the specified args]; otherwise, false.
+ /// true if [is music album] [the specified args], false otherwise.
private bool IsMusicAlbum(ItemResolveArgs args)
{
- // Args points to an album if parent is an Artist folder or it directly contains music
if (args.IsDirectory)
{
+ // If args is a artist subfolder it's not a music album
foreach (var subfolder in _namingOptions.ArtistSubfolders)
{
if (Path.GetDirectoryName(args.Path.AsSpan()).Equals(subfolder, StringComparison.OrdinalIgnoreCase))
@@ -108,6 +108,7 @@ namespace Emby.Server.Implementations.Library.Resolvers.Audio
}
}
+ // If args contains music it's a music album
if (ContainsMusic(args.FileSystemChildren, true, args.DirectoryService))
{
return true;
@@ -120,22 +121,23 @@ namespace Emby.Server.Implementations.Library.Resolvers.Audio
///
/// Determine if the supplied list contains what we should consider music.
///
+ /// true if the provided path list contains music, false otherwise.
private bool ContainsMusic(
ICollection list,
bool allowSubfolders,
IDirectoryService directoryService)
{
- // check for audio files before digging down into directories
+ // Check for audio files before digging down into directories
var foundAudioFile = list.Any(fileSystemInfo => !fileSystemInfo.IsDirectory && AudioFileParser.IsAudioFile(fileSystemInfo.FullName, _namingOptions));
if (foundAudioFile)
{
- // at least one audio file exists
+ // At least one audio file exists
return true;
}
if (!allowSubfolders)
{
- // not music since no audio file exists and we're not looking into subfolders
+ // Not music since no audio file exists and we're not looking into subfolders
return false;
}
diff --git a/Emby.Server.Implementations/Library/Resolvers/Audio/MusicArtistResolver.cs b/Emby.Server.Implementations/Library/Resolvers/Audio/MusicArtistResolver.cs
index b7c1724c07..2538c2b5b4 100644
--- a/Emby.Server.Implementations/Library/Resolvers/Audio/MusicArtistResolver.cs
+++ b/Emby.Server.Implementations/Library/Resolvers/Audio/MusicArtistResolver.cs
@@ -13,7 +13,7 @@ using Microsoft.Extensions.Logging;
namespace Emby.Server.Implementations.Library.Resolvers.Audio
{
///
- /// Class MusicArtistResolver.
+ /// The music artist resolver.
///
public class MusicArtistResolver : ItemResolver
{
@@ -23,8 +23,8 @@ namespace Emby.Server.Implementations.Library.Resolvers.Audio
///
/// Initializes a new instance of the class.
///
- /// The logger for the created instances.
- /// The naming options.
+ /// Instance of the interface.
+ /// The .
public MusicArtistResolver(
ILogger logger,
NamingOptions namingOptions)
@@ -40,10 +40,10 @@ namespace Emby.Server.Implementations.Library.Resolvers.Audio
public override ResolverPriority Priority => ResolverPriority.Second;
///
- /// Resolves the specified args.
+ /// Resolves the specified resolver arguments.
///
- /// The args.
- /// MusicArtist.
+ /// The resolver arguments.
+ /// A .
protected override MusicArtist Resolve(ItemResolveArgs args)
{
if (!args.IsDirectory)
@@ -82,23 +82,24 @@ namespace Emby.Server.Implementations.Library.Resolvers.Audio
var albumResolver = new MusicAlbumResolver(_logger, _namingOptions);
- // If we contain an album assume we are an artist folder
var directories = args.FileSystemChildren.Where(i => i.IsDirectory);
var result = Parallel.ForEach(directories, (fileSystemInfo, state) =>
{
+ // If we contain a artist subfolder assume we are an artist folder
foreach (var subfolder in _namingOptions.ArtistSubfolders)
{
if (fileSystemInfo.Name.Equals(subfolder, StringComparison.OrdinalIgnoreCase))
{
- // stop once we see a artist subfolder
+ // Stop once we see an artist subfolder
state.Stop();
}
}
+ // If we contain a music album assume we are an artist folder
if (albumResolver.IsMusicAlbum(fileSystemInfo.FullName, directoryService))
{
- // stop once we see a music album
+ // Stop once we see a music album
state.Stop();
}
});
diff --git a/MediaBrowser.Controller/Providers/ICustomMetadataProvider.cs b/MediaBrowser.Controller/Providers/ICustomMetadataProvider.cs
index 32a9cbef2e..14428df5b3 100644
--- a/MediaBrowser.Controller/Providers/ICustomMetadataProvider.cs
+++ b/MediaBrowser.Controller/Providers/ICustomMetadataProvider.cs
@@ -18,9 +18,9 @@ namespace MediaBrowser.Controller.Providers
/// Fetches the metadata asynchronously.
///
/// The item.
- /// The options.
- /// The cancellation token.
- /// Task{ItemUpdateType}.
+ /// The .
+ /// The .
+ /// A fetching the .
Task FetchAsync(TItemType item, MetadataRefreshOptions options, CancellationToken cancellationToken);
}
}
diff --git a/MediaBrowser.Providers/MediaInfo/AudioFileProber.cs b/MediaBrowser.Providers/MediaInfo/AudioFileProber.cs
index 2591e880f6..2b26b31379 100644
--- a/MediaBrowser.Providers/MediaInfo/AudioFileProber.cs
+++ b/MediaBrowser.Providers/MediaInfo/AudioFileProber.cs
@@ -1,7 +1,5 @@
#nullable disable
-#pragma warning disable CS1591
-
using System;
using System.Collections.Generic;
using System.Linq;
@@ -21,6 +19,9 @@ using TagLib;
namespace MediaBrowser.Providers.MediaInfo
{
+ ///
+ /// Probes audio files for metadata.
+ ///
public class AudioFileProber
{
private readonly IMediaEncoder _mediaEncoder;
@@ -28,6 +29,13 @@ namespace MediaBrowser.Providers.MediaInfo
private readonly ILibraryManager _libraryManager;
private readonly IMediaSourceManager _mediaSourceManager;
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Instance of the interface.
+ /// Instance of the interface.
+ /// Instance of the interface.
+ /// Instance of the interface.
public AudioFileProber(
IMediaSourceManager mediaSourceManager,
IMediaEncoder mediaEncoder,
@@ -40,6 +48,14 @@ namespace MediaBrowser.Providers.MediaInfo
_mediaSourceManager = mediaSourceManager;
}
+ ///
+ /// Probes the specified item for metadata.
+ ///
+ /// The item to probe.
+ /// The .
+ /// The .
+ /// The type of item to resolve.
+ /// A probing the item for metadata.
public async Task Probe(
T item,
MetadataRefreshOptions options,
@@ -80,9 +96,9 @@ namespace MediaBrowser.Providers.MediaInfo
///
/// Fetches the specified audio.
///
- /// The audio.
- /// The media information.
- /// The cancellation token.
+ /// The .
+ /// The .
+ /// The .
protected void Fetch(Audio audio, Model.MediaInfo.MediaInfo mediaInfo, CancellationToken cancellationToken)
{
audio.Container = mediaInfo.Container;
@@ -91,18 +107,15 @@ namespace MediaBrowser.Providers.MediaInfo
audio.RunTimeTicks = mediaInfo.RunTimeTicks;
audio.Size = mediaInfo.Size;
- // var extension = (Path.GetExtension(audio.Path) ?? string.Empty).TrimStart('.');
- // audio.Container = extension;
-
FetchDataFromTags(audio);
_itemRepo.SaveMediaStreams(audio.Id, mediaInfo.MediaStreams, cancellationToken);
}
///
- /// Fetches data from the tags dictionary.
+ /// Fetches data from the tags.
///
- /// The audio.
+ /// The .
private void FetchDataFromTags(Audio audio)
{
var file = TagLib.File.Create(audio.Path);
diff --git a/MediaBrowser.Providers/MediaInfo/ProbeProvider.cs b/MediaBrowser.Providers/MediaInfo/ProbeProvider.cs
index 54c12a8f17..6591366076 100644
--- a/MediaBrowser.Providers/MediaInfo/ProbeProvider.cs
+++ b/MediaBrowser.Providers/MediaInfo/ProbeProvider.cs
@@ -1,7 +1,5 @@
#nullable disable
-#pragma warning disable CS1591
-
using System;
using System.IO;
using System.Linq;
@@ -27,6 +25,9 @@ using Microsoft.Extensions.Logging;
namespace MediaBrowser.Providers.MediaInfo
{
+ ///
+ /// The probe provider.
+ ///
public class ProbeProvider : ICustomMetadataProvider,
ICustomMetadataProvider,
ICustomMetadataProvider,
@@ -46,6 +47,22 @@ namespace MediaBrowser.Providers.MediaInfo
private readonly AudioFileProber _audioProber;
private readonly Task _cachedTask = Task.FromResult(ItemUpdateType.None);
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Instance of the interface.
+ /// Instance of the interface.
+ /// Instance of the interface.
+ /// Instance of the interface.
+ /// Instance of the interface.
+ /// Instance of the interface.
+ /// Instance of the interface.
+ /// Instance of the interface.
+ /// Instance of the interface.
+ /// Instance of the interface.
+ /// Instance of the .
+ /// Instance of the interface.
+ /// The .
public ProbeProvider(
IMediaSourceManager mediaSourceManager,
IMediaEncoder mediaEncoder,
@@ -81,11 +98,13 @@ namespace MediaBrowser.Providers.MediaInfo
_subtitleResolver);
}
- public string Name => "filemetadataprober";
+ ///
+ public string Name => "Probe Provider";
- // Run last
+ ///
public int Order => 100;
+ ///
public bool HasChanged(BaseItem item, IDirectoryService directoryService)
{
var video = item as Video;
@@ -127,41 +146,56 @@ namespace MediaBrowser.Providers.MediaInfo
return false;
}
+ ///
public Task FetchAsync(Episode item, MetadataRefreshOptions options, CancellationToken cancellationToken)
{
return FetchVideoInfo(item, options, cancellationToken);
}
+ ///
public Task FetchAsync(MusicVideo item, MetadataRefreshOptions options, CancellationToken cancellationToken)
{
return FetchVideoInfo(item, options, cancellationToken);
}
+ ///
public Task FetchAsync(Movie item, MetadataRefreshOptions options, CancellationToken cancellationToken)
{
return FetchVideoInfo(item, options, cancellationToken);
}
+ ///
public Task FetchAsync(Trailer item, MetadataRefreshOptions options, CancellationToken cancellationToken)
{
return FetchVideoInfo(item, options, cancellationToken);
}
+ ///
public Task FetchAsync(Video item, MetadataRefreshOptions options, CancellationToken cancellationToken)
{
return FetchVideoInfo(item, options, cancellationToken);
}
+ ///
public Task FetchAsync(Audio item, MetadataRefreshOptions options, CancellationToken cancellationToken)
{
return FetchAudioInfo(item, options, cancellationToken);
}
+ ///
public Task FetchAsync(AudioBook item, MetadataRefreshOptions options, CancellationToken cancellationToken)
{
return FetchAudioInfo(item, options, cancellationToken);
}
+ ///
+ /// Fetches video information for an item.
+ ///
+ /// The item.
+ /// The .
+ /// The .
+ /// The type of item to resolve.
+ /// A fetching the for an item.
public Task FetchVideoInfo(T item, MetadataRefreshOptions options, CancellationToken cancellationToken)
where T : Video
{
@@ -208,6 +242,14 @@ namespace MediaBrowser.Providers.MediaInfo
.FirstOrDefault(i => !string.IsNullOrWhiteSpace(i) && !i.StartsWith('#'));
}
+ ///
+ /// Fetches audio information for an item.
+ ///
+ /// The item.
+ /// The .
+ /// The .
+ /// The type of item to resolve.
+ /// A fetching the for an item.
public Task FetchAudioInfo(T item, MetadataRefreshOptions options, CancellationToken cancellationToken)
where T : Audio
{
diff --git a/MediaBrowser.Providers/Music/AlbumMetadataService.cs b/MediaBrowser.Providers/Music/AlbumMetadataService.cs
index b8426f31c1..1a8e20be32 100644
--- a/MediaBrowser.Providers/Music/AlbumMetadataService.cs
+++ b/MediaBrowser.Providers/Music/AlbumMetadataService.cs
@@ -1,5 +1,3 @@
-#pragma warning disable CS1591
-
using System;
using System.Collections.Generic;
using System.Linq;
@@ -15,8 +13,19 @@ using Microsoft.Extensions.Logging;
namespace MediaBrowser.Providers.Music
{
+ ///
+ /// The album metadata service.
+ ///
public class AlbumMetadataService : MetadataService
{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Instance of the .
+ /// Instance of the interface.
+ /// Instance of the interface.
+ /// Instance of the interface.
+ /// Instance of the interface.
public AlbumMetadataService(
IServerConfigurationManager serverConfigurationManager,
ILogger logger,
diff --git a/MediaBrowser.Providers/Music/AudioMetadataService.cs b/MediaBrowser.Providers/Music/AudioMetadataService.cs
index 64f40ef49f..7c38d0bcf5 100644
--- a/MediaBrowser.Providers/Music/AudioMetadataService.cs
+++ b/MediaBrowser.Providers/Music/AudioMetadataService.cs
@@ -1,5 +1,3 @@
-#pragma warning disable CS1591
-
using System;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities.Audio;
@@ -12,8 +10,19 @@ using Microsoft.Extensions.Logging;
namespace MediaBrowser.Providers.Music
{
+ ///
+ /// The audio metadata service.
+ ///
public class AudioMetadataService : MetadataService
{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Instance of the .
+ /// Instance of the interface.
+ /// Instance of the interface.
+ /// Instance of the interface.
+ /// Instance of the interface.
public AudioMetadataService(
IServerConfigurationManager serverConfigurationManager,
ILogger logger,
--
cgit v1.2.3
From c71d6f2358ba8a5b1f80a2bef41b6f438c06d03c Mon Sep 17 00:00:00 2001
From: Zach Phelan
Date: Tue, 13 Sep 2022 16:40:47 -0600
Subject: Sort special features same as other spots, removing unnecssary
function
Added to contributors
---
CONTRIBUTORS.md | 1 +
Jellyfin.Api/Controllers/UserLibraryController.cs | 3 ++-
MediaBrowser.Controller/Entities/BaseItem.cs | 13 -------------
3 files changed, 3 insertions(+), 14 deletions(-)
(limited to 'MediaBrowser.Controller')
diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md
index 98acd4449f..8daaae4d94 100644
--- a/CONTRIBUTORS.md
+++ b/CONTRIBUTORS.md
@@ -148,6 +148,7 @@
- [xosdy](https://github.com/xosdy)
- [XVicarious](https://github.com/XVicarious)
- [YouKnowBlom](https://github.com/YouKnowBlom)
+ - [ZachPhelan](https://github.com/ZachPhelan)
- [KristupasSavickas](https://github.com/KristupasSavickas)
- [Pusta](https://github.com/pusta)
- [nielsvanvelzen](https://github.com/nielsvanvelzen)
diff --git a/Jellyfin.Api/Controllers/UserLibraryController.cs b/Jellyfin.Api/Controllers/UserLibraryController.cs
index 1656a1e98c..940fa27a70 100644
--- a/Jellyfin.Api/Controllers/UserLibraryController.cs
+++ b/Jellyfin.Api/Controllers/UserLibraryController.cs
@@ -233,7 +233,8 @@ namespace Jellyfin.Api.Controllers
var dtoOptions = new DtoOptions().AddClientFields(Request);
return Ok(item
- .GetExtras(BaseItem.DisplayExtraTypes)
+ .GetExtras()
+ .Where(i => i.ExtraType.HasValue && BaseItem.DisplayExtraTypes.Contains(i.ExtraType.Value))
.Select(i => _dtoService.GetBaseItemDto(i, dtoOptions, user, item)));
}
diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs
index 5cee6ce406..988d0a534a 100644
--- a/MediaBrowser.Controller/Entities/BaseItem.cs
+++ b/MediaBrowser.Controller/Entities/BaseItem.cs
@@ -2606,19 +2606,6 @@ namespace MediaBrowser.Controller.Entities
.OrderBy(i => i.SortName);
}
- ///
- /// Get all extras with specific types that are associated with this item.
- ///
- /// The types of extras to retrieve.
- /// An enumerable containing the extras.
- public IEnumerable GetExtras(IReadOnlyCollection extraTypes)
- {
- return ExtraIds
- .Select(LibraryManager.GetItemById)
- .Where(i => i != null)
- .Where(i => i.ExtraType.HasValue && extraTypes.Contains(i.ExtraType.Value));
- }
-
public virtual long GetRunTimeTicksForPlayState()
{
return RunTimeTicks ?? 0;
--
cgit v1.2.3
From 8857edb66cbc0260981aa1aa3542da495e1b2443 Mon Sep 17 00:00:00 2001
From: Zach Phelan
Date: Tue, 13 Sep 2022 17:13:02 -0600
Subject: Add function back for compatibility, add sorting
---
MediaBrowser.Controller/Entities/BaseItem.cs | 14 ++++++++++++++
1 file changed, 14 insertions(+)
(limited to 'MediaBrowser.Controller')
diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs
index 988d0a534a..9461b01e31 100644
--- a/MediaBrowser.Controller/Entities/BaseItem.cs
+++ b/MediaBrowser.Controller/Entities/BaseItem.cs
@@ -2606,6 +2606,20 @@ namespace MediaBrowser.Controller.Entities
.OrderBy(i => i.SortName);
}
+ ///
+ /// Get all extras with specific types that are associated with this item.
+ ///
+ /// The types of extras to retrieve.
+ /// An enumerable containing the extras.
+ public IEnumerable GetExtras(IReadOnlyCollection extraTypes)
+ {
+ return ExtraIds
+ .Select(LibraryManager.GetItemById)
+ .Where(i => i != null)
+ .Where(i => i.ExtraType.HasValue && extraTypes.Contains(i.ExtraType.Value))
+ .OrderBy(i => i.SortName);
+ }
+
public virtual long GetRunTimeTicksForPlayState()
{
return RunTimeTicks ?? 0;
--
cgit v1.2.3
From d9be3874ba3842d5888c5cbbe583614ed990849e Mon Sep 17 00:00:00 2001
From: 1hitsong <3330318+1hitsong@users.noreply.github.com>
Date: Thu, 15 Sep 2022 19:45:26 -0400
Subject: Auto stash before merge of "lyric-lrc-file-support" and
"origin/lyric-lrc-file-support"
---
Emby.Server.Implementations/ApplicationHost.cs | 2 +
Emby.Server.Implementations/Dto/DtoService.cs | 9 +-
Jellyfin.Api/Controllers/UserLibraryController.cs | 5 +-
Jellyfin.Api/Helpers/ItemHelper.cs | 106 -------------------
Jellyfin.Api/Jellyfin.Api.csproj | 1 -
Jellyfin.Api/Models/UserDtos/ILyricsProvider.cs | 34 ------
Jellyfin.Api/Models/UserDtos/LrcLyricsProvider.cs | 117 ---------------------
Jellyfin.Api/Models/UserDtos/Lyric.cs | 18 ----
Jellyfin.Api/Models/UserDtos/TxtLyricsProvider.cs | 81 --------------
MediaBrowser.Controller/Lyrics/ILyricsProvider.cs | 24 +++++
MediaBrowser.Controller/Lyrics/Lyric.cs | 18 ++++
MediaBrowser.Controller/Lyrics/LyricInfo.cs | 87 +++++++++++++++
MediaBrowser.Controller/Lyrics/LyricResponse.cs | 15 +++
MediaBrowser.Model/Dto/BaseItemDto.cs | 2 +-
MediaBrowser.Providers/Lyric/LrcLyricsProvider.cs | 112 ++++++++++++++++++++
MediaBrowser.Providers/Lyric/TxtLyricsProvider.cs | 74 +++++++++++++
.../MediaBrowser.Providers.csproj | 2 +
17 files changed, 345 insertions(+), 362 deletions(-)
delete mode 100644 Jellyfin.Api/Helpers/ItemHelper.cs
delete mode 100644 Jellyfin.Api/Models/UserDtos/ILyricsProvider.cs
delete mode 100644 Jellyfin.Api/Models/UserDtos/LrcLyricsProvider.cs
delete mode 100644 Jellyfin.Api/Models/UserDtos/Lyric.cs
delete mode 100644 Jellyfin.Api/Models/UserDtos/TxtLyricsProvider.cs
create mode 100644 MediaBrowser.Controller/Lyrics/ILyricsProvider.cs
create mode 100644 MediaBrowser.Controller/Lyrics/Lyric.cs
create mode 100644 MediaBrowser.Controller/Lyrics/LyricInfo.cs
create mode 100644 MediaBrowser.Controller/Lyrics/LyricResponse.cs
create mode 100644 MediaBrowser.Providers/Lyric/LrcLyricsProvider.cs
create mode 100644 MediaBrowser.Providers/Lyric/TxtLyricsProvider.cs
(limited to 'MediaBrowser.Controller')
diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs
index 3e9c540e7b..5487e5e023 100644
--- a/Emby.Server.Implementations/ApplicationHost.cs
+++ b/Emby.Server.Implementations/ApplicationHost.cs
@@ -68,6 +68,7 @@ using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.LiveTv;
+using MediaBrowser.Controller.Lyrics;
using MediaBrowser.Controller.MediaEncoding;
using MediaBrowser.Controller.Net;
using MediaBrowser.Controller.Notifications;
@@ -95,6 +96,7 @@ using MediaBrowser.Model.Serialization;
using MediaBrowser.Model.System;
using MediaBrowser.Model.Tasks;
using MediaBrowser.Providers.Chapters;
+using MediaBrowser.Providers.Lyric;
using MediaBrowser.Providers.Manager;
using MediaBrowser.Providers.Plugins.Tmdb;
using MediaBrowser.Providers.Subtitles;
diff --git a/Emby.Server.Implementations/Dto/DtoService.cs b/Emby.Server.Implementations/Dto/DtoService.cs
index 96717cff53..bed82a4bbb 100644
--- a/Emby.Server.Implementations/Dto/DtoService.cs
+++ b/Emby.Server.Implementations/Dto/DtoService.cs
@@ -19,6 +19,7 @@ using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.LiveTv;
+using MediaBrowser.Controller.Lyrics;
using MediaBrowser.Controller.Persistence;
using MediaBrowser.Controller.Playlists;
using MediaBrowser.Controller.Providers;
@@ -51,6 +52,8 @@ namespace Emby.Server.Implementations.Dto
private readonly IMediaSourceManager _mediaSourceManager;
private readonly Lazy _livetvManagerFactory;
+ private readonly IEnumerable _lyricProviders;
+
public DtoService(
ILogger logger,
ILibraryManager libraryManager,
@@ -60,7 +63,8 @@ namespace Emby.Server.Implementations.Dto
IProviderManager providerManager,
IApplicationHost appHost,
IMediaSourceManager mediaSourceManager,
- Lazy livetvManagerFactory)
+ Lazy livetvManagerFactory,
+ IEnumerable lyricProviders)
{
_logger = logger;
_libraryManager = libraryManager;
@@ -71,6 +75,7 @@ namespace Emby.Server.Implementations.Dto
_appHost = appHost;
_mediaSourceManager = mediaSourceManager;
_livetvManagerFactory = livetvManagerFactory;
+ _lyricProviders = lyricProviders;
}
private ILiveTvManager LivetvManager => _livetvManagerFactory.Value;
@@ -142,7 +147,7 @@ namespace Emby.Server.Implementations.Dto
}
else if (item is Audio)
{
- dto.HasLocalLyricsFile = ItemHelper.HasLyricFile(item.Path);
+ dto.HasLyrics = MediaBrowser.Controller.Lyrics.LyricInfo.HasLyricFile(_lyricProviders, item.Path);
}
if (item is IItemByName itemByName
diff --git a/Jellyfin.Api/Controllers/UserLibraryController.cs b/Jellyfin.Api/Controllers/UserLibraryController.cs
index 123c5e0795..3da78c1169 100644
--- a/Jellyfin.Api/Controllers/UserLibraryController.cs
+++ b/Jellyfin.Api/Controllers/UserLibraryController.cs
@@ -13,6 +13,7 @@ using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Library;
+using MediaBrowser.Controller.Lyrics;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
@@ -414,8 +415,8 @@ namespace Jellyfin.Api.Controllers
return NotFound();
}
- // Super nieve implementation. I would suggest building a lyric service of some sort and doing this there.
- foreach (var provider in _lyricProviders)
+ var result = MediaBrowser.Controller.Lyrics.LyricInfo.GetLyricData(_lyricProviders, item);
+ if (result is not null)
{
provider.Process(item);
if (provider.HasData)
diff --git a/Jellyfin.Api/Helpers/ItemHelper.cs b/Jellyfin.Api/Helpers/ItemHelper.cs
deleted file mode 100644
index 49bb8af8e3..0000000000
--- 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
-{
- ///
- /// Item helper.
- ///
- public static class ItemHelper
- {
- ///
- /// Opens lyrics file, converts to a List of Lyrics, and returns it.
- ///
- /// Requested Item.
- /// Collection of Lyrics.
- 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;
- }
-
- ///
- /// Checks if requested item has a matching lyric file.
- ///
- /// Path of requested item.
- /// True if item has a matching lyrics file.
- 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;
- }
-
-
- ///
- /// Checks if requested item has a matching local lyric file.
- ///
- /// Path of requested item.
- /// True if item has a matching lyrics file; otherwise false.
- public static bool HasLyricFile(string itemPath)
- {
- string? lyricFilePath = GetLyricFilePath(itemPath);
- return !string.IsNullOrEmpty(lyricFilePath);
- }
- }
-}
diff --git a/Jellyfin.Api/Jellyfin.Api.csproj b/Jellyfin.Api/Jellyfin.Api.csproj
index 972387e02a..894d871383 100644
--- a/Jellyfin.Api/Jellyfin.Api.csproj
+++ b/Jellyfin.Api/Jellyfin.Api.csproj
@@ -17,7 +17,6 @@
-
diff --git a/Jellyfin.Api/Models/UserDtos/ILyricsProvider.cs b/Jellyfin.Api/Models/UserDtos/ILyricsProvider.cs
deleted file mode 100644
index 37f1f5bbe4..0000000000
--- a/Jellyfin.Api/Models/UserDtos/ILyricsProvider.cs
+++ /dev/null
@@ -1,34 +0,0 @@
-using System.Collections.ObjectModel;
-using MediaBrowser.Controller.Entities;
-
-namespace Jellyfin.Api.Models.UserDtos
-{
- ///
- /// Interface ILyricsProvider.
- ///
- public interface ILyricsProvider
- {
- ///
- /// Gets a value indicating the File Extenstions this provider works with.
- ///
- public Collection? FileExtensions { get; }
-
- ///
- /// Gets a value indicating whether Process() generated data.
- ///
- /// true if data generated; otherwise, false.
- bool HasData { get; }
-
- ///
- /// Gets Data object generated by Process() method.
- ///
- /// Object with data if no error occured; otherwise, null.
- object? Data { get; }
-
- ///
- /// Opens lyric file for [the specified item], and processes it for API return.
- ///
- /// The item to to process.
- void Process(BaseItem item);
- }
-}
diff --git a/Jellyfin.Api/Models/UserDtos/LrcLyricsProvider.cs b/Jellyfin.Api/Models/UserDtos/LrcLyricsProvider.cs
deleted file mode 100644
index 029acd6ca5..0000000000
--- a/Jellyfin.Api/Models/UserDtos/LrcLyricsProvider.cs
+++ /dev/null
@@ -1,117 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.Dynamic;
-using System.Globalization;
-using System.Linq;
-using LrcParser.Model;
-using LrcParser.Parser;
-using MediaBrowser.Controller.Entities;
-
-namespace Jellyfin.Api.Models.UserDtos
-{
- ///
- /// LRC File Lyric Provider.
- ///
- public class LrcLyricsProvider : ILyricsProvider
- {
- ///
- /// Initializes a new instance of the class.
- ///
- public LrcLyricsProvider()
- {
- FileExtensions = new Collection
- {
- "lrc"
- };
- }
-
- ///
- /// Gets a value indicating the File Extenstions this provider works with.
- ///
- public Collection? FileExtensions { get; }
-
- ///
- /// Gets or Sets a value indicating whether Process() generated data.
- ///
- /// true if data generated; otherwise, false.
- public bool HasData { get; set; }
-
- ///
- /// Gets or Sets Data object generated by Process() method.
- ///
- /// Object with data if no error occured; otherwise, null.
- public object? Data { get; set; }
-
- ///
- /// Opens lyric file for [the specified item], and processes it for API return.
- ///
- /// The item to to process.
- public void Process(BaseItem item)
- {
- string? lyricFilePath = Helpers.ItemHelper.GetLyricFilePath(item.Path);
-
- if (string.IsNullOrEmpty(lyricFilePath))
- {
- return;
- }
-
- List lyricsList = new List();
-
- List sortedLyricData = new List();
- var metaData = new ExpandoObject() as IDictionary;
- string lrcFileContent = System.IO.File.ReadAllText(lyricFilePath);
-
- 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.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(":");
-
- string metaDataFieldName = metaDataField[0].Replace("[", string.Empty, StringComparison.Ordinal);
- string metaDataFieldValue = metaDataField[1].Replace("]", string.Empty, StringComparison.Ordinal);
-
- metaData.Add(metaDataFieldName, metaDataFieldValue);
- }
- }
- catch
- {
- return;
- }
-
- if (!sortedLyricData.Any())
- {
- return;
- }
-
- for (int i = 0; i < sortedLyricData.Count; i++)
- {
- var timeData = sortedLyricData[i].TimeTags.ToArray()[0].Value;
- double ticks = Convert.ToDouble(timeData, new NumberFormatInfo()) * 10000;
- lyricsList.Add(new Lyric { Start = Math.Ceiling(ticks), Text = sortedLyricData[i].Text });
- }
-
- this.HasData = true;
- if (metaData.Any())
- {
- this.Data = new { MetaData = metaData, lyrics = lyricsList };
- }
- else
- {
- this.Data = new { lyrics = lyricsList };
- }
- }
- }
-}
diff --git a/Jellyfin.Api/Models/UserDtos/Lyric.cs b/Jellyfin.Api/Models/UserDtos/Lyric.cs
deleted file mode 100644
index f83fc9839b..0000000000
--- a/Jellyfin.Api/Models/UserDtos/Lyric.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-namespace Jellyfin.Api.Models.UserDtos
-{
- ///
- /// Lyric dto.
- ///
- public class Lyric
- {
- ///
- /// Gets or sets the start time (ticks).
- ///
- public double? Start { get; set; }
-
- ///
- /// Gets or sets the text.
- ///
- public string Text { get; set; } = string.Empty;
- }
-}
diff --git a/Jellyfin.Api/Models/UserDtos/TxtLyricsProvider.cs b/Jellyfin.Api/Models/UserDtos/TxtLyricsProvider.cs
deleted file mode 100644
index 03cce1ffbb..0000000000
--- a/Jellyfin.Api/Models/UserDtos/TxtLyricsProvider.cs
+++ /dev/null
@@ -1,81 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.Dynamic;
-using System.Globalization;
-using System.Linq;
-using LrcParser.Model;
-using LrcParser.Parser;
-using MediaBrowser.Controller.Entities;
-
-namespace Jellyfin.Api.Models.UserDtos
-{
- ///
- /// TXT File Lyric Provider.
- ///
- public class TxtLyricsProvider : ILyricsProvider
- {
- ///
- /// Initializes a new instance of the class.
- ///
- public TxtLyricsProvider()
- {
- FileExtensions = new Collection
- {
- "lrc", "txt"
- };
- }
-
- ///
- /// Gets a value indicating the File Extenstions this provider works with.
- ///
- public Collection? FileExtensions { get; }
-
- ///
- /// Gets or Sets a value indicating whether Process() generated data.
- ///
- /// true if data generated; otherwise, false.
- public bool HasData { get; set; }
-
- ///
- /// Gets or Sets Data object generated by Process() method.
- ///
- /// Object with data if no error occured; otherwise, null.
- public object? Data { get; set; }
-
- ///
- /// Opens lyric file for [the specified item], and processes it for API return.
- ///
- /// The item to to process.
- public void Process(BaseItem item)
- {
- string? lyricFilePath = Helpers.ItemHelper.GetLyricFilePath(item.Path);
-
- if (string.IsNullOrEmpty(lyricFilePath))
- {
- return;
- }
-
- List lyricsList = new List();
-
- string lyricData = System.IO.File.ReadAllText(lyricFilePath);
-
- // 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);
-
- if (!lyricTextLines.Any())
- {
- return;
- }
-
- foreach (string lyricLine in lyricTextLines)
- {
- lyricsList.Add(new Lyric { Text = lyricLine });
- }
-
- this.HasData = true;
- this.Data = new { lyrics = lyricsList };
- }
- }
-}
diff --git a/MediaBrowser.Controller/Lyrics/ILyricsProvider.cs b/MediaBrowser.Controller/Lyrics/ILyricsProvider.cs
new file mode 100644
index 0000000000..bac32a398a
--- /dev/null
+++ b/MediaBrowser.Controller/Lyrics/ILyricsProvider.cs
@@ -0,0 +1,24 @@
+using System.Collections.Generic;
+using MediaBrowser.Controller.Entities;
+
+namespace MediaBrowser.Controller.Lyrics
+{
+ ///
+ /// Interface ILyricsProvider.
+ ///
+ public interface ILyricsProvider
+ {
+ ///
+ /// Gets the supported media types for this provider.
+ ///
+ /// The supported media types.
+ IEnumerable SupportedMediaTypes { get; }
+
+ ///
+ /// Gets the lyrics.
+ ///
+ /// The item to to process.
+ /// Task{LyricResponse}.
+ LyricResponse? GetLyrics(BaseItem item);
+ }
+}
diff --git a/MediaBrowser.Controller/Lyrics/Lyric.cs b/MediaBrowser.Controller/Lyrics/Lyric.cs
new file mode 100644
index 0000000000..d44546dd39
--- /dev/null
+++ b/MediaBrowser.Controller/Lyrics/Lyric.cs
@@ -0,0 +1,18 @@
+namespace MediaBrowser.Controller.Lyrics
+{
+ ///
+ /// Lyric dto.
+ ///
+ public class Lyric
+ {
+ ///
+ /// Gets or sets the start time (ticks).
+ ///
+ public double? Start { get; set; }
+
+ ///
+ /// Gets or sets the text.
+ ///
+ public string Text { get; set; } = string.Empty;
+ }
+}
diff --git a/MediaBrowser.Controller/Lyrics/LyricInfo.cs b/MediaBrowser.Controller/Lyrics/LyricInfo.cs
new file mode 100644
index 0000000000..83a10701a2
--- /dev/null
+++ b/MediaBrowser.Controller/Lyrics/LyricInfo.cs
@@ -0,0 +1,87 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Threading.Tasks;
+using MediaBrowser.Controller.Entities;
+using MediaBrowser.Controller.Lyrics;
+using MediaBrowser.Controller.Net;
+using Microsoft.AspNetCore.Mvc;
+
+namespace MediaBrowser.Controller.Lyrics
+{
+ ///
+ /// Item helper.
+ ///
+ public class LyricInfo
+ {
+ ///
+ /// Opens lyrics file, converts to a List of Lyrics, and returns it.
+ ///
+ /// Collection of all registered interfaces.
+ /// Requested Item.
+ /// Collection of Lyrics.
+ public static LyricResponse? GetLyricData(IEnumerable lyricProviders, BaseItem item)
+ {
+
+ foreach (var provider in lyricProviders)
+ {
+ var result = provider.GetLyrics(item);
+ if (result is not null)
+ {
+ return result;
+ }
+ }
+
+ return new LyricResponse
+ {
+ Lyrics = new List
+ {
+ new Lyric { Start = 0, Text = "Test" }
+ }
+ };
+ }
+
+ ///
+ /// Checks if requested item has a matching lyric file.
+ ///
+ /// The current lyricProvider interface.
+ /// Path of requested item.
+ /// True if item has a matching lyrics file.
+ public static string? GetLyricFilePath(ILyricsProvider lyricProvider, string itemPath)
+ {
+ if (lyricProvider.SupportedMediaTypes.Any())
+ {
+ foreach (string lyricFileExtension in lyricProvider.SupportedMediaTypes)
+ {
+ string lyricFilePath = @Path.ChangeExtension(itemPath, lyricFileExtension);
+ if (System.IO.File.Exists(lyricFilePath))
+ {
+ return lyricFilePath;
+ }
+ }
+ }
+
+ return null;
+ }
+
+ ///
+ /// Checks if requested item has a matching local lyric file.
+ ///
+ /// Collection of all registered interfaces.
+ /// Path of requested item.
+ /// True if item has a matching lyrics file; otherwise false.
+ public static bool HasLyricFile(IEnumerable lyricProviders, string itemPath)
+ {
+ foreach (var provider in lyricProviders)
+ {
+ if (GetLyricFilePath(provider, itemPath) is not null)
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+ }
+}
diff --git a/MediaBrowser.Controller/Lyrics/LyricResponse.cs b/MediaBrowser.Controller/Lyrics/LyricResponse.cs
new file mode 100644
index 0000000000..e312638ecc
--- /dev/null
+++ b/MediaBrowser.Controller/Lyrics/LyricResponse.cs
@@ -0,0 +1,15 @@
+#nullable disable
+
+#pragma warning disable CS1591
+
+using System.Collections.Generic;
+
+namespace MediaBrowser.Controller.Lyrics
+{
+ public class LyricResponse
+ {
+ public IDictionary MetaData { get; set; }
+
+ public IEnumerable Lyrics { get; set; }
+ }
+}
diff --git a/MediaBrowser.Model/Dto/BaseItemDto.cs b/MediaBrowser.Model/Dto/BaseItemDto.cs
index b40a0210ad..2a86fded22 100644
--- a/MediaBrowser.Model/Dto/BaseItemDto.cs
+++ b/MediaBrowser.Model/Dto/BaseItemDto.cs
@@ -76,7 +76,7 @@ namespace MediaBrowser.Model.Dto
public bool? CanDownload { get; set; }
- public bool? HasLocalLyricsFile { get; set; }
+ public bool? HasLyrics { get; set; }
public bool? HasSubtitles { get; set; }
diff --git a/MediaBrowser.Providers/Lyric/LrcLyricsProvider.cs b/MediaBrowser.Providers/Lyric/LrcLyricsProvider.cs
new file mode 100644
index 0000000000..e30d563087
--- /dev/null
+++ b/MediaBrowser.Providers/Lyric/LrcLyricsProvider.cs
@@ -0,0 +1,112 @@
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Dynamic;
+using System.Globalization;
+using System.Linq;
+using System.Threading.Tasks;
+using Jellyfin.Api.Helpers;
+using LrcParser.Model;
+using LrcParser.Parser;
+using MediaBrowser.Controller.Entities;
+using MediaBrowser.Controller.Lyrics;
+
+namespace MediaBrowser.Providers.Lyric
+{
+ ///
+ /// LRC File Lyric Provider.
+ ///
+ public class LrcLyricsProvider : ILyricsProvider
+ {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public LrcLyricsProvider()
+ {
+ SupportedMediaTypes = new Collection
+ {
+ "lrc"
+ };
+ }
+
+ ///
+ /// Gets a value indicating the File Extenstions this provider works with.
+ ///
+ public IEnumerable SupportedMediaTypes { get; }
+
+ ///
+ /// Gets or Sets Data object generated by Process() method.
+ ///
+ /// Object with data if no error occured; otherwise, null.
+ public object? Data { get; set; }
+
+ ///
+ /// Opens lyric file for [the specified item], and processes it for API return.
+ ///
+ /// The item to to process.
+ /// A representing the asynchronous operation.
+ public LyricResponse? GetLyrics(BaseItem item)
+ {
+ string? lyricFilePath = LyricInfo.GetLyricFilePath(this, item.Path);
+
+ if (string.IsNullOrEmpty(lyricFilePath))
+ {
+ return null;
+ }
+
+ List lyricsList = new List();
+
+ List sortedLyricData = new List();
+ var metaData = new ExpandoObject() as IDictionary;
+ string lrcFileContent = System.IO.File.ReadAllText(lyricFilePath);
+
+ 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.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(":");
+
+ string metaDataFieldName = metaDataField[0].Replace("[", string.Empty, StringComparison.Ordinal);
+ string metaDataFieldValue = metaDataField[1].Replace("]", string.Empty, StringComparison.Ordinal);
+
+ metaData.Add(metaDataFieldName, metaDataFieldValue);
+ }
+ }
+ catch
+ {
+ return null;
+ }
+
+ if (!sortedLyricData.Any())
+ {
+ return null;
+ }
+
+ for (int i = 0; i < sortedLyricData.Count; i++)
+ {
+ var timeData = sortedLyricData[i].TimeTags.ToArray()[0].Value;
+ double ticks = Convert.ToDouble(timeData, new NumberFormatInfo()) * 10000;
+ lyricsList.Add(new MediaBrowser.Controller.Lyrics.Lyric { Start = Math.Ceiling(ticks), Text = sortedLyricData[i].Text });
+ }
+
+ if (metaData.Any())
+ {
+ return new LyricResponse { MetaData = metaData, Lyrics = lyricsList };
+ }
+
+ return new LyricResponse { Lyrics = lyricsList };
+ }
+ }
+}
diff --git a/MediaBrowser.Providers/Lyric/TxtLyricsProvider.cs b/MediaBrowser.Providers/Lyric/TxtLyricsProvider.cs
new file mode 100644
index 0000000000..2a5da4e4d8
--- /dev/null
+++ b/MediaBrowser.Providers/Lyric/TxtLyricsProvider.cs
@@ -0,0 +1,74 @@
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Linq;
+using System.Threading.Tasks;
+using Jellyfin.Api.Helpers;
+using MediaBrowser.Controller.Entities;
+using MediaBrowser.Controller.Lyrics;
+
+namespace MediaBrowser.Providers.Lyric
+{
+ ///
+ /// TXT File Lyric Provider.
+ ///
+ public class TxtLyricsProvider : ILyricsProvider
+ {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public TxtLyricsProvider()
+ {
+ SupportedMediaTypes = new Collection
+ {
+ "lrc", "txt"
+ };
+ }
+
+ ///
+ /// Gets a value indicating the File Extenstions this provider works with.
+ ///
+ public IEnumerable SupportedMediaTypes { get; }
+
+ ///
+ /// Gets or Sets Data object generated by Process() method.
+ ///
+ /// Object with data if no error occured; otherwise, null.
+ public object? Data { get; set; }
+
+ ///
+ /// Opens lyric file for [the specified item], and processes it for API return.
+ ///
+ /// The item to to process.
+ /// A representing the asynchronous operation.
+ public LyricResponse? GetLyrics(BaseItem item)
+ {
+ string? lyricFilePath = LyricInfo.GetLyricFilePath(this, item.Path);
+
+ if (string.IsNullOrEmpty(lyricFilePath))
+ {
+ return null;
+ }
+
+ List lyricsList = new List();
+
+ string lyricData = System.IO.File.ReadAllText(lyricFilePath);
+
+ // 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);
+
+ if (!lyricTextLines.Any())
+ {
+ return null;
+ }
+
+ foreach (string lyricLine in lyricTextLines)
+ {
+ lyricsList.Add(new MediaBrowser.Controller.Lyrics.Lyric { Text = lyricLine });
+ }
+
+ return new LyricResponse { Lyrics = lyricsList };
+ }
+ }
+}
diff --git a/MediaBrowser.Providers/MediaBrowser.Providers.csproj b/MediaBrowser.Providers/MediaBrowser.Providers.csproj
index 9864db9ac2..8514489f8a 100644
--- a/MediaBrowser.Providers/MediaBrowser.Providers.csproj
+++ b/MediaBrowser.Providers/MediaBrowser.Providers.csproj
@@ -6,6 +6,7 @@
+
@@ -16,6 +17,7 @@
+
--
cgit v1.2.3
From f4fd908f8d7ffcdea6acaf75928f6c2960ed6338 Mon Sep 17 00:00:00 2001
From: 1hitsong <3330318+1hitsong@users.noreply.github.com>
Date: Thu, 15 Sep 2022 20:49:25 -0400
Subject: Create ILyricManager
---
Emby.Server.Implementations/ApplicationHost.cs | 4 +-
Emby.Server.Implementations/Dto/DtoService.cs | 8 +-
Jellyfin.Api/Controllers/UserLibraryController.cs | 16 ++-
MediaBrowser.Controller/Lyrics/ILyricManager.cs | 37 +++++++
MediaBrowser.Controller/Lyrics/ILyricProvider.cs | 29 ++++++
MediaBrowser.Controller/Lyrics/ILyricsProvider.cs | 24 -----
MediaBrowser.Controller/Lyrics/LyricInfo.cs | 50 +--------
MediaBrowser.Providers/Lyric/LrcLyricProvider.cs | 119 ++++++++++++++++++++++
MediaBrowser.Providers/Lyric/LrcLyricsProvider.cs | 112 --------------------
MediaBrowser.Providers/Lyric/LyricManager.cs | 97 ++++++++++++++++++
MediaBrowser.Providers/Lyric/TxtLyricProvider.cs | 82 +++++++++++++++
MediaBrowser.Providers/Lyric/TxtLyricsProvider.cs | 74 --------------
12 files changed, 378 insertions(+), 274 deletions(-)
create mode 100644 MediaBrowser.Controller/Lyrics/ILyricManager.cs
create mode 100644 MediaBrowser.Controller/Lyrics/ILyricProvider.cs
delete mode 100644 MediaBrowser.Controller/Lyrics/ILyricsProvider.cs
create mode 100644 MediaBrowser.Providers/Lyric/LrcLyricProvider.cs
delete mode 100644 MediaBrowser.Providers/Lyric/LrcLyricsProvider.cs
create mode 100644 MediaBrowser.Providers/Lyric/LyricManager.cs
create mode 100644 MediaBrowser.Providers/Lyric/TxtLyricProvider.cs
delete mode 100644 MediaBrowser.Providers/Lyric/TxtLyricsProvider.cs
(limited to 'MediaBrowser.Controller')
diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs
index 5487e5e023..409fc04b16 100644
--- a/Emby.Server.Implementations/ApplicationHost.cs
+++ b/Emby.Server.Implementations/ApplicationHost.cs
@@ -583,8 +583,6 @@ namespace Emby.Server.Implementations
serviceCollection.AddTransient(provider => new Lazy(provider.GetRequiredService));
serviceCollection.AddTransient(provider => new Lazy(provider.GetRequiredService));
serviceCollection.AddTransient(provider => new Lazy(provider.GetRequiredService));
- serviceCollection.AddTransient();
- serviceCollection.AddTransient();
serviceCollection.AddSingleton();
serviceCollection.AddSingleton();
@@ -603,6 +601,7 @@ namespace Emby.Server.Implementations
serviceCollection.AddSingleton();
serviceCollection.AddSingleton();
+ serviceCollection.AddSingleton();
serviceCollection.AddSingleton();
@@ -790,6 +789,7 @@ namespace Emby.Server.Implementations
Resolve().AddParts(GetExports(), GetExports(), GetExports());
Resolve().AddParts(GetExports());
+ Resolve().AddParts(GetExports());
Resolve().AddParts(GetExports());
diff --git a/Emby.Server.Implementations/Dto/DtoService.cs b/Emby.Server.Implementations/Dto/DtoService.cs
index bed82a4bbb..6ab574c5c5 100644
--- a/Emby.Server.Implementations/Dto/DtoService.cs
+++ b/Emby.Server.Implementations/Dto/DtoService.cs
@@ -52,7 +52,7 @@ namespace Emby.Server.Implementations.Dto
private readonly IMediaSourceManager _mediaSourceManager;
private readonly Lazy _livetvManagerFactory;
- private readonly IEnumerable _lyricProviders;
+ private readonly ILyricManager _lyricManager;
public DtoService(
ILogger logger,
@@ -64,7 +64,7 @@ namespace Emby.Server.Implementations.Dto
IApplicationHost appHost,
IMediaSourceManager mediaSourceManager,
Lazy livetvManagerFactory,
- IEnumerable lyricProviders)
+ ILyricManager lyricManager)
{
_logger = logger;
_libraryManager = libraryManager;
@@ -75,7 +75,7 @@ namespace Emby.Server.Implementations.Dto
_appHost = appHost;
_mediaSourceManager = mediaSourceManager;
_livetvManagerFactory = livetvManagerFactory;
- _lyricProviders = lyricProviders;
+ _lyricManager = lyricManager;
}
private ILiveTvManager LivetvManager => _livetvManagerFactory.Value;
@@ -147,7 +147,7 @@ namespace Emby.Server.Implementations.Dto
}
else if (item is Audio)
{
- dto.HasLyrics = MediaBrowser.Controller.Lyrics.LyricInfo.HasLyricFile(_lyricProviders, item.Path);
+ dto.HasLyrics = _lyricManager.HasLyricFile(item);
}
if (item is IItemByName itemByName
diff --git a/Jellyfin.Api/Controllers/UserLibraryController.cs b/Jellyfin.Api/Controllers/UserLibraryController.cs
index 3da78c1169..1421ab444a 100644
--- a/Jellyfin.Api/Controllers/UserLibraryController.cs
+++ b/Jellyfin.Api/Controllers/UserLibraryController.cs
@@ -38,7 +38,7 @@ namespace Jellyfin.Api.Controllers
private readonly IDtoService _dtoService;
private readonly IUserViewManager _userViewManager;
private readonly IFileSystem _fileSystem;
- private readonly IEnumerable _lyricProviders;
+ private readonly ILyricManager _lyricManager;
///
/// Initializes a new instance of the class.
@@ -49,7 +49,7 @@ namespace Jellyfin.Api.Controllers
/// Instance of the interface.
/// Instance of the interface.
/// Instance of the interface.
- /// Collection of all registered interfaces.
+ /// Instance of the interface.
public UserLibraryController(
IUserManager userManager,
IUserDataManager userDataRepository,
@@ -57,7 +57,7 @@ namespace Jellyfin.Api.Controllers
IDtoService dtoService,
IUserViewManager userViewManager,
IFileSystem fileSystem,
- IEnumerable lyricProviders)
+ ILyricManager lyricManager)
{
_userManager = userManager;
_userDataRepository = userDataRepository;
@@ -65,7 +65,7 @@ namespace Jellyfin.Api.Controllers
_dtoService = dtoService;
_userViewManager = userViewManager;
_fileSystem = fileSystem;
- _lyricProviders = lyricProviders;
+ _lyricManager = lyricManager;
}
///
@@ -415,14 +415,10 @@ namespace Jellyfin.Api.Controllers
return NotFound();
}
- var result = MediaBrowser.Controller.Lyrics.LyricInfo.GetLyricData(_lyricProviders, item);
+ var result = _lyricManager.GetLyric(item);
if (result is not null)
{
- provider.Process(item);
- if (provider.HasData)
- {
- return Ok(provider.Data);
- }
+ return Ok(result);
}
return NotFound();
diff --git a/MediaBrowser.Controller/Lyrics/ILyricManager.cs b/MediaBrowser.Controller/Lyrics/ILyricManager.cs
new file mode 100644
index 0000000000..4fd11b9e02
--- /dev/null
+++ b/MediaBrowser.Controller/Lyrics/ILyricManager.cs
@@ -0,0 +1,37 @@
+#nullable disable
+
+#pragma warning disable CS1591
+
+using System;
+using System.Collections.Generic;
+using System.Threading;
+using System.Threading.Tasks;
+using MediaBrowser.Controller.Entities;
+using MediaBrowser.Model.Configuration;
+using MediaBrowser.Model.Providers;
+
+namespace MediaBrowser.Controller.Lyrics
+{
+ public interface ILyricManager
+ {
+ ///
+ /// Adds the parts.
+ ///
+ /// The lyric providers.
+ void AddParts(IEnumerable lyricProviders);
+
+ ///
+ /// Gets the lyrics.
+ ///
+ /// The media item.
+ /// Lyrics for passed item.
+ LyricResponse GetLyric(BaseItem item);
+
+ ///
+ /// Checks if requested item has a matching local lyric file.
+ ///
+ /// The media item.
+ /// True if item has a matching lyrics file; otherwise false.
+ bool HasLyricFile(BaseItem item);
+ }
+}
diff --git a/MediaBrowser.Controller/Lyrics/ILyricProvider.cs b/MediaBrowser.Controller/Lyrics/ILyricProvider.cs
new file mode 100644
index 0000000000..691fed1fd2
--- /dev/null
+++ b/MediaBrowser.Controller/Lyrics/ILyricProvider.cs
@@ -0,0 +1,29 @@
+using System.Collections.Generic;
+using MediaBrowser.Controller.Entities;
+
+namespace MediaBrowser.Controller.Lyrics
+{
+ ///
+ /// Interface ILyricsProvider.
+ ///
+ public interface ILyricProvider
+ {
+ ///
+ /// Gets a value indicating the provider name.
+ ///
+ string Name { get; }
+
+ ///
+ /// Gets the supported media types for this provider.
+ ///
+ /// The supported media types.
+ IEnumerable SupportedMediaTypes { get; }
+
+ ///
+ /// Gets the lyrics.
+ ///
+ /// The item to to process.
+ /// Task{LyricResponse}.
+ LyricResponse? GetLyrics(BaseItem item);
+ }
+}
diff --git a/MediaBrowser.Controller/Lyrics/ILyricsProvider.cs b/MediaBrowser.Controller/Lyrics/ILyricsProvider.cs
deleted file mode 100644
index bac32a398a..0000000000
--- a/MediaBrowser.Controller/Lyrics/ILyricsProvider.cs
+++ /dev/null
@@ -1,24 +0,0 @@
-using System.Collections.Generic;
-using MediaBrowser.Controller.Entities;
-
-namespace MediaBrowser.Controller.Lyrics
-{
- ///
- /// Interface ILyricsProvider.
- ///
- public interface ILyricsProvider
- {
- ///
- /// Gets the supported media types for this provider.
- ///
- /// The supported media types.
- IEnumerable SupportedMediaTypes { get; }
-
- ///
- /// Gets the lyrics.
- ///
- /// The item to to process.
- /// Task{LyricResponse}.
- LyricResponse? GetLyrics(BaseItem item);
- }
-}
diff --git a/MediaBrowser.Controller/Lyrics/LyricInfo.cs b/MediaBrowser.Controller/Lyrics/LyricInfo.cs
index 83a10701a2..d44e14237a 100644
--- a/MediaBrowser.Controller/Lyrics/LyricInfo.cs
+++ b/MediaBrowser.Controller/Lyrics/LyricInfo.cs
@@ -13,42 +13,15 @@ namespace MediaBrowser.Controller.Lyrics
///
/// Item helper.
///
- public class LyricInfo
+ public static class LyricInfo
{
- ///
- /// Opens lyrics file, converts to a List of Lyrics, and returns it.
- ///
- /// Collection of all registered interfaces.
- /// Requested Item.
- /// Collection of Lyrics.
- public static LyricResponse? GetLyricData(IEnumerable lyricProviders, BaseItem item)
- {
-
- foreach (var provider in lyricProviders)
- {
- var result = provider.GetLyrics(item);
- if (result is not null)
- {
- return result;
- }
- }
-
- return new LyricResponse
- {
- Lyrics = new List
- {
- new Lyric { Start = 0, Text = "Test" }
- }
- };
- }
-
///
/// Checks if requested item has a matching lyric file.
///
/// The current lyricProvider interface.
/// Path of requested item.
/// True if item has a matching lyrics file.
- public static string? GetLyricFilePath(ILyricsProvider lyricProvider, string itemPath)
+ public static string? GetLyricFilePath(ILyricProvider lyricProvider, string itemPath)
{
if (lyricProvider.SupportedMediaTypes.Any())
{
@@ -64,24 +37,5 @@ namespace MediaBrowser.Controller.Lyrics
return null;
}
-
- ///
- /// Checks if requested item has a matching local lyric file.
- ///
- /// Collection of all registered interfaces.
- /// Path of requested item.
- /// True if item has a matching lyrics file; otherwise false.
- public static bool HasLyricFile(IEnumerable lyricProviders, string itemPath)
- {
- foreach (var provider in lyricProviders)
- {
- if (GetLyricFilePath(provider, itemPath) is not null)
- {
- return true;
- }
- }
-
- return false;
- }
}
}
diff --git a/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs b/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs
new file mode 100644
index 0000000000..18a85c93ac
--- /dev/null
+++ b/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs
@@ -0,0 +1,119 @@
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Dynamic;
+using System.Globalization;
+using System.Linq;
+using System.Threading.Tasks;
+using Jellyfin.Api.Helpers;
+using LrcParser.Model;
+using LrcParser.Parser;
+using MediaBrowser.Controller.Entities;
+using MediaBrowser.Controller.Lyrics;
+
+namespace MediaBrowser.Providers.Lyric
+{
+ ///
+ /// LRC File Lyric Provider.
+ ///
+ public class LrcLyricProvider : ILyricProvider
+ {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public LrcLyricProvider()
+ {
+ Name = "LrcLyricProvider";
+
+ SupportedMediaTypes = new Collection
+ {
+ "lrc"
+ };
+ }
+
+ ///
+ /// Gets a value indicating the provider name.
+ ///
+ public string Name { get; }
+
+ ///
+ /// Gets a value indicating the File Extenstions this provider works with.
+ ///
+ public IEnumerable SupportedMediaTypes { get; }
+
+ ///
+ /// Gets or Sets Data object generated by Process() method.
+ ///
+ /// Object with data if no error occured; otherwise, null.
+ public object? Data { get; set; }
+
+ ///
+ /// Opens lyric file for [the specified item], and processes it for API return.
+ ///
+ /// The item to to process.
+ /// A representing the asynchronous operation.
+ public LyricResponse? GetLyrics(BaseItem item)
+ {
+ string? lyricFilePath = LyricInfo.GetLyricFilePath(this, item.Path);
+
+ if (string.IsNullOrEmpty(lyricFilePath))
+ {
+ return null;
+ }
+
+ List lyricsList = new List();
+
+ List sortedLyricData = new List();
+ var metaData = new ExpandoObject() as IDictionary;
+ string lrcFileContent = System.IO.File.ReadAllText(lyricFilePath);
+
+ 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.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(":");
+
+ string metaDataFieldName = metaDataField[0].Replace("[", string.Empty, StringComparison.Ordinal);
+ string metaDataFieldValue = metaDataField[1].Replace("]", string.Empty, StringComparison.Ordinal);
+
+ metaData.Add(metaDataFieldName, metaDataFieldValue);
+ }
+ }
+ catch
+ {
+ return null;
+ }
+
+ if (!sortedLyricData.Any())
+ {
+ return null;
+ }
+
+ for (int i = 0; i < sortedLyricData.Count; i++)
+ {
+ var timeData = sortedLyricData[i].TimeTags.ToArray()[0].Value;
+ double ticks = Convert.ToDouble(timeData, new NumberFormatInfo()) * 10000;
+ lyricsList.Add(new MediaBrowser.Controller.Lyrics.Lyric { Start = Math.Ceiling(ticks), Text = sortedLyricData[i].Text });
+ }
+
+ if (metaData.Any())
+ {
+ return new LyricResponse { MetaData = metaData, Lyrics = lyricsList };
+ }
+
+ return new LyricResponse { Lyrics = lyricsList };
+ }
+ }
+}
diff --git a/MediaBrowser.Providers/Lyric/LrcLyricsProvider.cs b/MediaBrowser.Providers/Lyric/LrcLyricsProvider.cs
deleted file mode 100644
index e30d563087..0000000000
--- a/MediaBrowser.Providers/Lyric/LrcLyricsProvider.cs
+++ /dev/null
@@ -1,112 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.Dynamic;
-using System.Globalization;
-using System.Linq;
-using System.Threading.Tasks;
-using Jellyfin.Api.Helpers;
-using LrcParser.Model;
-using LrcParser.Parser;
-using MediaBrowser.Controller.Entities;
-using MediaBrowser.Controller.Lyrics;
-
-namespace MediaBrowser.Providers.Lyric
-{
- ///
- /// LRC File Lyric Provider.
- ///
- public class LrcLyricsProvider : ILyricsProvider
- {
- ///
- /// Initializes a new instance of the class.
- ///
- public LrcLyricsProvider()
- {
- SupportedMediaTypes = new Collection
- {
- "lrc"
- };
- }
-
- ///
- /// Gets a value indicating the File Extenstions this provider works with.
- ///
- public IEnumerable SupportedMediaTypes { get; }
-
- ///
- /// Gets or Sets Data object generated by Process() method.
- ///
- /// Object with data if no error occured; otherwise, null.
- public object? Data { get; set; }
-
- ///
- /// Opens lyric file for [the specified item], and processes it for API return.
- ///
- /// The item to to process.
- /// A representing the asynchronous operation.
- public LyricResponse? GetLyrics(BaseItem item)
- {
- string? lyricFilePath = LyricInfo.GetLyricFilePath(this, item.Path);
-
- if (string.IsNullOrEmpty(lyricFilePath))
- {
- return null;
- }
-
- List lyricsList = new List();
-
- List sortedLyricData = new List();
- var metaData = new ExpandoObject() as IDictionary;
- string lrcFileContent = System.IO.File.ReadAllText(lyricFilePath);
-
- 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.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(":");
-
- string metaDataFieldName = metaDataField[0].Replace("[", string.Empty, StringComparison.Ordinal);
- string metaDataFieldValue = metaDataField[1].Replace("]", string.Empty, StringComparison.Ordinal);
-
- metaData.Add(metaDataFieldName, metaDataFieldValue);
- }
- }
- catch
- {
- return null;
- }
-
- if (!sortedLyricData.Any())
- {
- return null;
- }
-
- for (int i = 0; i < sortedLyricData.Count; i++)
- {
- var timeData = sortedLyricData[i].TimeTags.ToArray()[0].Value;
- double ticks = Convert.ToDouble(timeData, new NumberFormatInfo()) * 10000;
- lyricsList.Add(new MediaBrowser.Controller.Lyrics.Lyric { Start = Math.Ceiling(ticks), Text = sortedLyricData[i].Text });
- }
-
- if (metaData.Any())
- {
- return new LyricResponse { MetaData = metaData, Lyrics = lyricsList };
- }
-
- return new LyricResponse { Lyrics = lyricsList };
- }
- }
-}
diff --git a/MediaBrowser.Providers/Lyric/LyricManager.cs b/MediaBrowser.Providers/Lyric/LyricManager.cs
new file mode 100644
index 0000000000..48572c63e4
--- /dev/null
+++ b/MediaBrowser.Providers/Lyric/LyricManager.cs
@@ -0,0 +1,97 @@
+#nullable disable
+
+#pragma warning disable CS1591
+
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.IO;
+using System.Linq;
+using System.Threading;
+using System.Threading.Tasks;
+using Jellyfin.Extensions;
+using MediaBrowser.Common.Extensions;
+using MediaBrowser.Controller.Entities;
+using MediaBrowser.Controller.Entities.Movies;
+using MediaBrowser.Controller.Entities.TV;
+using MediaBrowser.Controller.Library;
+using MediaBrowser.Controller.Lyrics;
+using MediaBrowser.Controller.Persistence;
+using MediaBrowser.Controller.Providers;
+using MediaBrowser.Controller.Subtitles;
+using MediaBrowser.Model.Configuration;
+using MediaBrowser.Model.Entities;
+using MediaBrowser.Model.Globalization;
+using MediaBrowser.Model.IO;
+using MediaBrowser.Model.Providers;
+using Microsoft.Extensions.Logging;
+
+namespace MediaBrowser.Providers.Lyric
+{
+ public class LyricManager : ILyricManager
+ {
+ private readonly ILogger _logger;
+ private readonly IFileSystem _fileSystem;
+ private readonly ILibraryMonitor _monitor;
+ private readonly IMediaSourceManager _mediaSourceManager;
+ private readonly ILocalizationManager _localization;
+
+ private ILyricProvider[] _lyricProviders;
+
+ public LyricManager(
+ ILogger logger,
+ IFileSystem fileSystem,
+ ILibraryMonitor monitor,
+ IMediaSourceManager mediaSourceManager,
+ ILocalizationManager localizationManager)
+ {
+ _logger = logger;
+ _fileSystem = fileSystem;
+ _monitor = monitor;
+ _mediaSourceManager = mediaSourceManager;
+ _localization = localizationManager;
+ }
+
+ ///
+ public void AddParts(IEnumerable lyricProviders)
+ {
+ _lyricProviders = lyricProviders
+ .OrderBy(i => i is IHasOrder hasOrder ? hasOrder.Order : 0)
+ .ToArray();
+ }
+
+ ///
+ public LyricResponse GetLyric(BaseItem item)
+ {
+ foreach (ILyricProvider provider in _lyricProviders)
+ {
+ var results = provider.GetLyrics(item);
+ if (results is not null)
+ {
+ return results;
+ }
+ }
+
+ return null;
+ }
+
+ ///
+ public bool HasLyricFile(BaseItem item)
+ {
+ foreach (ILyricProvider provider in _lyricProviders)
+ {
+ if (item is null)
+ {
+ continue;
+ }
+
+ if (LyricInfo.GetLyricFilePath(provider, item.Path) is not null)
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+ }
+}
diff --git a/MediaBrowser.Providers/Lyric/TxtLyricProvider.cs b/MediaBrowser.Providers/Lyric/TxtLyricProvider.cs
new file mode 100644
index 0000000000..939d8708b2
--- /dev/null
+++ b/MediaBrowser.Providers/Lyric/TxtLyricProvider.cs
@@ -0,0 +1,82 @@
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Linq;
+using System.Threading.Tasks;
+using System.Xml.Linq;
+using Jellyfin.Api.Helpers;
+using MediaBrowser.Controller.Entities;
+using MediaBrowser.Controller.Lyrics;
+
+namespace MediaBrowser.Providers.Lyric
+{
+ ///
+ /// TXT File Lyric Provider.
+ ///
+ public class TxtLyricProvider : ILyricProvider
+ {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public TxtLyricProvider()
+ {
+ Name = "TxtLyricProvider";
+
+ SupportedMediaTypes = new Collection
+ {
+ "lrc", "txt"
+ };
+ }
+
+ ///
+ /// Gets a value indicating the provider name.
+ ///
+ public string Name { get; }
+
+ ///
+ /// Gets a value indicating the File Extenstions this provider works with.
+ ///
+ public IEnumerable SupportedMediaTypes { get; }
+
+ ///
+ /// Gets or Sets Data object generated by Process() method.
+ ///
+ /// Object with data if no error occured; otherwise, null.
+ public object? Data { get; set; }
+
+ ///
+ /// Opens lyric file for [the specified item], and processes it for API return.
+ ///
+ /// The item to to process.
+ /// A representing the asynchronous operation.
+ public LyricResponse? GetLyrics(BaseItem item)
+ {
+ string? lyricFilePath = LyricInfo.GetLyricFilePath(this, item.Path);
+
+ if (string.IsNullOrEmpty(lyricFilePath))
+ {
+ return null;
+ }
+
+ List lyricsList = new List();
+
+ string lyricData = System.IO.File.ReadAllText(lyricFilePath);
+
+ // 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);
+
+ if (!lyricTextLines.Any())
+ {
+ return null;
+ }
+
+ foreach (string lyricLine in lyricTextLines)
+ {
+ lyricsList.Add(new MediaBrowser.Controller.Lyrics.Lyric { Text = lyricLine });
+ }
+
+ return new LyricResponse { Lyrics = lyricsList };
+ }
+ }
+}
diff --git a/MediaBrowser.Providers/Lyric/TxtLyricsProvider.cs b/MediaBrowser.Providers/Lyric/TxtLyricsProvider.cs
deleted file mode 100644
index 2a5da4e4d8..0000000000
--- a/MediaBrowser.Providers/Lyric/TxtLyricsProvider.cs
+++ /dev/null
@@ -1,74 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.Linq;
-using System.Threading.Tasks;
-using Jellyfin.Api.Helpers;
-using MediaBrowser.Controller.Entities;
-using MediaBrowser.Controller.Lyrics;
-
-namespace MediaBrowser.Providers.Lyric
-{
- ///
- /// TXT File Lyric Provider.
- ///
- public class TxtLyricsProvider : ILyricsProvider
- {
- ///
- /// Initializes a new instance of the class.
- ///
- public TxtLyricsProvider()
- {
- SupportedMediaTypes = new Collection
- {
- "lrc", "txt"
- };
- }
-
- ///
- /// Gets a value indicating the File Extenstions this provider works with.
- ///
- public IEnumerable SupportedMediaTypes { get; }
-
- ///
- /// Gets or Sets Data object generated by Process() method.
- ///
- /// Object with data if no error occured; otherwise, null.
- public object? Data { get; set; }
-
- ///
- /// Opens lyric file for [the specified item], and processes it for API return.
- ///
- /// The item to to process.
- /// A representing the asynchronous operation.
- public LyricResponse? GetLyrics(BaseItem item)
- {
- string? lyricFilePath = LyricInfo.GetLyricFilePath(this, item.Path);
-
- if (string.IsNullOrEmpty(lyricFilePath))
- {
- return null;
- }
-
- List lyricsList = new List();
-
- string lyricData = System.IO.File.ReadAllText(lyricFilePath);
-
- // 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);
-
- if (!lyricTextLines.Any())
- {
- return null;
- }
-
- foreach (string lyricLine in lyricTextLines)
- {
- lyricsList.Add(new MediaBrowser.Controller.Lyrics.Lyric { Text = lyricLine });
- }
-
- return new LyricResponse { Lyrics = lyricsList };
- }
- }
-}
--
cgit v1.2.3
From f740d1b9f00d91bfad970f56abed67d8c8c16c9c Mon Sep 17 00:00:00 2001
From: 1hitsong <3330318+1hitsong@users.noreply.github.com>
Date: Fri, 16 Sep 2022 20:52:40 -0400
Subject: Remove use of AddParts. Cleanup use of Lyric vs Lyrics.
---
Emby.Server.Implementations/ApplicationHost.cs | 2 +-
Jellyfin.Api/Controllers/UserLibraryController.cs | 6 +++---
Jellyfin.Server/CoreAppHost.cs | 6 ++++++
MediaBrowser.Controller/Lyrics/ILyricManager.cs | 18 ++--------------
MediaBrowser.Controller/Lyrics/ILyricProvider.cs | 4 ++--
MediaBrowser.Controller/Lyrics/Lyric.cs | 4 ++--
MediaBrowser.Controller/Lyrics/LyricInfo.cs | 8 +++----
MediaBrowser.Controller/Lyrics/LyricResponse.cs | 9 ++++++++
MediaBrowser.Providers/Lyric/LrcLyricProvider.cs | 24 ++++++++-------------
MediaBrowser.Providers/Lyric/LyricManager.cs | 16 +++++---------
MediaBrowser.Providers/Lyric/TxtLyricProvider.cs | 26 +++++++++--------------
11 files changed, 53 insertions(+), 70 deletions(-)
(limited to 'MediaBrowser.Controller')
diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs
index 409fc04b16..5edc25952d 100644
--- a/Emby.Server.Implementations/ApplicationHost.cs
+++ b/Emby.Server.Implementations/ApplicationHost.cs
@@ -789,7 +789,7 @@ namespace Emby.Server.Implementations
Resolve().AddParts(GetExports(), GetExports(), GetExports());
Resolve().AddParts(GetExports());
- Resolve().AddParts(GetExports());
+ //Resolve().AddParts(GetExports());
Resolve().AddParts(GetExports());
diff --git a/Jellyfin.Api/Controllers/UserLibraryController.cs b/Jellyfin.Api/Controllers/UserLibraryController.cs
index 1421ab444a..2cb2e93284 100644
--- a/Jellyfin.Api/Controllers/UserLibraryController.cs
+++ b/Jellyfin.Api/Controllers/UserLibraryController.cs
@@ -394,10 +394,10 @@ namespace Jellyfin.Api.Controllers
/// Item id.
/// Lyrics returned.
/// Something went wrong. No Lyrics will be returned.
- /// An containing the intros to play.
+ /// An containing the item's lyrics.
[HttpGet("Users/{userId}/Items/{itemId}/Lyrics")]
[ProducesResponseType(StatusCodes.Status200OK)]
- public ActionResult> GetLyrics([FromRoute, Required] Guid userId, [FromRoute, Required] Guid itemId)
+ public ActionResult> GetLyrics([FromRoute, Required] Guid userId, [FromRoute, Required] Guid itemId)
{
var user = _userManager.GetUserById(userId);
@@ -415,7 +415,7 @@ namespace Jellyfin.Api.Controllers
return NotFound();
}
- var result = _lyricManager.GetLyric(item);
+ var result = _lyricManager.GetLyrics(item);
if (result is not null)
{
return Ok(result);
diff --git a/Jellyfin.Server/CoreAppHost.cs b/Jellyfin.Server/CoreAppHost.cs
index 67e50b92d9..984711dc2d 100644
--- a/Jellyfin.Server/CoreAppHost.cs
+++ b/Jellyfin.Server/CoreAppHost.cs
@@ -19,6 +19,7 @@ using MediaBrowser.Controller.Devices;
using MediaBrowser.Controller.Drawing;
using MediaBrowser.Controller.Events;
using MediaBrowser.Controller.Library;
+using MediaBrowser.Controller.Lyrics;
using MediaBrowser.Controller.Net;
using MediaBrowser.Controller.Security;
using MediaBrowser.Model.Activity;
@@ -95,6 +96,11 @@ namespace Jellyfin.Server
serviceCollection.AddScoped();
+ foreach (var type in GetExportTypes())
+ {
+ serviceCollection.AddSingleton(typeof(ILyricProvider), type);
+ }
+
base.RegisterServices(serviceCollection);
}
diff --git a/MediaBrowser.Controller/Lyrics/ILyricManager.cs b/MediaBrowser.Controller/Lyrics/ILyricManager.cs
index 4fd11b9e02..c0f78d177d 100644
--- a/MediaBrowser.Controller/Lyrics/ILyricManager.cs
+++ b/MediaBrowser.Controller/Lyrics/ILyricManager.cs
@@ -1,37 +1,23 @@
-#nullable disable
-
#pragma warning disable CS1591
-using System;
-using System.Collections.Generic;
-using System.Threading;
-using System.Threading.Tasks;
using MediaBrowser.Controller.Entities;
-using MediaBrowser.Model.Configuration;
-using MediaBrowser.Model.Providers;
namespace MediaBrowser.Controller.Lyrics
{
public interface ILyricManager
{
- ///
- /// Adds the parts.
- ///
- /// The lyric providers.
- void AddParts(IEnumerable lyricProviders);
-
///
/// Gets the lyrics.
///
/// The media item.
/// Lyrics for passed item.
- LyricResponse GetLyric(BaseItem item);
+ LyricResponse GetLyrics(BaseItem item);
///
/// Checks if requested item has a matching local lyric file.
///
/// The media item.
- /// True if item has a matching lyrics file; otherwise false.
+ /// True if item has a matching lyric file; otherwise false.
bool HasLyricFile(BaseItem item);
}
}
diff --git a/MediaBrowser.Controller/Lyrics/ILyricProvider.cs b/MediaBrowser.Controller/Lyrics/ILyricProvider.cs
index 691fed1fd2..5e677ab26f 100644
--- a/MediaBrowser.Controller/Lyrics/ILyricProvider.cs
+++ b/MediaBrowser.Controller/Lyrics/ILyricProvider.cs
@@ -22,8 +22,8 @@ namespace MediaBrowser.Controller.Lyrics
///
/// Gets the lyrics.
///
- /// The item to to process.
- /// Task{LyricResponse}.
+ /// The media item.
+ /// If found, returns lyrics for passed item; otherwise, null.
LyricResponse? GetLyrics(BaseItem item);
}
}
diff --git a/MediaBrowser.Controller/Lyrics/Lyric.cs b/MediaBrowser.Controller/Lyrics/Lyric.cs
index d44546dd39..56a0a8a72d 100644
--- a/MediaBrowser.Controller/Lyrics/Lyric.cs
+++ b/MediaBrowser.Controller/Lyrics/Lyric.cs
@@ -1,12 +1,12 @@
namespace MediaBrowser.Controller.Lyrics
{
///
- /// Lyric dto.
+ /// Lyric model.
///
public class Lyric
{
///
- /// Gets or sets the start time (ticks).
+ /// Gets or sets the start time in ticks.
///
public double? Start { get; set; }
diff --git a/MediaBrowser.Controller/Lyrics/LyricInfo.cs b/MediaBrowser.Controller/Lyrics/LyricInfo.cs
index d44e14237a..018f296b1a 100644
--- a/MediaBrowser.Controller/Lyrics/LyricInfo.cs
+++ b/MediaBrowser.Controller/Lyrics/LyricInfo.cs
@@ -11,16 +11,16 @@ using Microsoft.AspNetCore.Mvc;
namespace MediaBrowser.Controller.Lyrics
{
///
- /// Item helper.
+ /// Lyric helper methods.
///
public static class LyricInfo
{
///
- /// Checks if requested item has a matching lyric file.
+ /// Gets matching lyric file for a requested item.
///
- /// The current lyricProvider interface.
+ /// The lyricProvider interface to use.
/// Path of requested item.
- /// True if item has a matching lyrics file.
+ /// Lyric file path if passed lyric provider's supported media type is found; otherwise, null.
public static string? GetLyricFilePath(ILyricProvider lyricProvider, string itemPath)
{
if (lyricProvider.SupportedMediaTypes.Any())
diff --git a/MediaBrowser.Controller/Lyrics/LyricResponse.cs b/MediaBrowser.Controller/Lyrics/LyricResponse.cs
index e312638ecc..498eb873c7 100644
--- a/MediaBrowser.Controller/Lyrics/LyricResponse.cs
+++ b/MediaBrowser.Controller/Lyrics/LyricResponse.cs
@@ -6,10 +6,19 @@ using System.Collections.Generic;
namespace MediaBrowser.Controller.Lyrics
{
+ ///
+ /// LyricResponse model.
+ ///
public class LyricResponse
{
+ ///
+ /// Gets or sets MetaData.
+ ///
public IDictionary MetaData { get; set; }
+ ///
+ /// Gets or sets Lyrics.
+ ///
public IEnumerable Lyrics { get; set; }
}
}
diff --git a/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs b/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs
index 18a85c93ac..10db10ac6f 100644
--- a/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs
+++ b/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs
@@ -14,7 +14,7 @@ using MediaBrowser.Controller.Lyrics;
namespace MediaBrowser.Providers.Lyric
{
///
- /// LRC File Lyric Provider.
+ /// LRC Lyric Provider.
///
public class LrcLyricProvider : ILyricProvider
{
@@ -37,21 +37,15 @@ namespace MediaBrowser.Providers.Lyric
public string Name { get; }
///
- /// Gets a value indicating the File Extenstions this provider works with.
+ /// Gets a value indicating the File Extenstions this provider supports.
///
public IEnumerable SupportedMediaTypes { get; }
///
- /// Gets or Sets Data object generated by Process() method.
- ///
- /// Object with data if no error occured; otherwise, null.
- public object? Data { get; set; }
-
- ///
- /// Opens lyric file for [the specified item], and processes it for API return.
+ /// Opens lyric file for the requested item, and processes it for API return.
///
/// The item to to process.
- /// A representing the asynchronous operation.
+ /// If provider can determine lyrics, returns a with or without metadata; otherwise, null.
public LyricResponse? GetLyrics(BaseItem item)
{
string? lyricFilePath = LyricInfo.GetLyricFilePath(this, item.Path);
@@ -61,9 +55,9 @@ namespace MediaBrowser.Providers.Lyric
return null;
}
- List lyricsList = new List();
-
+ List lyricList = new List();
List sortedLyricData = new List();
+
var metaData = new ExpandoObject() as IDictionary;
string lrcFileContent = System.IO.File.ReadAllText(lyricFilePath);
@@ -105,15 +99,15 @@ namespace MediaBrowser.Providers.Lyric
{
var timeData = sortedLyricData[i].TimeTags.ToArray()[0].Value;
double ticks = Convert.ToDouble(timeData, new NumberFormatInfo()) * 10000;
- lyricsList.Add(new MediaBrowser.Controller.Lyrics.Lyric { Start = Math.Ceiling(ticks), Text = sortedLyricData[i].Text });
+ lyricList.Add(new Controller.Lyrics.Lyric { Start = Math.Ceiling(ticks), Text = sortedLyricData[i].Text });
}
if (metaData.Any())
{
- return new LyricResponse { MetaData = metaData, Lyrics = lyricsList };
+ return new LyricResponse { MetaData = metaData, Lyrics = lyricList };
}
- return new LyricResponse { Lyrics = lyricsList };
+ return new LyricResponse { Lyrics = lyricList };
}
}
}
diff --git a/MediaBrowser.Providers/Lyric/LyricManager.cs b/MediaBrowser.Providers/Lyric/LyricManager.cs
index 48572c63e4..698da46867 100644
--- a/MediaBrowser.Providers/Lyric/LyricManager.cs
+++ b/MediaBrowser.Providers/Lyric/LyricManager.cs
@@ -36,32 +36,26 @@ namespace MediaBrowser.Providers.Lyric
private readonly IMediaSourceManager _mediaSourceManager;
private readonly ILocalizationManager _localization;
- private ILyricProvider[] _lyricProviders;
+ private IEnumerable _lyricProviders;
public LyricManager(
ILogger logger,
IFileSystem fileSystem,
ILibraryMonitor monitor,
IMediaSourceManager mediaSourceManager,
- ILocalizationManager localizationManager)
+ ILocalizationManager localizationManager,
+ IEnumerable lyricProviders)
{
_logger = logger;
_fileSystem = fileSystem;
_monitor = monitor;
_mediaSourceManager = mediaSourceManager;
_localization = localizationManager;
+ _lyricProviders = lyricProviders;
}
///
- public void AddParts(IEnumerable lyricProviders)
- {
- _lyricProviders = lyricProviders
- .OrderBy(i => i is IHasOrder hasOrder ? hasOrder.Order : 0)
- .ToArray();
- }
-
- ///
- public LyricResponse GetLyric(BaseItem item)
+ public LyricResponse GetLyrics(BaseItem item)
{
foreach (ILyricProvider provider in _lyricProviders)
{
diff --git a/MediaBrowser.Providers/Lyric/TxtLyricProvider.cs b/MediaBrowser.Providers/Lyric/TxtLyricProvider.cs
index 939d8708b2..aa222ed97b 100644
--- a/MediaBrowser.Providers/Lyric/TxtLyricProvider.cs
+++ b/MediaBrowser.Providers/Lyric/TxtLyricProvider.cs
@@ -11,7 +11,7 @@ using MediaBrowser.Controller.Lyrics;
namespace MediaBrowser.Providers.Lyric
{
///
- /// TXT File Lyric Provider.
+ /// TXT Lyric Provider.
///
public class TxtLyricProvider : ILyricProvider
{
@@ -34,21 +34,15 @@ namespace MediaBrowser.Providers.Lyric
public string Name { get; }
///
- /// Gets a value indicating the File Extenstions this provider works with.
+ /// Gets a value indicating the File Extenstions this provider supports.
///
public IEnumerable SupportedMediaTypes { get; }
///
- /// Gets or Sets Data object generated by Process() method.
- ///
- /// Object with data if no error occured; otherwise, null.
- public object? Data { get; set; }
-
- ///
- /// Opens lyric file for [the specified item], and processes it for API return.
+ /// Opens lyric file for the requested item, and processes it for API return.
///
/// The item to to process.
- /// A representing the asynchronous operation.
+ /// If provider can determine lyrics, returns a ; otherwise, null.
public LyricResponse? GetLyrics(BaseItem item)
{
string? lyricFilePath = LyricInfo.GetLyricFilePath(this, item.Path);
@@ -58,25 +52,25 @@ namespace MediaBrowser.Providers.Lyric
return null;
}
- List lyricsList = new List();
+ List lyricList = new List();
string lyricData = System.IO.File.ReadAllText(lyricFilePath);
// 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);
+ char[] newLineDelims = new[] { '\r', '\n' };
+ string[] lyricTextLines = lyricData.Split(newLineDelims, StringSplitOptions.RemoveEmptyEntries);
if (!lyricTextLines.Any())
{
return null;
}
- foreach (string lyricLine in lyricTextLines)
+ foreach (string lyricTextLine in lyricTextLines)
{
- lyricsList.Add(new MediaBrowser.Controller.Lyrics.Lyric { Text = lyricLine });
+ lyricList.Add(new Controller.Lyrics.Lyric { Text = lyricTextLine });
}
- return new LyricResponse { Lyrics = lyricsList };
+ return new LyricResponse { Lyrics = lyricList };
}
}
}
--
cgit v1.2.3
From 823e2ec029d8708b71452afc7442524823d82acb Mon Sep 17 00:00:00 2001
From: 1hitsong <3330318+1hitsong@users.noreply.github.com>
Date: Sat, 17 Sep 2022 09:22:07 -0400
Subject: Removing unused lines
---
MediaBrowser.Controller/Lyrics/LyricInfo.cs | 7 -------
MediaBrowser.Controller/Lyrics/LyricResponse.cs | 2 --
MediaBrowser.Providers/Lyric/LrcLyricProvider.cs | 2 --
MediaBrowser.Providers/Lyric/TxtLyricProvider.cs | 3 ---
4 files changed, 14 deletions(-)
(limited to 'MediaBrowser.Controller')
diff --git a/MediaBrowser.Controller/Lyrics/LyricInfo.cs b/MediaBrowser.Controller/Lyrics/LyricInfo.cs
index 018f296b1a..ae831b4d23 100644
--- a/MediaBrowser.Controller/Lyrics/LyricInfo.cs
+++ b/MediaBrowser.Controller/Lyrics/LyricInfo.cs
@@ -1,12 +1,5 @@
-using System;
-using System.Collections.Generic;
using System.IO;
using System.Linq;
-using System.Threading.Tasks;
-using MediaBrowser.Controller.Entities;
-using MediaBrowser.Controller.Lyrics;
-using MediaBrowser.Controller.Net;
-using Microsoft.AspNetCore.Mvc;
namespace MediaBrowser.Controller.Lyrics
{
diff --git a/MediaBrowser.Controller/Lyrics/LyricResponse.cs b/MediaBrowser.Controller/Lyrics/LyricResponse.cs
index 498eb873c7..59ee5c7f2c 100644
--- a/MediaBrowser.Controller/Lyrics/LyricResponse.cs
+++ b/MediaBrowser.Controller/Lyrics/LyricResponse.cs
@@ -1,7 +1,5 @@
#nullable disable
-#pragma warning disable CS1591
-
using System.Collections.Generic;
namespace MediaBrowser.Controller.Lyrics
diff --git a/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs b/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs
index 10db10ac6f..ea42d75255 100644
--- a/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs
+++ b/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs
@@ -4,8 +4,6 @@ using System.Collections.ObjectModel;
using System.Dynamic;
using System.Globalization;
using System.Linq;
-using System.Threading.Tasks;
-using Jellyfin.Api.Helpers;
using LrcParser.Model;
using LrcParser.Parser;
using MediaBrowser.Controller.Entities;
diff --git a/MediaBrowser.Providers/Lyric/TxtLyricProvider.cs b/MediaBrowser.Providers/Lyric/TxtLyricProvider.cs
index aa222ed97b..8a51d7277c 100644
--- a/MediaBrowser.Providers/Lyric/TxtLyricProvider.cs
+++ b/MediaBrowser.Providers/Lyric/TxtLyricProvider.cs
@@ -2,9 +2,6 @@ using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
-using System.Threading.Tasks;
-using System.Xml.Linq;
-using Jellyfin.Api.Helpers;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Lyrics;
--
cgit v1.2.3
From 7d886116fd3b617cae6884a33b8b545358fa6289 Mon Sep 17 00:00:00 2001
From: 1hitsong <3330318+1hitsong@users.noreply.github.com>
Date: Sat, 17 Sep 2022 10:42:48 -0400
Subject: Var type refinements
---
MediaBrowser.Controller/Lyrics/Lyric.cs | 2 +-
MediaBrowser.Controller/Lyrics/LyricResponse.cs | 4 ++--
MediaBrowser.Providers/Lyric/LrcLyricProvider.cs | 13 +++++++------
3 files changed, 10 insertions(+), 9 deletions(-)
(limited to 'MediaBrowser.Controller')
diff --git a/MediaBrowser.Controller/Lyrics/Lyric.cs b/MediaBrowser.Controller/Lyrics/Lyric.cs
index 56a0a8a72d..35cdabbb9b 100644
--- a/MediaBrowser.Controller/Lyrics/Lyric.cs
+++ b/MediaBrowser.Controller/Lyrics/Lyric.cs
@@ -8,7 +8,7 @@ namespace MediaBrowser.Controller.Lyrics
///
/// Gets or sets the start time in ticks.
///
- public double? Start { get; set; }
+ public long? Start { get; set; }
///
/// Gets or sets the text.
diff --git a/MediaBrowser.Controller/Lyrics/LyricResponse.cs b/MediaBrowser.Controller/Lyrics/LyricResponse.cs
index 59ee5c7f2c..796ca3bc36 100644
--- a/MediaBrowser.Controller/Lyrics/LyricResponse.cs
+++ b/MediaBrowser.Controller/Lyrics/LyricResponse.cs
@@ -10,9 +10,9 @@ namespace MediaBrowser.Controller.Lyrics
public class LyricResponse
{
///
- /// Gets or sets MetaData.
+ /// Gets or sets Metadata.
///
- public IDictionary MetaData { get; set; }
+ public IDictionary Metadata { get; set; }
///
/// Gets or sets Lyrics.
diff --git a/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs b/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs
index ea42d75255..59a172cee2 100644
--- a/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs
+++ b/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs
@@ -8,6 +8,7 @@ using LrcParser.Model;
using LrcParser.Parser;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Lyrics;
+using Swashbuckle.AspNetCore.SwaggerGen;
namespace MediaBrowser.Providers.Lyric
{
@@ -56,7 +57,7 @@ namespace MediaBrowser.Providers.Lyric
List lyricList = new List();
List sortedLyricData = new List();
- var metaData = new ExpandoObject() as IDictionary;
+ IDictionary metaData = new Dictionary();
string lrcFileContent = System.IO.File.ReadAllText(lyricFilePath);
try
@@ -77,8 +78,8 @@ namespace MediaBrowser.Providers.Lyric
{
var metaDataField = metaDataRow.Split(":");
- string metaDataFieldName = metaDataField[0].Replace("[", string.Empty, StringComparison.Ordinal);
- string metaDataFieldValue = metaDataField[1].Replace("]", string.Empty, StringComparison.Ordinal);
+ string metaDataFieldName = metaDataField[0].Replace("[", string.Empty, StringComparison.Ordinal).Trim();
+ string metaDataFieldValue = metaDataField[1].Replace("]", string.Empty, StringComparison.Ordinal).Trim();
metaData.Add(metaDataFieldName, metaDataFieldValue);
}
@@ -96,13 +97,13 @@ namespace MediaBrowser.Providers.Lyric
for (int i = 0; i < sortedLyricData.Count; i++)
{
var timeData = sortedLyricData[i].TimeTags.ToArray()[0].Value;
- double ticks = Convert.ToDouble(timeData, new NumberFormatInfo()) * 10000;
- lyricList.Add(new Controller.Lyrics.Lyric { Start = Math.Ceiling(ticks), Text = sortedLyricData[i].Text });
+ long ticks = Convert.ToInt64(timeData, new NumberFormatInfo()) * 10000;
+ lyricList.Add(new Controller.Lyrics.Lyric { Start = ticks, Text = sortedLyricData[i].Text });
}
if (metaData.Any())
{
- return new LyricResponse { MetaData = metaData, Lyrics = lyricList };
+ return new LyricResponse { Metadata = metaData, Lyrics = lyricList };
}
return new LyricResponse { Lyrics = lyricList };
--
cgit v1.2.3
From c65819221d9a84ec0ae69a243fdcb17bce7aa65f Mon Sep 17 00:00:00 2001
From: 1hitsong <3330318+1hitsong@users.noreply.github.com>
Date: Sat, 17 Sep 2022 17:37:38 -0400
Subject: Code cleanups. Remove pragma commands
---
MediaBrowser.Controller/Lyrics/ILyricManager.cs | 36 ++---
MediaBrowser.Controller/Lyrics/ILyricProvider.cs | 39 +++---
MediaBrowser.Controller/Lyrics/Lyric.cs | 34 +++--
MediaBrowser.Controller/Lyrics/LyricInfo.cs | 39 +++---
MediaBrowser.Controller/Lyrics/LyricResponse.cs | 27 ++--
MediaBrowser.Providers/Lyric/LrcLyricProvider.cs | 152 ++++++++++-----------
MediaBrowser.Providers/Lyric/LyricManager.cs | 72 +++++-----
MediaBrowser.Providers/Lyric/TxtLyricProvider.cs | 86 +++++-------
.../MediaBrowser.Providers.csproj | 1 -
9 files changed, 231 insertions(+), 255 deletions(-)
(limited to 'MediaBrowser.Controller')
diff --git a/MediaBrowser.Controller/Lyrics/ILyricManager.cs b/MediaBrowser.Controller/Lyrics/ILyricManager.cs
index c0f78d177d..dad0250f6b 100644
--- a/MediaBrowser.Controller/Lyrics/ILyricManager.cs
+++ b/MediaBrowser.Controller/Lyrics/ILyricManager.cs
@@ -1,23 +1,23 @@
-#pragma warning disable CS1591
-
using MediaBrowser.Controller.Entities;
-namespace MediaBrowser.Controller.Lyrics
+namespace MediaBrowser.Controller.Lyrics;
+
+///
+/// Interface ILyricManager.
+///
+public interface ILyricManager
{
- public interface ILyricManager
- {
- ///
- /// Gets the lyrics.
- ///
- /// The media item.
- /// Lyrics for passed item.
- LyricResponse GetLyrics(BaseItem item);
+ ///
+ /// Gets the lyrics.
+ ///
+ /// The media item.
+ /// Lyrics for passed item.
+ LyricResponse GetLyrics(BaseItem item);
- ///
- /// Checks if requested item has a matching local lyric file.
- ///
- /// The media item.
- /// True if item has a matching lyric file; otherwise false.
- bool HasLyricFile(BaseItem item);
- }
+ ///
+ /// Checks if requested item has a matching local lyric file.
+ ///
+ /// The media item.
+ /// True if item has a matching lyric file; otherwise false.
+ bool HasLyricFile(BaseItem item);
}
diff --git a/MediaBrowser.Controller/Lyrics/ILyricProvider.cs b/MediaBrowser.Controller/Lyrics/ILyricProvider.cs
index 5e677ab26f..1b52de255f 100644
--- a/MediaBrowser.Controller/Lyrics/ILyricProvider.cs
+++ b/MediaBrowser.Controller/Lyrics/ILyricProvider.cs
@@ -1,29 +1,28 @@
using System.Collections.Generic;
using MediaBrowser.Controller.Entities;
-namespace MediaBrowser.Controller.Lyrics
+namespace MediaBrowser.Controller.Lyrics;
+
+///
+/// Interface ILyricsProvider.
+///
+public interface ILyricProvider
{
///
- /// Interface ILyricsProvider.
+ /// Gets a value indicating the provider name.
///
- public interface ILyricProvider
- {
- ///
- /// Gets a value indicating the provider name.
- ///
- string Name { get; }
+ string Name { get; }
- ///
- /// Gets the supported media types for this provider.
- ///
- /// The supported media types.
- IEnumerable SupportedMediaTypes { get; }
+ ///
+ /// Gets the supported media types for this provider.
+ ///
+ /// The supported media types.
+ IEnumerable SupportedMediaTypes { get; }
- ///
- /// Gets the lyrics.
- ///
- /// The media item.
- /// If found, returns lyrics for passed item; otherwise, null.
- LyricResponse? GetLyrics(BaseItem item);
- }
+ ///
+ /// Gets the lyrics.
+ ///
+ /// The media item.
+ /// If found, returns lyrics for passed item; otherwise, null.
+ LyricResponse? GetLyrics(BaseItem item);
}
diff --git a/MediaBrowser.Controller/Lyrics/Lyric.cs b/MediaBrowser.Controller/Lyrics/Lyric.cs
index 35cdabbb9b..f39fbb0221 100644
--- a/MediaBrowser.Controller/Lyrics/Lyric.cs
+++ b/MediaBrowser.Controller/Lyrics/Lyric.cs
@@ -1,18 +1,28 @@
-namespace MediaBrowser.Controller.Lyrics
+namespace MediaBrowser.Controller.Lyrics;
+
+///
+/// Lyric model.
+///
+public class Lyric
{
///
- /// Lyric model.
+ /// Initializes a new instance of the class.
///
- public class Lyric
+ /// The lyric start time in ticks.
+ /// The lyric text.
+ public Lyric(string text, long? start = null)
{
- ///
- /// Gets or sets the start time in ticks.
- ///
- public long? Start { get; set; }
-
- ///
- /// Gets or sets the text.
- ///
- public string Text { get; set; } = string.Empty;
+ Start = start;
+ Text = text;
}
+
+ ///
+ /// Gets the start time in ticks.
+ ///
+ public long? Start { get; }
+
+ ///
+ /// Gets the text.
+ ///
+ public string Text { get; }
}
diff --git a/MediaBrowser.Controller/Lyrics/LyricInfo.cs b/MediaBrowser.Controller/Lyrics/LyricInfo.cs
index ae831b4d23..61e205b6cc 100644
--- a/MediaBrowser.Controller/Lyrics/LyricInfo.cs
+++ b/MediaBrowser.Controller/Lyrics/LyricInfo.cs
@@ -1,34 +1,29 @@
using System.IO;
-using System.Linq;
-namespace MediaBrowser.Controller.Lyrics
+namespace MediaBrowser.Controller.Lyrics;
+
+///
+/// Lyric helper methods.
+///
+public static class LyricInfo
{
///
- /// Lyric helper methods.
+ /// Gets matching lyric file for a requested item.
///
- public static class LyricInfo
+ /// The lyricProvider interface to use.
+ /// Path of requested item.
+ /// Lyric file path if passed lyric provider's supported media type is found; otherwise, null.
+ public static string? GetLyricFilePath(ILyricProvider lyricProvider, string itemPath)
{
- ///
- /// Gets matching lyric file for a requested item.
- ///
- /// The lyricProvider interface to use.
- /// Path of requested item.
- /// Lyric file path if passed lyric provider's supported media type is found; otherwise, null.
- 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;
}
}
diff --git a/MediaBrowser.Controller/Lyrics/LyricResponse.cs b/MediaBrowser.Controller/Lyrics/LyricResponse.cs
index 796ca3bc36..e18cb1101e 100644
--- a/MediaBrowser.Controller/Lyrics/LyricResponse.cs
+++ b/MediaBrowser.Controller/Lyrics/LyricResponse.cs
@@ -1,22 +1,19 @@
-#nullable disable
-
using System.Collections.Generic;
-namespace MediaBrowser.Controller.Lyrics
+namespace MediaBrowser.Controller.Lyrics;
+
+///
+/// LyricResponse model.
+///
+public class LyricResponse
{
///
- /// LyricResponse model.
+ /// Gets or sets Metadata.
///
- public class LyricResponse
- {
- ///
- /// Gets or sets Metadata.
- ///
- public IDictionary Metadata { get; set; }
+ public IDictionary? Metadata { get; set; }
- ///
- /// Gets or sets Lyrics.
- ///
- public IEnumerable Lyrics { get; set; }
- }
+ ///
+ /// Gets or sets Lyrics.
+ ///
+ public IEnumerable? Lyrics { get; set; }
}
diff --git a/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs b/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs
index 59a172cee2..9bacfc2964 100644
--- a/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs
+++ b/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs
@@ -1,112 +1,102 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
-using System.Dynamic;
using System.Globalization;
using System.Linq;
using LrcParser.Model;
using LrcParser.Parser;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Lyrics;
-using Swashbuckle.AspNetCore.SwaggerGen;
-namespace MediaBrowser.Providers.Lyric
+namespace MediaBrowser.Providers.Lyric;
+
+///
+/// LRC Lyric Provider.
+///
+public class LrcLyricProvider : ILyricProvider
{
- ///
- /// LRC Lyric Provider.
- ///
- public class LrcLyricProvider : ILyricProvider
- {
- ///
- /// Initializes a new instance of the class.
- ///
- public LrcLyricProvider()
- {
- Name = "LrcLyricProvider";
+ ///
+ public string Name { get; } = "LrcLyricProvider";
- SupportedMediaTypes = new Collection
+ ///
+ public IEnumerable SupportedMediaTypes
+ {
+ get => new Collection
{
"lrc"
};
- }
+ }
- ///
- /// Gets a value indicating the provider name.
- ///
- public string Name { get; }
-
- ///
- /// Gets a value indicating the File Extenstions this provider supports.
- ///
- public IEnumerable SupportedMediaTypes { get; }
-
- ///
- /// Opens lyric file for the requested item, and processes it for API return.
- ///
- /// The item to to process.
- /// If provider can determine lyrics, returns a with or without metadata; otherwise, null.
- public LyricResponse? GetLyrics(BaseItem item)
- {
- string? lyricFilePath = LyricInfo.GetLyricFilePath(this, item.Path);
+ ///
+ /// Opens lyric file for the requested item, and processes it for API return.
+ ///
+ /// The item to to process.
+ /// If provider can determine lyrics, returns a with or without metadata; otherwise, null.
+ 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 lyricList = new List();
- List sortedLyricData = new List();
+ List lyricList = new List();
+ List sortedLyricData = new List();
- IDictionary metaData = new Dictionary();
- string lrcFileContent = System.IO.File.ReadAllText(lyricFilePath);
+ IDictionary metaData = new Dictionary();
+ 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 };
}
}
diff --git a/MediaBrowser.Providers/Lyric/LyricManager.cs b/MediaBrowser.Providers/Lyric/LyricManager.cs
index f5560b0542..06f913d079 100644
--- a/MediaBrowser.Providers/Lyric/LyricManager.cs
+++ b/MediaBrowser.Providers/Lyric/LyricManager.cs
@@ -1,55 +1,57 @@
-#nullable disable
-
-#pragma warning disable CS1591
-
using System.Collections.Generic;
using System.Linq;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Lyrics;
-namespace MediaBrowser.Providers.Lyric
+namespace MediaBrowser.Providers.Lyric;
+
+///
+/// Lyric Manager.
+///
+public class LyricManager : ILyricManager
{
- public class LyricManager : ILyricManager
- {
- private readonly ILyricProvider[] _lyricProviders;
+ private readonly ILyricProvider[] _lyricProviders;
- public LyricManager(IEnumerable lyricProviders)
- {
- _lyricProviders = lyricProviders.ToArray();
- }
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// All found lyricProviders.
+ public LyricManager(IEnumerable lyricProviders)
+ {
+ _lyricProviders = lyricProviders.ToArray();
+ }
- ///
- public LyricResponse GetLyrics(BaseItem item)
+ ///
+ 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;
}
- ///
- public bool HasLyricFile(BaseItem item)
+ return null;
+ }
+
+ ///
+ 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;
}
}
diff --git a/MediaBrowser.Providers/Lyric/TxtLyricProvider.cs b/MediaBrowser.Providers/Lyric/TxtLyricProvider.cs
index 8a51d7277c..d417c85981 100644
--- a/MediaBrowser.Providers/Lyric/TxtLyricProvider.cs
+++ b/MediaBrowser.Providers/Lyric/TxtLyricProvider.cs
@@ -5,69 +5,53 @@ using System.Linq;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Lyrics;
-namespace MediaBrowser.Providers.Lyric
+namespace MediaBrowser.Providers.Lyric;
+
+///
+/// TXT Lyric Provider.
+///
+public class TxtLyricProvider : ILyricProvider
{
- ///
- /// TXT Lyric Provider.
- ///
- public class TxtLyricProvider : ILyricProvider
- {
- ///
- /// Initializes a new instance of the class.
- ///
- public TxtLyricProvider()
- {
- Name = "TxtLyricProvider";
+ ///
+ public string Name { get; } = "TxtLyricProvider";
- SupportedMediaTypes = new Collection
+ ///
+ public IEnumerable SupportedMediaTypes
+ {
+ get => new Collection
{
"lrc", "txt"
};
- }
-
- ///
- /// Gets a value indicating the provider name.
- ///
- public string Name { get; }
+ }
- ///
- /// Gets a value indicating the File Extenstions this provider supports.
- ///
- public IEnumerable SupportedMediaTypes { get; }
+ ///
+ /// Opens lyric file for the requested item, and processes it for API return.
+ ///
+ /// The item to to process.
+ /// If provider can determine lyrics, returns a ; otherwise, null.
+ public LyricResponse? GetLyrics(BaseItem item)
+ {
+ string? lyricFilePath = LyricInfo.GetLyricFilePath(this, item.Path);
- ///
- /// Opens lyric file for the requested item, and processes it for API return.
- ///
- /// The item to to process.
- /// If provider can determine lyrics, returns a ; otherwise, null.
- public LyricResponse? GetLyrics(BaseItem item)
+ if (string.IsNullOrEmpty(lyricFilePath))
{
- string? lyricFilePath = LyricInfo.GetLyricFilePath(this, item.Path);
-
- if (string.IsNullOrEmpty(lyricFilePath))
- {
- return null;
- }
-
- List lyricList = new List();
-
- 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 lyricList = new List();
- 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 };
}
}
diff --git a/MediaBrowser.Providers/MediaBrowser.Providers.csproj b/MediaBrowser.Providers/MediaBrowser.Providers.csproj
index 8514489f8a..e12776ba05 100644
--- a/MediaBrowser.Providers/MediaBrowser.Providers.csproj
+++ b/MediaBrowser.Providers/MediaBrowser.Providers.csproj
@@ -6,7 +6,6 @@
-
--
cgit v1.2.3
From 64b013b121f472d2658e5f2b3a672c4c4ced342d Mon Sep 17 00:00:00 2001
From: 1hitsong <3330318+1hitsong@users.noreply.github.com>
Date: Sat, 17 Sep 2022 17:48:27 -0400
Subject: Resolve Azure build issues
---
MediaBrowser.Controller/Lyrics/ILyricManager.cs | 2 +-
MediaBrowser.Providers/Lyric/LrcLyricProvider.cs | 7 ++++++-
MediaBrowser.Providers/Lyric/LyricManager.cs | 2 +-
3 files changed, 8 insertions(+), 3 deletions(-)
(limited to 'MediaBrowser.Controller')
diff --git a/MediaBrowser.Controller/Lyrics/ILyricManager.cs b/MediaBrowser.Controller/Lyrics/ILyricManager.cs
index dad0250f6b..5920bcc628 100644
--- a/MediaBrowser.Controller/Lyrics/ILyricManager.cs
+++ b/MediaBrowser.Controller/Lyrics/ILyricManager.cs
@@ -12,7 +12,7 @@ public interface ILyricManager
///
/// The media item.
/// Lyrics for passed item.
- LyricResponse GetLyrics(BaseItem item);
+ LyricResponse? GetLyrics(BaseItem item);
///
/// Checks if requested item has a matching local lyric file.
diff --git a/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs b/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs
index 9bacfc2964..db87d92368 100644
--- a/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs
+++ b/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs
@@ -87,7 +87,12 @@ public class LrcLyricProvider : ILyricProvider
for (int i = 0; i < sortedLyricData.Count; i++)
{
- var timeData = sortedLyricData[i].TimeTags.ToArray()[0].Value;
+ var timeData = sortedLyricData[i].TimeTags.First().Value;
+ if (timeData is null)
+ {
+ continue;
+ }
+
long ticks = TimeSpan.FromMilliseconds((double)timeData).Ticks;
lyricList.Add(new Controller.Lyrics.Lyric(sortedLyricData[i].Text, ticks));
}
diff --git a/MediaBrowser.Providers/Lyric/LyricManager.cs b/MediaBrowser.Providers/Lyric/LyricManager.cs
index 06f913d079..0de008db7f 100644
--- a/MediaBrowser.Providers/Lyric/LyricManager.cs
+++ b/MediaBrowser.Providers/Lyric/LyricManager.cs
@@ -22,7 +22,7 @@ public class LyricManager : ILyricManager
}
///
- public LyricResponse GetLyrics(BaseItem item)
+ public LyricResponse? GetLyrics(BaseItem item)
{
foreach (ILyricProvider provider in _lyricProviders)
{
--
cgit v1.2.3
From 0b86630be7737e28555f0132322ecd02915284c5 Mon Sep 17 00:00:00 2001
From: 1hitsong <3330318+1hitsong@users.noreply.github.com>
Date: Sat, 17 Sep 2022 19:47:29 -0400
Subject: Use model properties for LRC metadata
---
MediaBrowser.Controller/Lyrics/LyricResponse.cs | 2 +-
MediaBrowser.Controller/Lyrics/Metadata.cs | 54 ++++++++++++++++++++++
.../MediaBrowser.Controller.csproj | 1 +
MediaBrowser.Providers/Lyric/LrcLyricProvider.cs | 11 +++--
4 files changed, 64 insertions(+), 4 deletions(-)
create mode 100644 MediaBrowser.Controller/Lyrics/Metadata.cs
(limited to 'MediaBrowser.Controller')
diff --git a/MediaBrowser.Controller/Lyrics/LyricResponse.cs b/MediaBrowser.Controller/Lyrics/LyricResponse.cs
index e18cb1101e..adc13050ee 100644
--- a/MediaBrowser.Controller/Lyrics/LyricResponse.cs
+++ b/MediaBrowser.Controller/Lyrics/LyricResponse.cs
@@ -10,7 +10,7 @@ public class LyricResponse
///
/// Gets or sets Metadata.
///
- public IDictionary? Metadata { get; set; }
+ public Metadata? Metadata { get; set; }
///
/// Gets or sets Lyrics.
diff --git a/MediaBrowser.Controller/Lyrics/Metadata.cs b/MediaBrowser.Controller/Lyrics/Metadata.cs
new file mode 100644
index 0000000000..114b56777a
--- /dev/null
+++ b/MediaBrowser.Controller/Lyrics/Metadata.cs
@@ -0,0 +1,54 @@
+using System.Collections.Generic;
+
+namespace MediaBrowser.Controller.Lyrics;
+
+///
+/// Metadata model.
+///
+public class Metadata
+{
+ ///
+ /// Gets or sets Artist - [ar:The song artist].
+ ///
+ public string? Ar { get; set; }
+
+ ///
+ /// Gets or sets Album - [al:The album this song is on].
+ ///
+ public string? Al { get; set; }
+
+ ///
+ /// Gets or sets Title - [ti:The title of the song].
+ ///
+ public string? Ti { get; set; }
+
+ ///
+ /// Gets or sets Author - [au:Creator of the lyric data].
+ ///
+ public string? Au { get; set; }
+
+ ///
+ /// Gets or sets Length - [length:How long the song is].
+ ///
+ public string? Length { get; set; }
+
+ ///
+ /// Gets or sets By - [by:Creator of the LRC file].
+ ///
+ public string? By { get; set; }
+
+ ///
+ /// Gets or sets Offset - [offsec:+/- Timestamp adjustment in milliseconds].
+ ///
+ public string? Offset { get; set; }
+
+ ///
+ /// Gets or sets Creator - [re:The Software used to create the LRC file].
+ ///
+ public string? Re { get; set; }
+
+ ///
+ /// Gets or sets Version - [ve:The version of the Creator used].
+ ///
+ public string? Ve { get; set; }
+}
diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj
index d4e025a43e..c08e276dcf 100644
--- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj
+++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj
@@ -18,6 +18,7 @@
+
diff --git a/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs b/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs
index db87d92368..b527c5303c 100644
--- a/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs
+++ b/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Linq;
+using AutoMapper;
using LrcParser.Model;
using LrcParser.Parser;
using MediaBrowser.Controller.Entities;
@@ -44,7 +45,8 @@ public class LrcLyricProvider : ILyricProvider
List lyricList = new List();
List sortedLyricData = new List();
- IDictionary metaData = new Dictionary();
+ // Must be for automapper support
+ IDictionary metaData = new Dictionary();
string lrcFileContent = System.IO.File.ReadAllText(lyricFilePath);
try
@@ -69,7 +71,7 @@ public class LrcLyricProvider : ILyricProvider
continue;
}
- string metaDataFieldName = metaDataField[0][1..].Trim();
+ string metaDataFieldName = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(metaDataField[0][1..].Trim().ToLowerInvariant());
string metaDataFieldValue = metaDataField[1][..^1].Trim();
metaData.Add(metaDataFieldName, metaDataFieldValue);
@@ -85,6 +87,9 @@ public class LrcLyricProvider : ILyricProvider
return null;
}
+ var config = new MapperConfiguration(cfg => { });
+ var mapper = config.CreateMapper();
+
for (int i = 0; i < sortedLyricData.Count; i++)
{
var timeData = sortedLyricData[i].TimeTags.First().Value;
@@ -99,7 +104,7 @@ public class LrcLyricProvider : ILyricProvider
if (metaData.Any())
{
- return new LyricResponse { Metadata = metaData, Lyrics = lyricList };
+ return new LyricResponse { Metadata = mapper.Map(metaData), Lyrics = lyricList };
}
return new LyricResponse { Lyrics = lyricList };
--
cgit v1.2.3
From a52d108af6b8519715bc7005e7db3f1a116760bc Mon Sep 17 00:00:00 2001
From: 1hitsong <3330318+1hitsong@users.noreply.github.com>
Date: Sun, 18 Sep 2022 11:47:57 -0400
Subject: Remove automapper tool
---
MediaBrowser.Controller/Lyrics/LyricMetadata.cs | 52 +++++++++++++++
MediaBrowser.Controller/Lyrics/LyricResponse.cs | 2 +-
MediaBrowser.Controller/Lyrics/Metadata.cs | 54 ---------------
.../MediaBrowser.Controller.csproj | 1 -
MediaBrowser.Providers/Lyric/LrcLyricProvider.cs | 78 +++++++++++++++++++---
5 files changed, 120 insertions(+), 67 deletions(-)
create mode 100644 MediaBrowser.Controller/Lyrics/LyricMetadata.cs
delete mode 100644 MediaBrowser.Controller/Lyrics/Metadata.cs
(limited to 'MediaBrowser.Controller')
diff --git a/MediaBrowser.Controller/Lyrics/LyricMetadata.cs b/MediaBrowser.Controller/Lyrics/LyricMetadata.cs
new file mode 100644
index 0000000000..36a833f85c
--- /dev/null
+++ b/MediaBrowser.Controller/Lyrics/LyricMetadata.cs
@@ -0,0 +1,52 @@
+namespace MediaBrowser.Controller.Lyrics;
+
+///
+/// LyricMetadata model.
+///
+public class LyricMetadata
+{
+ ///
+ /// Gets or sets Artist - The song artist.
+ ///
+ public string? Artist { get; set; }
+
+ ///
+ /// Gets or sets Album - The album this song is on.
+ ///
+ public string? Album { get; set; }
+
+ ///
+ /// Gets or sets Title - The title of the song.
+ ///
+ public string? Title { get; set; }
+
+ ///
+ /// Gets or sets Author - Creator of the lyric data.
+ ///
+ public string? Author { get; set; }
+
+ ///
+ /// Gets or sets Length - How long the song is.
+ ///
+ public string? Length { get; set; }
+
+ ///
+ /// Gets or sets By - Creator of the LRC file.
+ ///
+ public string? By { get; set; }
+
+ ///
+ /// Gets or sets Offset - Offset:+/- Timestamp adjustment in milliseconds.
+ ///
+ public string? Offset { get; set; }
+
+ ///
+ /// Gets or sets Creator - The Software used to create the LRC file.
+ ///
+ public string? Creator { get; set; }
+
+ ///
+ /// Gets or sets Version - The version of the Creator used.
+ ///
+ public string? Version { get; set; }
+}
diff --git a/MediaBrowser.Controller/Lyrics/LyricResponse.cs b/MediaBrowser.Controller/Lyrics/LyricResponse.cs
index adc13050ee..9892483889 100644
--- a/MediaBrowser.Controller/Lyrics/LyricResponse.cs
+++ b/MediaBrowser.Controller/Lyrics/LyricResponse.cs
@@ -10,7 +10,7 @@ public class LyricResponse
///
/// Gets or sets Metadata.
///
- public Metadata? Metadata { get; set; }
+ public LyricMetadata? Metadata { get; set; }
///
/// Gets or sets Lyrics.
diff --git a/MediaBrowser.Controller/Lyrics/Metadata.cs b/MediaBrowser.Controller/Lyrics/Metadata.cs
deleted file mode 100644
index 114b56777a..0000000000
--- a/MediaBrowser.Controller/Lyrics/Metadata.cs
+++ /dev/null
@@ -1,54 +0,0 @@
-using System.Collections.Generic;
-
-namespace MediaBrowser.Controller.Lyrics;
-
-///
-/// Metadata model.
-///
-public class Metadata
-{
- ///
- /// Gets or sets Artist - [ar:The song artist].
- ///
- public string? Ar { get; set; }
-
- ///
- /// Gets or sets Album - [al:The album this song is on].
- ///
- public string? Al { get; set; }
-
- ///
- /// Gets or sets Title - [ti:The title of the song].
- ///
- public string? Ti { get; set; }
-
- ///
- /// Gets or sets Author - [au:Creator of the lyric data].
- ///
- public string? Au { get; set; }
-
- ///
- /// Gets or sets Length - [length:How long the song is].
- ///
- public string? Length { get; set; }
-
- ///
- /// Gets or sets By - [by:Creator of the LRC file].
- ///
- public string? By { get; set; }
-
- ///
- /// Gets or sets Offset - [offsec:+/- Timestamp adjustment in milliseconds].
- ///
- public string? Offset { get; set; }
-
- ///
- /// Gets or sets Creator - [re:The Software used to create the LRC file].
- ///
- public string? Re { get; set; }
-
- ///
- /// Gets or sets Version - [ve:The version of the Creator used].
- ///
- public string? Ve { get; set; }
-}
diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj
index c08e276dcf..d4e025a43e 100644
--- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj
+++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj
@@ -18,7 +18,6 @@
-
diff --git a/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs b/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs
index b527c5303c..4cc06dac8d 100644
--- a/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs
+++ b/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs
@@ -1,13 +1,12 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
-using System.Globalization;
using System.Linq;
-using AutoMapper;
using LrcParser.Model;
using LrcParser.Parser;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Lyrics;
+using Newtonsoft.Json.Linq;
namespace MediaBrowser.Providers.Lyric;
@@ -45,8 +44,7 @@ public class LrcLyricProvider : ILyricProvider
List lyricList = new List();
List sortedLyricData = new List();
- // Must be for automapper support
- IDictionary metaData = new Dictionary();
+ IDictionary fileMetaData = new Dictionary();
string lrcFileContent = System.IO.File.ReadAllText(lyricFilePath);
try
@@ -71,10 +69,10 @@ public class LrcLyricProvider : ILyricProvider
continue;
}
- string metaDataFieldName = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(metaDataField[0][1..].Trim().ToLowerInvariant());
+ string metaDataFieldName = metaDataField[0][1..].Trim().ToLowerInvariant();
string metaDataFieldValue = metaDataField[1][..^1].Trim();
- metaData.Add(metaDataFieldName, metaDataFieldValue);
+ fileMetaData.Add(metaDataFieldName, metaDataFieldValue);
}
}
catch
@@ -87,9 +85,6 @@ public class LrcLyricProvider : ILyricProvider
return null;
}
- var config = new MapperConfiguration(cfg => { });
- var mapper = config.CreateMapper();
-
for (int i = 0; i < sortedLyricData.Count; i++)
{
var timeData = sortedLyricData[i].TimeTags.First().Value;
@@ -102,11 +97,72 @@ public class LrcLyricProvider : ILyricProvider
lyricList.Add(new Controller.Lyrics.Lyric(sortedLyricData[i].Text, ticks));
}
- if (metaData.Any())
+ if (fileMetaData.Any())
{
- return new LyricResponse { Metadata = mapper.Map(metaData), Lyrics = lyricList };
+ // Map metaData values from LRC file to LyricMetadata properties
+ LyricMetadata lyricMetadata = MapMetadataValues(fileMetaData);
+
+ return new LyricResponse { Metadata = lyricMetadata, Lyrics = lyricList };
}
return new LyricResponse { Lyrics = lyricList };
}
+
+ ///
+ /// Converts metadata from an LRC file to LyricMetadata properties.
+ ///
+ /// The metadata from the LRC file.
+ /// A lyricMetadata object with mapped property data.
+ private LyricMetadata MapMetadataValues(IDictionary metaData)
+ {
+ LyricMetadata lyricMetadata = new LyricMetadata();
+
+ if (metaData.TryGetValue("ar", out var artist) && artist is not null)
+ {
+ lyricMetadata.Artist = artist;
+ }
+
+ if (metaData.TryGetValue("al", out var album) && album is not null)
+ {
+ lyricMetadata.Album = album;
+ }
+
+ if (metaData.TryGetValue("ti", out var title) && title is not null)
+ {
+ lyricMetadata.Title = title;
+ }
+
+ if (metaData.TryGetValue("au", out var author) && author is not null)
+ {
+ lyricMetadata.Author = author;
+ }
+
+ if (metaData.TryGetValue("length", out var length) && length is not null)
+ {
+ lyricMetadata.Length = length;
+ }
+
+ if (metaData.TryGetValue("by", out var by) && by is not null)
+ {
+ lyricMetadata.By = by;
+ }
+
+ if (metaData.TryGetValue("offset", out var offset) && offset is not null)
+ {
+ lyricMetadata.Offset = offset;
+ }
+
+ if (metaData.TryGetValue("re", out var creator) && creator is not null)
+ {
+ lyricMetadata.Creator = creator;
+ }
+
+ if (metaData.TryGetValue("ve", out var version) && version is not null)
+ {
+ lyricMetadata.Version = version;
+ }
+
+ return lyricMetadata;
+
+ }
}
--
cgit v1.2.3
From f737581d49dd9f6ab0c68269f8be073df27fb0ba Mon Sep 17 00:00:00 2001
From: 1hitsong <3330318+1hitsong@users.noreply.github.com>
Date: Sun, 18 Sep 2022 13:13:01 -0400
Subject: Use providers in order of priority
---
MediaBrowser.Controller/Lyrics/ILyricProvider.cs | 7 ++++
MediaBrowser.Providers/Lyric/LrcLyricProvider.cs | 48 ++++++++++++++++--------
MediaBrowser.Providers/Lyric/LyricManager.cs | 2 +-
MediaBrowser.Providers/Lyric/TxtLyricProvider.cs | 7 ++++
4 files changed, 47 insertions(+), 17 deletions(-)
(limited to 'MediaBrowser.Controller')
diff --git a/MediaBrowser.Controller/Lyrics/ILyricProvider.cs b/MediaBrowser.Controller/Lyrics/ILyricProvider.cs
index 1b52de255f..651fe507f9 100644
--- a/MediaBrowser.Controller/Lyrics/ILyricProvider.cs
+++ b/MediaBrowser.Controller/Lyrics/ILyricProvider.cs
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using MediaBrowser.Controller.Entities;
+using MediaBrowser.Controller.Resolvers;
namespace MediaBrowser.Controller.Lyrics;
@@ -13,6 +14,12 @@ public interface ILyricProvider
///
string Name { get; }
+ ///
+ /// Gets the priority.
+ ///
+ /// The priority.
+ ResolverPriority Priority { get; }
+
///
/// Gets the supported media types for this provider.
///
diff --git a/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs b/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs
index 90396e5532..4690c3e209 100644
--- a/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs
+++ b/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs
@@ -1,12 +1,12 @@
using System;
using System.Collections.Generic;
-using System.Collections.ObjectModel;
using System.Linq;
using LrcParser.Model;
using LrcParser.Parser;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Lyrics;
-using Newtonsoft.Json.Linq;
+using MediaBrowser.Controller.Resolvers;
+using Microsoft.Extensions.Logging;
namespace MediaBrowser.Providers.Lyric;
@@ -15,9 +15,26 @@ namespace MediaBrowser.Providers.Lyric;
///
public class LrcLyricProvider : ILyricProvider
{
+ private readonly ILogger _logger;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Instance of the interface.
+ public LrcLyricProvider(ILogger logger)
+ {
+ _logger = logger;
+ }
+
///
public string Name => "LrcLyricProvider";
+ ///
+ /// Gets the priority.
+ ///
+ /// The priority.
+ public ResolverPriority Priority => ResolverPriority.First;
+
///
public IEnumerable SupportedMediaTypes { get; } = new[] { "lrc" };
@@ -38,7 +55,7 @@ public class LrcLyricProvider : ILyricProvider
List lyricList = new List();
List sortedLyricData = new List();
- IDictionary fileMetaData = new Dictionary();
+ IDictionary fileMetaData = new Dictionary(StringComparer.OrdinalIgnoreCase);
string lrcFileContent = System.IO.File.ReadAllText(lyricFilePath);
try
@@ -63,15 +80,15 @@ public class LrcLyricProvider : ILyricProvider
continue;
}
- string metaDataFieldName = metaDataField[0][1..].Trim().ToLowerInvariant();
+ string metaDataFieldName = metaDataField[0][1..].Trim();
string metaDataFieldValue = metaDataField[1][..^1].Trim();
fileMetaData.Add(metaDataFieldName, metaDataFieldValue);
}
}
- catch
+ catch (Exception ex)
{
- return null;
+ _logger.LogError(ex, "Error parsing lyric data from {Provider}", Name);
}
if (sortedLyricData.Count == 0)
@@ -111,52 +128,51 @@ public class LrcLyricProvider : ILyricProvider
{
LyricMetadata lyricMetadata = new LyricMetadata();
- if (metaData.TryGetValue("ar", out var artist) && artist is not null)
+ if (metaData.TryGetValue("ar", out var artist) && !string.IsNullOrEmpty(artist))
{
lyricMetadata.Artist = artist;
}
- if (metaData.TryGetValue("al", out var album) && album is not null)
+ if (metaData.TryGetValue("al", out var album) && !string.IsNullOrEmpty(album))
{
lyricMetadata.Album = album;
}
- if (metaData.TryGetValue("ti", out var title) && title is not null)
+ if (metaData.TryGetValue("ti", out var title) && !string.IsNullOrEmpty(title))
{
lyricMetadata.Title = title;
}
- if (metaData.TryGetValue("au", out var author) && author is not null)
+ if (metaData.TryGetValue("au", out var author) && !string.IsNullOrEmpty(author))
{
lyricMetadata.Author = author;
}
- if (metaData.TryGetValue("length", out var length) && length is not null)
+ if (metaData.TryGetValue("length", out var length) && !string.IsNullOrEmpty(length))
{
lyricMetadata.Length = length;
}
- if (metaData.TryGetValue("by", out var by) && by is not null)
+ if (metaData.TryGetValue("by", out var by) && !string.IsNullOrEmpty(by))
{
lyricMetadata.By = by;
}
- if (metaData.TryGetValue("offset", out var offset) && offset is not null)
+ if (metaData.TryGetValue("offset", out var offset) && !string.IsNullOrEmpty(offset))
{
lyricMetadata.Offset = offset;
}
- if (metaData.TryGetValue("re", out var creator) && creator is not null)
+ if (metaData.TryGetValue("re", out var creator) && !string.IsNullOrEmpty(creator))
{
lyricMetadata.Creator = creator;
}
- if (metaData.TryGetValue("ve", out var version) && version is not null)
+ if (metaData.TryGetValue("ve", out var version) && !string.IsNullOrEmpty(version))
{
lyricMetadata.Version = version;
}
return lyricMetadata;
-
}
}
diff --git a/MediaBrowser.Providers/Lyric/LyricManager.cs b/MediaBrowser.Providers/Lyric/LyricManager.cs
index 0de008db7f..7487c68615 100644
--- a/MediaBrowser.Providers/Lyric/LyricManager.cs
+++ b/MediaBrowser.Providers/Lyric/LyricManager.cs
@@ -18,7 +18,7 @@ public class LyricManager : ILyricManager
/// All found lyricProviders.
public LyricManager(IEnumerable lyricProviders)
{
- _lyricProviders = lyricProviders.ToArray();
+ _lyricProviders = lyricProviders.OrderBy(i => i.Priority).ToArray();
}
///
diff --git a/MediaBrowser.Providers/Lyric/TxtLyricProvider.cs b/MediaBrowser.Providers/Lyric/TxtLyricProvider.cs
index a2161c427f..c690086862 100644
--- a/MediaBrowser.Providers/Lyric/TxtLyricProvider.cs
+++ b/MediaBrowser.Providers/Lyric/TxtLyricProvider.cs
@@ -4,6 +4,7 @@ using System.Collections.ObjectModel;
using System.Linq;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Lyrics;
+using MediaBrowser.Controller.Resolvers;
namespace MediaBrowser.Providers.Lyric;
@@ -15,6 +16,12 @@ public class TxtLyricProvider : ILyricProvider
///
public string Name => "TxtLyricProvider";
+ ///
+ /// Gets the priority.
+ ///
+ /// The priority.
+ public ResolverPriority Priority => ResolverPriority.Second;
+
///
public IEnumerable SupportedMediaTypes { get; } = new[] { "lrc", "txt" };
--
cgit v1.2.3
From dce81d88182c90fdce90f2690b3adb22485fecd4 Mon Sep 17 00:00:00 2001
From: 1hitsong <3330318+1hitsong@users.noreply.github.com>
Date: Sun, 18 Sep 2022 14:53:25 -0400
Subject: Update MediaBrowser.Controller/Lyrics/LyricResponse.cs
Co-authored-by: Niels van Velzen
---
MediaBrowser.Controller/Lyrics/LyricResponse.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'MediaBrowser.Controller')
diff --git a/MediaBrowser.Controller/Lyrics/LyricResponse.cs b/MediaBrowser.Controller/Lyrics/LyricResponse.cs
index 9892483889..f3d8b07bc8 100644
--- a/MediaBrowser.Controller/Lyrics/LyricResponse.cs
+++ b/MediaBrowser.Controller/Lyrics/LyricResponse.cs
@@ -10,7 +10,7 @@ public class LyricResponse
///
/// Gets or sets Metadata.
///
- public LyricMetadata? Metadata { get; set; }
+ public LyricMetadata Metadata { get; set; }
///
/// Gets or sets Lyrics.
--
cgit v1.2.3
From dddebec794c72242952cb45e84fed452d828a641 Mon Sep 17 00:00:00 2001
From: 1hitsong <3330318+1hitsong@users.noreply.github.com>
Date: Sun, 18 Sep 2022 14:53:36 -0400
Subject: Update MediaBrowser.Controller/Lyrics/LyricResponse.cs
Co-authored-by: Niels van Velzen
---
MediaBrowser.Controller/Lyrics/LyricResponse.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'MediaBrowser.Controller')
diff --git a/MediaBrowser.Controller/Lyrics/LyricResponse.cs b/MediaBrowser.Controller/Lyrics/LyricResponse.cs
index f3d8b07bc8..405e8cac18 100644
--- a/MediaBrowser.Controller/Lyrics/LyricResponse.cs
+++ b/MediaBrowser.Controller/Lyrics/LyricResponse.cs
@@ -15,5 +15,5 @@ public class LyricResponse
///
/// Gets or sets Lyrics.
///
- public IEnumerable? Lyrics { get; set; }
+ public IEnumerable Lyrics { get; set; }
}
--
cgit v1.2.3
From 7e923e268865d8c0933a22247424d205429a474b Mon Sep 17 00:00:00 2001
From: 1hitsong <3330318+1hitsong@users.noreply.github.com>
Date: Sun, 18 Sep 2022 16:05:50 -0400
Subject: Use numeric values for metadata values
---
MediaBrowser.Controller/Lyrics/ILyricProvider.cs | 2 +-
MediaBrowser.Controller/Lyrics/Lyric.cs | 28 -------------
MediaBrowser.Controller/Lyrics/LyricLine.cs | 28 +++++++++++++
MediaBrowser.Controller/Lyrics/LyricMetadata.cs | 6 ++-
MediaBrowser.Controller/Lyrics/LyricResponse.cs | 2 +-
MediaBrowser.Providers/Lyric/LrcLyricProvider.cs | 53 ++++++++++++++++++++----
MediaBrowser.Providers/Lyric/TxtLyricProvider.cs | 9 ++--
7 files changed, 81 insertions(+), 47 deletions(-)
delete mode 100644 MediaBrowser.Controller/Lyrics/Lyric.cs
create mode 100644 MediaBrowser.Controller/Lyrics/LyricLine.cs
(limited to 'MediaBrowser.Controller')
diff --git a/MediaBrowser.Controller/Lyrics/ILyricProvider.cs b/MediaBrowser.Controller/Lyrics/ILyricProvider.cs
index 651fe507f9..c5b6252267 100644
--- a/MediaBrowser.Controller/Lyrics/ILyricProvider.cs
+++ b/MediaBrowser.Controller/Lyrics/ILyricProvider.cs
@@ -24,7 +24,7 @@ public interface ILyricProvider
/// Gets the supported media types for this provider.
///
/// The supported media types.
- IEnumerable SupportedMediaTypes { get; }
+ IReadOnlyCollection SupportedMediaTypes { get; }
///
/// Gets the lyrics.
diff --git a/MediaBrowser.Controller/Lyrics/Lyric.cs b/MediaBrowser.Controller/Lyrics/Lyric.cs
deleted file mode 100644
index f39fbb0221..0000000000
--- a/MediaBrowser.Controller/Lyrics/Lyric.cs
+++ /dev/null
@@ -1,28 +0,0 @@
-namespace MediaBrowser.Controller.Lyrics;
-
-///
-/// Lyric model.
-///
-public class Lyric
-{
- ///
- /// Initializes a new instance of the class.
- ///
- /// The lyric start time in ticks.
- /// The lyric text.
- public Lyric(string text, long? start = null)
- {
- Start = start;
- Text = text;
- }
-
- ///
- /// Gets the start time in ticks.
- ///
- public long? Start { get; }
-
- ///
- /// Gets the text.
- ///
- public string Text { get; }
-}
diff --git a/MediaBrowser.Controller/Lyrics/LyricLine.cs b/MediaBrowser.Controller/Lyrics/LyricLine.cs
new file mode 100644
index 0000000000..43997f6564
--- /dev/null
+++ b/MediaBrowser.Controller/Lyrics/LyricLine.cs
@@ -0,0 +1,28 @@
+namespace MediaBrowser.Controller.Lyrics;
+
+///
+/// Lyric model.
+///
+public class LyricLine
+{
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The lyric start time in ticks.
+ /// The lyric text.
+ public LyricLine(string text, long? start = null)
+ {
+ Start = start;
+ Text = text;
+ }
+
+ ///
+ /// Gets the start time in ticks.
+ ///
+ public long? Start { get; }
+
+ ///
+ /// Gets the text.
+ ///
+ public string Text { get; }
+}
diff --git a/MediaBrowser.Controller/Lyrics/LyricMetadata.cs b/MediaBrowser.Controller/Lyrics/LyricMetadata.cs
index 36a833f85c..0ba7779750 100644
--- a/MediaBrowser.Controller/Lyrics/LyricMetadata.cs
+++ b/MediaBrowser.Controller/Lyrics/LyricMetadata.cs
@@ -1,3 +1,5 @@
+using System;
+
namespace MediaBrowser.Controller.Lyrics;
///
@@ -28,7 +30,7 @@ public class LyricMetadata
///
/// Gets or sets Length - How long the song is.
///
- public string? Length { get; set; }
+ public long? Length { get; set; }
///
/// Gets or sets By - Creator of the LRC file.
@@ -38,7 +40,7 @@ public class LyricMetadata
///
/// Gets or sets Offset - Offset:+/- Timestamp adjustment in milliseconds.
///
- public string? Offset { get; set; }
+ public long? Offset { get; set; }
///
/// Gets or sets Creator - The Software used to create the LRC file.
diff --git a/MediaBrowser.Controller/Lyrics/LyricResponse.cs b/MediaBrowser.Controller/Lyrics/LyricResponse.cs
index 405e8cac18..b3c65ac8c0 100644
--- a/MediaBrowser.Controller/Lyrics/LyricResponse.cs
+++ b/MediaBrowser.Controller/Lyrics/LyricResponse.cs
@@ -15,5 +15,5 @@ public class LyricResponse
///
/// Gets or sets Lyrics.
///
- public IEnumerable Lyrics { get; set; }
+ public IEnumerable Lyrics { get; set; }
}
diff --git a/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs b/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs
index 4690c3e209..50fa519b3e 100644
--- a/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs
+++ b/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs
@@ -1,11 +1,13 @@
using System;
using System.Collections.Generic;
+using System.Globalization;
using System.Linq;
using LrcParser.Model;
using LrcParser.Parser;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Lyrics;
using MediaBrowser.Controller.Resolvers;
+using MediaBrowser.Model.Entities;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Providers.Lyric;
@@ -36,7 +38,7 @@ public class LrcLyricProvider : ILyricProvider
public ResolverPriority Priority => ResolverPriority.First;
///
- public IEnumerable SupportedMediaTypes { get; } = new[] { "lrc" };
+ public IReadOnlyCollection SupportedMediaTypes { get; } = new[] { "lrc" };
///
/// Opens lyric file for the requested item, and processes it for API return.
@@ -52,7 +54,7 @@ public class LrcLyricProvider : ILyricProvider
return null;
}
- List lyricList = new List();
+ List lyricList = new List();
List sortedLyricData = new List();
IDictionary fileMetaData = new Dictionary(StringComparer.OrdinalIgnoreCase);
@@ -74,14 +76,28 @@ public class LrcLyricProvider : ILyricProvider
foreach (string metaDataRow in metaDataRows)
{
- var metaDataField = metaDataRow.Split(':');
- if (metaDataField.Length != 2)
+ int colonCount = metaDataRow.Count(f => (f == ':'));
+ if (colonCount == 0)
{
continue;
}
- string metaDataFieldName = metaDataField[0][1..].Trim();
- string metaDataFieldValue = metaDataField[1][..^1].Trim();
+ string[] metaDataField;
+ string metaDataFieldName;
+ string metaDataFieldValue;
+
+ if (colonCount == 1)
+ {
+ metaDataField = metaDataRow.Split(':');
+ metaDataFieldName = metaDataField[0][1..].Trim();
+ metaDataFieldValue = metaDataField[1][..^1].Trim();
+ }
+ else
+ {
+ int colonIndex = metaDataRow.IndexOf(':', StringComparison.OrdinalIgnoreCase);
+ metaDataFieldName = metaDataRow[..colonIndex][1..].Trim();
+ metaDataFieldValue = metaDataRow[(colonIndex + 1)..][..^1].Trim();
+ }
fileMetaData.Add(metaDataFieldName, metaDataFieldValue);
}
@@ -105,7 +121,7 @@ public class LrcLyricProvider : ILyricProvider
}
long ticks = TimeSpan.FromMilliseconds(timeData.Value).Ticks;
- lyricList.Add(new Controller.Lyrics.Lyric(sortedLyricData[i].Text, ticks));
+ lyricList.Add(new LyricLine(sortedLyricData[i].Text, ticks));
}
if (fileMetaData.Count != 0)
@@ -150,7 +166,23 @@ public class LrcLyricProvider : ILyricProvider
if (metaData.TryGetValue("length", out var length) && !string.IsNullOrEmpty(length))
{
- lyricMetadata.Length = length;
+ // Ensure minutes include leading zero
+ var lengthData = length.Split(':');
+ if (lengthData[0].Length == 1)
+ {
+ length = "0" + length;
+ }
+
+ // If only Minutes and Seconds were provided, prepend zeros for hours
+ if (lengthData.Length == 2)
+ {
+ length = "00:" + length;
+ }
+
+ if (DateTime.TryParseExact(length, "HH:mm:ss", null, DateTimeStyles.None, out var value))
+ {
+ lyricMetadata.Length = value.TimeOfDay.Ticks;
+ }
}
if (metaData.TryGetValue("by", out var by) && !string.IsNullOrEmpty(by))
@@ -160,7 +192,10 @@ public class LrcLyricProvider : ILyricProvider
if (metaData.TryGetValue("offset", out var offset) && !string.IsNullOrEmpty(offset))
{
- lyricMetadata.Offset = offset;
+ if (int.TryParse(offset, out var value))
+ {
+ lyricMetadata.Offset = TimeSpan.FromMilliseconds(value).Ticks;
+ }
}
if (metaData.TryGetValue("re", out var creator) && !string.IsNullOrEmpty(creator))
diff --git a/MediaBrowser.Providers/Lyric/TxtLyricProvider.cs b/MediaBrowser.Providers/Lyric/TxtLyricProvider.cs
index c690086862..cd0e1599e7 100644
--- a/MediaBrowser.Providers/Lyric/TxtLyricProvider.cs
+++ b/MediaBrowser.Providers/Lyric/TxtLyricProvider.cs
@@ -1,7 +1,4 @@
-using System;
using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.Linq;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Lyrics;
using MediaBrowser.Controller.Resolvers;
@@ -23,7 +20,7 @@ public class TxtLyricProvider : ILyricProvider
public ResolverPriority Priority => ResolverPriority.Second;
///
- public IEnumerable SupportedMediaTypes { get; } = new[] { "lrc", "txt" };
+ public IReadOnlyCollection SupportedMediaTypes { get; } = new[] { "lrc", "txt" };
///
/// Opens lyric file for the requested item, and processes it for API return.
@@ -41,7 +38,7 @@ public class TxtLyricProvider : ILyricProvider
string[] lyricTextLines = System.IO.File.ReadAllLines(lyricFilePath);
- List lyricList = new List();
+ List lyricList = new List();
if (lyricTextLines.Length == 0)
{
@@ -50,7 +47,7 @@ public class TxtLyricProvider : ILyricProvider
foreach (string lyricTextLine in lyricTextLines)
{
- lyricList.Add(new Controller.Lyrics.Lyric(lyricTextLine));
+ lyricList.Add(new LyricLine(lyricTextLine));
}
return new LyricResponse { Lyrics = lyricList };
--
cgit v1.2.3
From 552b6aceae94bd8079a027407d15acf6d46f9b6e Mon Sep 17 00:00:00 2001
From: 1hitsong <3330318+1hitsong@users.noreply.github.com>
Date: Sun, 18 Sep 2022 16:17:26 -0400
Subject: Add default values to LyricResponse
---
MediaBrowser.Controller/Lyrics/LyricResponse.cs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
(limited to 'MediaBrowser.Controller')
diff --git a/MediaBrowser.Controller/Lyrics/LyricResponse.cs b/MediaBrowser.Controller/Lyrics/LyricResponse.cs
index b3c65ac8c0..ded3ca10e2 100644
--- a/MediaBrowser.Controller/Lyrics/LyricResponse.cs
+++ b/MediaBrowser.Controller/Lyrics/LyricResponse.cs
@@ -10,10 +10,10 @@ public class LyricResponse
///
/// Gets or sets Metadata.
///
- public LyricMetadata Metadata { get; set; }
+ public LyricMetadata Metadata { get; set; } = new LyricMetadata();
///
/// Gets or sets Lyrics.
///
- public IEnumerable Lyrics { get; set; }
+ public IReadOnlyCollection Lyrics { get; set; } = new List();
}
--
cgit v1.2.3
From 28d017865b7f51babc7c13dbfaf71a660d834d46 Mon Sep 17 00:00:00 2001
From: 1hitsong <3330318+1hitsong@users.noreply.github.com>
Date: Sun, 18 Sep 2022 21:17:53 -0400
Subject: Code Cleanup
---
MediaBrowser.Controller/Lyrics/LyricLine.cs | 2 +-
MediaBrowser.Controller/Lyrics/LyricResponse.cs | 4 +--
MediaBrowser.Providers/Lyric/LrcLyricProvider.cs | 39 ++++++------------------
MediaBrowser.Providers/Lyric/TxtLyricProvider.cs | 4 +--
4 files changed, 14 insertions(+), 35 deletions(-)
(limited to 'MediaBrowser.Controller')
diff --git a/MediaBrowser.Controller/Lyrics/LyricLine.cs b/MediaBrowser.Controller/Lyrics/LyricLine.cs
index 43997f6564..eb5ff9972e 100644
--- a/MediaBrowser.Controller/Lyrics/LyricLine.cs
+++ b/MediaBrowser.Controller/Lyrics/LyricLine.cs
@@ -8,8 +8,8 @@ public class LyricLine
///
/// Initializes a new instance of the class.
///
- /// The lyric start time in ticks.
/// The lyric text.
+ /// The lyric start time in ticks.
public LyricLine(string text, long? start = null)
{
Start = start;
diff --git a/MediaBrowser.Controller/Lyrics/LyricResponse.cs b/MediaBrowser.Controller/Lyrics/LyricResponse.cs
index ded3ca10e2..64c3b3c28b 100644
--- a/MediaBrowser.Controller/Lyrics/LyricResponse.cs
+++ b/MediaBrowser.Controller/Lyrics/LyricResponse.cs
@@ -10,10 +10,10 @@ public class LyricResponse
///
/// Gets or sets Metadata.
///
- public LyricMetadata Metadata { get; set; } = new LyricMetadata();
+ public LyricMetadata Metadata { get; set; } = new();
///
/// Gets or sets Lyrics.
///
- public IReadOnlyCollection Lyrics { get; set; } = new List();
+ public IReadOnlyList Lyrics { get; set; } = new List();
}
diff --git a/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs b/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs
index 50fa519b3e..9d622a1cdf 100644
--- a/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs
+++ b/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs
@@ -38,7 +38,7 @@ public class LrcLyricProvider : ILyricProvider
public ResolverPriority Priority => ResolverPriority.First;
///
- public IReadOnlyCollection SupportedMediaTypes { get; } = new[] { "lrc" };
+ public IReadOnlyCollection SupportedMediaTypes { get; } = new[] { "lrc", "elrc" };
///
/// Opens lyric file for the requested item, and processes it for API return.
@@ -54,8 +54,8 @@ public class LrcLyricProvider : ILyricProvider
return null;
}
- List lyricList = new List();
- List sortedLyricData = new List();
+ List lyricList = new();
+ List sortedLyricData = new();
IDictionary fileMetaData = new Dictionary(StringComparer.OrdinalIgnoreCase);
string lrcFileContent = System.IO.File.ReadAllText(lyricFilePath);
@@ -85,19 +85,11 @@ public class LrcLyricProvider : ILyricProvider
string[] metaDataField;
string metaDataFieldName;
string metaDataFieldValue;
+ string[] test;
- if (colonCount == 1)
- {
- metaDataField = metaDataRow.Split(':');
- metaDataFieldName = metaDataField[0][1..].Trim();
- metaDataFieldValue = metaDataField[1][..^1].Trim();
- }
- else
- {
- int colonIndex = metaDataRow.IndexOf(':', StringComparison.OrdinalIgnoreCase);
- metaDataFieldName = metaDataRow[..colonIndex][1..].Trim();
- metaDataFieldValue = metaDataRow[(colonIndex + 1)..][..^1].Trim();
- }
+ metaDataField = metaDataRow.Split(':', 2, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
+ metaDataFieldName = metaDataField[0][1..].Trim();
+ metaDataFieldValue = metaDataField[1][..^1].Trim();
fileMetaData.Add(metaDataFieldName, metaDataFieldValue);
}
@@ -142,7 +134,7 @@ public class LrcLyricProvider : ILyricProvider
/// A lyricMetadata object with mapped property data.
private LyricMetadata MapMetadataValues(IDictionary metaData)
{
- LyricMetadata lyricMetadata = new LyricMetadata();
+ LyricMetadata lyricMetadata = new();
if (metaData.TryGetValue("ar", out var artist) && !string.IsNullOrEmpty(artist))
{
@@ -166,20 +158,7 @@ public class LrcLyricProvider : ILyricProvider
if (metaData.TryGetValue("length", out var length) && !string.IsNullOrEmpty(length))
{
- // Ensure minutes include leading zero
- var lengthData = length.Split(':');
- if (lengthData[0].Length == 1)
- {
- length = "0" + length;
- }
-
- // If only Minutes and Seconds were provided, prepend zeros for hours
- if (lengthData.Length == 2)
- {
- length = "00:" + length;
- }
-
- if (DateTime.TryParseExact(length, "HH:mm:ss", null, DateTimeStyles.None, out var value))
+ if (DateTime.TryParseExact(length, new string[] { "HH:mm:ss", "H:mm:ss", "mm:ss", "m:ss" }, null, DateTimeStyles.None, out var value))
{
lyricMetadata.Length = value.TimeOfDay.Ticks;
}
diff --git a/MediaBrowser.Providers/Lyric/TxtLyricProvider.cs b/MediaBrowser.Providers/Lyric/TxtLyricProvider.cs
index cd0e1599e7..542df13873 100644
--- a/MediaBrowser.Providers/Lyric/TxtLyricProvider.cs
+++ b/MediaBrowser.Providers/Lyric/TxtLyricProvider.cs
@@ -20,7 +20,7 @@ public class TxtLyricProvider : ILyricProvider
public ResolverPriority Priority => ResolverPriority.Second;
///
- public IReadOnlyCollection SupportedMediaTypes { get; } = new[] { "lrc", "txt" };
+ public IReadOnlyCollection SupportedMediaTypes { get; } = new[] { "lrc", "elrc", "txt" };
///
/// Opens lyric file for the requested item, and processes it for API return.
@@ -38,7 +38,7 @@ public class TxtLyricProvider : ILyricProvider
string[] lyricTextLines = System.IO.File.ReadAllLines(lyricFilePath);
- List lyricList = new List();
+ List lyricList = new();
if (lyricTextLines.Length == 0)
{
--
cgit v1.2.3
From 5d2364f0646ba4f4b6866115ad82fd8fac0733de Mon Sep 17 00:00:00 2001
From: 1hitsong <3330318+1hitsong@users.noreply.github.com>
Date: Mon, 19 Sep 2022 16:59:16 -0400
Subject: Move AcceptedTimeFormats to class level variable
---
MediaBrowser.Controller/Lyrics/LyricResponse.cs | 3 ++-
MediaBrowser.Providers/Lyric/LrcLyricProvider.cs | 8 +++++---
2 files changed, 7 insertions(+), 4 deletions(-)
(limited to 'MediaBrowser.Controller')
diff --git a/MediaBrowser.Controller/Lyrics/LyricResponse.cs b/MediaBrowser.Controller/Lyrics/LyricResponse.cs
index 64c3b3c28b..56a5696450 100644
--- a/MediaBrowser.Controller/Lyrics/LyricResponse.cs
+++ b/MediaBrowser.Controller/Lyrics/LyricResponse.cs
@@ -1,3 +1,4 @@
+using System;
using System.Collections.Generic;
namespace MediaBrowser.Controller.Lyrics;
@@ -15,5 +16,5 @@ public class LyricResponse
///