mirror of https://github.com/jellyfin/jellyfin.git
Add ability to get track number and length from MusicBrainz for tracks where this is null
This commit is contained in:
parent
df8346cd63
commit
a75fc39ddd
|
@ -49,4 +49,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>
|
||||
|
@ -20,6 +20,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>
|
||||
|
|
|
@ -256,6 +256,65 @@ public class MusicBrainzAlbumProvider : IRemoteMetadataProvider<MusicAlbum, Albu
|
|||
}
|
||||
}
|
||||
|
||||
if (Plugin.Instance != null && Plugin.Instance.Configuration.GetMissingTrackInfo)
|
||||
{
|
||||
if (result.Item.Children.Any(s => s is Audio && s.IndexNumber == null))
|
||||
{
|
||||
var rspobj = _musicBrainzQuery.LookupRelease(Guid.Parse(releaseId ?? string.Empty), Include.Recordings);
|
||||
|
||||
IList<ITrack> tracks = new List<ITrack>();
|
||||
|
||||
if (rspobj.Media != null)
|
||||
{
|
||||
foreach (var t in rspobj.Media.SelectMany(m => m.Tracks))
|
||||
{
|
||||
if (t != null)
|
||||
{
|
||||
tracks.Add(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var c in result.Item.Children.Where(x =>
|
||||
x is Audio &&
|
||||
result.Item.Children.Any(p => Guid.Equals(p.Id, x.ParentId)) &&
|
||||
string.Equals(x.MediaType, MediaType.Audio, StringComparison.OrdinalIgnoreCase) &&
|
||||
x.RunTimeTicks == null))
|
||||
{
|
||||
var newlength = tracks.Where(t => string.Equals(t.Title, c.Name, StringComparison.OrdinalIgnoreCase)).FirstOrDefault()?.Length;
|
||||
if (newlength != null)
|
||||
{
|
||||
c.RunTimeTicks = newlength.HasValue ? newlength.Value.Ticks : 0;
|
||||
var parent = result.Item.Children.Where(p => Guid.Equals(p.Id, c.ParentId)).FirstOrDefault() as MusicAlbum;
|
||||
if (parent != null)
|
||||
{
|
||||
parent.AddChild(c);
|
||||
result.Item.AddChild(parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var c in result.Item.Children.Where(x =>
|
||||
x is Audio &&
|
||||
result.Item.Children.Any(p => Guid.Equals(p.Id, x.ParentId)) &&
|
||||
string.Equals(x.MediaType, MediaType.Audio, StringComparison.OrdinalIgnoreCase) &&
|
||||
x.IndexNumber == null))
|
||||
{
|
||||
var newindex = tracks.Where(t => string.Equals(t.Title, c.Name, StringComparison.OrdinalIgnoreCase)).FirstOrDefault()?.Position;
|
||||
if (newindex != null)
|
||||
{
|
||||
c.IndexNumber = newindex;
|
||||
var parent = result.Item.Children.Where(p => Guid.Equals(p.Id, c.ParentId)).FirstOrDefault() as MusicAlbum;
|
||||
if (parent != null)
|
||||
{
|
||||
parent.AddChild(c);
|
||||
result.Item.AddChild(parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue