mirror of https://github.com/jellyfin/jellyfin.git
Merge be4dfe79df
into 5612cb8178
This commit is contained in:
commit
2eb0be9585
|
@ -54,4 +54,9 @@ public class PluginConfiguration : BasePluginConfiguration
|
|||
/// Gets or sets a value indicating whether to replace the artist name.
|
||||
/// </summary>
|
||||
public bool ReplaceArtistName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether to retrieve missing track info.
|
||||
/// </summary>
|
||||
public bool GetMissingTrackInfo { get; set; }
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<!DOCTYPE html>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>MusicBrainz</title>
|
||||
|
@ -21,6 +21,10 @@
|
|||
<input is="emby-checkbox" type="checkbox" id="replaceArtistName" />
|
||||
<span>When an artist is found during a metadata search, replace the artist name with the value on the server.</span>
|
||||
</label>
|
||||
<label class="checkboxContainer">
|
||||
<input is="emby-checkbox" type="checkbox" id="getMissingTrackInfo" />
|
||||
<span>If track number or track length is missing, retrieve it from MusicBrainz.</span>
|
||||
</label>
|
||||
<br />
|
||||
<div>
|
||||
<button is="emby-button" type="submit" class="raised button-submit block"><span>Save</span></button>
|
||||
|
|
|
@ -4,6 +4,7 @@ using System.Linq;
|
|||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Jellyfin.Data.Enums;
|
||||
using Jellyfin.Extensions;
|
||||
using MediaBrowser.Controller.Entities.Audio;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
|
@ -65,6 +66,7 @@ public class MusicBrainzAlbumProvider : IRemoteMetadataProvider<MusicAlbum, Albu
|
|||
}
|
||||
|
||||
Query.DelayBetweenRequests = configuration.RateLimit;
|
||||
_musicBrainzQuery?.Dispose();
|
||||
_musicBrainzQuery = new Query();
|
||||
}
|
||||
|
||||
|
@ -274,6 +276,48 @@ public class MusicBrainzAlbumProvider : IRemoteMetadataProvider<MusicAlbum, Albu
|
|||
}
|
||||
}
|
||||
|
||||
if (Plugin.Instance != null && Plugin.Instance.Configuration.GetMissingTrackInfo)
|
||||
{
|
||||
var children = result.Item.Children.ToArray();
|
||||
if (children.Any(s => s is Audio && s.IndexNumber == null) && releaseId != null)
|
||||
{
|
||||
var rspobj = await _musicBrainzQuery.LookupReleaseAsync(Guid.Parse(releaseId), Include.Recordings, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
var tracks = new List<ITrack>();
|
||||
|
||||
if (rspobj.Media != null)
|
||||
{
|
||||
foreach (var t in rspobj.Media.Where(x => x.Tracks != null).SelectMany(x => x.Tracks!))
|
||||
{
|
||||
tracks.Add(t);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var c in children.Where(x =>
|
||||
x is Audio &&
|
||||
children.Any(p => Guid.Equals(p.Id, x.ParentId)) &&
|
||||
x.MediaType == MediaType.Audio &&
|
||||
((x.RunTimeTicks == null) || (x.IndexNumber == null))))
|
||||
{
|
||||
long? ticks = c.RunTimeTicks;
|
||||
int? index = c.IndexNumber;
|
||||
var trk = tracks.FirstOrDefault(t => string.Equals(t.Title, c.Name, StringComparison.OrdinalIgnoreCase));
|
||||
c.RunTimeTicks ??= trk?.Length?.Ticks ?? 0L;
|
||||
|
||||
c.IndexNumber ??= trk?.Position;
|
||||
|
||||
if ((ticks != c.RunTimeTicks) || (index != c.IndexNumber))
|
||||
{
|
||||
if (children.Where(p => Guid.Equals(p.Id, c.ParentId)).FirstOrDefault() is MusicAlbum parent)
|
||||
{
|
||||
parent.AddChild(c);
|
||||
result.Item.AddChild(parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue