Scott K 1 month ago committed by GitHub
commit 62de4abba4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -54,4 +54,9 @@ public class PluginConfiguration : BasePluginConfiguration
/// Gets or sets a value indicating whether to replace the artist name. /// Gets or sets a value indicating whether to replace the artist name.
/// </summary> /// </summary>
public bool ReplaceArtistName { get; set; } 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> <html>
<head> <head>
<title>MusicBrainz</title> <title>MusicBrainz</title>
@ -21,6 +21,10 @@
<input is="emby-checkbox" type="checkbox" id="replaceArtistName" /> <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> <span>When an artist is found during a metadata search, replace the artist name with the value on the server.</span>
</label> </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 /> <br />
<div> <div>
<button is="emby-button" type="submit" class="raised button-submit block"><span>Save</span></button> <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.Net.Http;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Jellyfin.Data.Enums;
using Jellyfin.Extensions; using Jellyfin.Extensions;
using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Providers; using MediaBrowser.Controller.Providers;
@ -65,6 +66,7 @@ public class MusicBrainzAlbumProvider : IRemoteMetadataProvider<MusicAlbum, Albu
} }
Query.DelayBetweenRequests = configuration.RateLimit; Query.DelayBetweenRequests = configuration.RateLimit;
_musicBrainzQuery?.Dispose();
_musicBrainzQuery = new Query(); _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; return result;
} }

Loading…
Cancel
Save