mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-04-20 00:55:13 +01:00
Merge branch 'jellyfin:master' into master
This commit is contained in:
220
MediaBrowser.Providers/Lyric/LrcLyricProvider.cs
Normal file
220
MediaBrowser.Providers/Lyric/LrcLyricProvider.cs
Normal file
@@ -0,0 +1,220 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using LrcParser.Model;
|
||||
using LrcParser.Parser;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Lyrics;
|
||||
using MediaBrowser.Controller.Resolvers;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace MediaBrowser.Providers.Lyric;
|
||||
|
||||
/// <summary>
|
||||
/// LRC Lyric Provider.
|
||||
/// </summary>
|
||||
public class LrcLyricProvider : ILyricProvider
|
||||
{
|
||||
private readonly ILogger<LrcLyricProvider> _logger;
|
||||
|
||||
private readonly LyricParser _lrcLyricParser;
|
||||
|
||||
private static readonly string[] _acceptedTimeFormats = { "HH:mm:ss", "H:mm:ss", "mm:ss", "m:ss" };
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LrcLyricProvider"/> class.
|
||||
/// </summary>
|
||||
/// <param name="logger">Instance of the <see cref="ILogger"/> interface.</param>
|
||||
public LrcLyricProvider(ILogger<LrcLyricProvider> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
_lrcLyricParser = new LrcParser.Parser.Lrc.LrcParser();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public string Name => "LrcLyricProvider";
|
||||
|
||||
/// <summary>
|
||||
/// Gets the priority.
|
||||
/// </summary>
|
||||
/// <value>The priority.</value>
|
||||
public ResolverPriority Priority => ResolverPriority.First;
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyCollection<string> SupportedMediaTypes { get; } = new[] { "lrc", "elrc" };
|
||||
|
||||
/// <summary>
|
||||
/// Opens lyric file for the requested item, and processes it for API return.
|
||||
/// </summary>
|
||||
/// <param name="item">The item to to process.</param>
|
||||
/// <returns>If provider can determine lyrics, returns a <see cref="LyricResponse"/> with or without metadata; otherwise, null.</returns>
|
||||
public async Task<LyricResponse?> GetLyrics(BaseItem item)
|
||||
{
|
||||
string? lyricFilePath = this.GetLyricFilePath(item.Path);
|
||||
|
||||
if (string.IsNullOrEmpty(lyricFilePath))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var fileMetaData = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||
string lrcFileContent = await File.ReadAllTextAsync(lyricFilePath).ConfigureAwait(false);
|
||||
|
||||
Song lyricData;
|
||||
|
||||
try
|
||||
{
|
||||
lyricData = _lrcLyricParser.Decode(lrcFileContent);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error parsing lyric file {LyricFilePath} from {Provider}", lyricFilePath, Name);
|
||||
return null;
|
||||
}
|
||||
|
||||
List<LrcParser.Model.Lyric> 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)
|
||||
{
|
||||
var index = metaDataRow.IndexOf(':', StringComparison.OrdinalIgnoreCase);
|
||||
if (index == -1)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Remove square bracket before field name, and after field value
|
||||
// Example 1: [au: 1hitsong]
|
||||
// Example 2: [ar: Calabrese]
|
||||
var metaDataFieldName = GetMetadataFieldName(metaDataRow, index);
|
||||
var metaDataFieldValue = GetMetadataValue(metaDataRow, index);
|
||||
|
||||
if (string.IsNullOrEmpty(metaDataFieldName) || string.IsNullOrEmpty(metaDataFieldValue))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
fileMetaData[metaDataFieldName] = metaDataFieldValue;
|
||||
}
|
||||
|
||||
if (sortedLyricData.Count == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
List<LyricLine> lyricList = new();
|
||||
|
||||
for (int i = 0; i < sortedLyricData.Count; i++)
|
||||
{
|
||||
var timeData = sortedLyricData[i].TimeTags.First().Value;
|
||||
if (timeData is null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
long ticks = TimeSpan.FromMilliseconds(timeData.Value).Ticks;
|
||||
lyricList.Add(new LyricLine(sortedLyricData[i].Text, ticks));
|
||||
}
|
||||
|
||||
if (fileMetaData.Count != 0)
|
||||
{
|
||||
// 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
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts metadata from an LRC file to LyricMetadata properties.
|
||||
/// </summary>
|
||||
/// <param name="metaData">The metadata from the LRC file.</param>
|
||||
/// <returns>A lyricMetadata object with mapped property data.</returns>
|
||||
private static LyricMetadata MapMetadataValues(IDictionary<string, string> metaData)
|
||||
{
|
||||
LyricMetadata lyricMetadata = new();
|
||||
|
||||
if (metaData.TryGetValue("ar", out var artist) && !string.IsNullOrEmpty(artist))
|
||||
{
|
||||
lyricMetadata.Artist = artist;
|
||||
}
|
||||
|
||||
if (metaData.TryGetValue("al", out var album) && !string.IsNullOrEmpty(album))
|
||||
{
|
||||
lyricMetadata.Album = album;
|
||||
}
|
||||
|
||||
if (metaData.TryGetValue("ti", out var title) && !string.IsNullOrEmpty(title))
|
||||
{
|
||||
lyricMetadata.Title = title;
|
||||
}
|
||||
|
||||
if (metaData.TryGetValue("au", out var author) && !string.IsNullOrEmpty(author))
|
||||
{
|
||||
lyricMetadata.Author = author;
|
||||
}
|
||||
|
||||
if (metaData.TryGetValue("length", out var length) && !string.IsNullOrEmpty(length))
|
||||
{
|
||||
if (DateTime.TryParseExact(length, _acceptedTimeFormats, null, DateTimeStyles.None, out var value))
|
||||
{
|
||||
lyricMetadata.Length = value.TimeOfDay.Ticks;
|
||||
}
|
||||
}
|
||||
|
||||
if (metaData.TryGetValue("by", out var by) && !string.IsNullOrEmpty(by))
|
||||
{
|
||||
lyricMetadata.By = by;
|
||||
}
|
||||
|
||||
if (metaData.TryGetValue("offset", out var offset) && !string.IsNullOrEmpty(offset))
|
||||
{
|
||||
if (int.TryParse(offset, out var value))
|
||||
{
|
||||
lyricMetadata.Offset = TimeSpan.FromMilliseconds(value).Ticks;
|
||||
}
|
||||
}
|
||||
|
||||
if (metaData.TryGetValue("re", out var creator) && !string.IsNullOrEmpty(creator))
|
||||
{
|
||||
lyricMetadata.Creator = creator;
|
||||
}
|
||||
|
||||
if (metaData.TryGetValue("ve", out var version) && !string.IsNullOrEmpty(version))
|
||||
{
|
||||
lyricMetadata.Version = version;
|
||||
}
|
||||
|
||||
return lyricMetadata;
|
||||
}
|
||||
|
||||
private static string GetMetadataFieldName(string metaDataRow, int index)
|
||||
{
|
||||
var metadataFieldName = metaDataRow.AsSpan(1, index - 1).Trim();
|
||||
return metadataFieldName.IsEmpty ? string.Empty : metadataFieldName.ToString();
|
||||
}
|
||||
|
||||
private static string GetMetadataValue(string metaDataRow, int index)
|
||||
{
|
||||
var metadataValue = metaDataRow.AsSpan(index + 1, metaDataRow.Length - index - 2).Trim();
|
||||
return metadataValue.IsEmpty ? string.Empty : metadataValue.ToString();
|
||||
}
|
||||
}
|
||||
58
MediaBrowser.Providers/Lyric/LyricManager.cs
Normal file
58
MediaBrowser.Providers/Lyric/LyricManager.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Lyrics;
|
||||
|
||||
namespace MediaBrowser.Providers.Lyric;
|
||||
|
||||
/// <summary>
|
||||
/// Lyric Manager.
|
||||
/// </summary>
|
||||
public class LyricManager : ILyricManager
|
||||
{
|
||||
private readonly ILyricProvider[] _lyricProviders;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LyricManager"/> class.
|
||||
/// </summary>
|
||||
/// <param name="lyricProviders">All found lyricProviders.</param>
|
||||
public LyricManager(IEnumerable<ILyricProvider> lyricProviders)
|
||||
{
|
||||
_lyricProviders = lyricProviders.OrderBy(i => i.Priority).ToArray();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<LyricResponse?> GetLyrics(BaseItem item)
|
||||
{
|
||||
foreach (ILyricProvider provider in _lyricProviders)
|
||||
{
|
||||
var results = await provider.GetLyrics(item).ConfigureAwait(false);
|
||||
if (results is not null)
|
||||
{
|
||||
return results;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool HasLyricFile(BaseItem item)
|
||||
{
|
||||
foreach (ILyricProvider provider in _lyricProviders)
|
||||
{
|
||||
if (item is null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (provider.GetLyricFilePath(item.Path) is not null)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
61
MediaBrowser.Providers/Lyric/TxtLyricProvider.cs
Normal file
61
MediaBrowser.Providers/Lyric/TxtLyricProvider.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
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.Resolvers;
|
||||
|
||||
namespace MediaBrowser.Providers.Lyric;
|
||||
|
||||
/// <summary>
|
||||
/// TXT Lyric Provider.
|
||||
/// </summary>
|
||||
public class TxtLyricProvider : ILyricProvider
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public string Name => "TxtLyricProvider";
|
||||
|
||||
/// <summary>
|
||||
/// Gets the priority.
|
||||
/// </summary>
|
||||
/// <value>The priority.</value>
|
||||
public ResolverPriority Priority => ResolverPriority.Second;
|
||||
|
||||
/// <inheritdoc />
|
||||
public IReadOnlyCollection<string> SupportedMediaTypes { get; } = new[] { "lrc", "elrc", "txt" };
|
||||
|
||||
/// <summary>
|
||||
/// Opens lyric file for the requested item, and processes it for API return.
|
||||
/// </summary>
|
||||
/// <param name="item">The item to to process.</param>
|
||||
/// <returns>If provider can determine lyrics, returns a <see cref="LyricResponse"/>; otherwise, null.</returns>
|
||||
public async Task<LyricResponse?> GetLyrics(BaseItem item)
|
||||
{
|
||||
string? lyricFilePath = this.GetLyricFilePath(item.Path);
|
||||
|
||||
if (string.IsNullOrEmpty(lyricFilePath))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
string[] lyricTextLines = await File.ReadAllLinesAsync(lyricFilePath).ConfigureAwait(false);
|
||||
|
||||
if (lyricTextLines.Length == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
LyricLine[] lyricList = new LyricLine[lyricTextLines.Length];
|
||||
|
||||
for (int lyricLineIndex = 0; lyricLineIndex < lyricTextLines.Length; lyricLineIndex++)
|
||||
{
|
||||
lyricList[lyricLineIndex] = new LyricLine(lyricTextLines[lyricLineIndex]);
|
||||
}
|
||||
|
||||
return new LyricResponse
|
||||
{
|
||||
Lyrics = lyricList
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -16,12 +16,15 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="LrcParser" Version="2022.529.1" />
|
||||
<PackageReference Include="MetaBrainz.MusicBrainz" Version="5.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="6.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||
<PackageReference Include="OptimizedPriorityQueue" Version="5.1.0" />
|
||||
<PackageReference Include="PlaylistsNET" Version="1.2.1" />
|
||||
<PackageReference Include="TagLibSharp" Version="2.3.0" />
|
||||
<PackageReference Include="TMDbLib" Version="1.9.2" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
215
MediaBrowser.Providers/MediaInfo/AudioFileProber.cs
Normal file
215
MediaBrowser.Providers/MediaInfo/AudioFileProber.cs
Normal file
@@ -0,0 +1,215 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Entities.Audio;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.MediaEncoding;
|
||||
using MediaBrowser.Controller.Persistence;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Dlna;
|
||||
using MediaBrowser.Model.Dto;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.MediaInfo;
|
||||
using TagLib;
|
||||
|
||||
namespace MediaBrowser.Providers.MediaInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// Probes audio files for metadata.
|
||||
/// </summary>
|
||||
public class AudioFileProber
|
||||
{
|
||||
private readonly IMediaEncoder _mediaEncoder;
|
||||
private readonly IItemRepository _itemRepo;
|
||||
private readonly ILibraryManager _libraryManager;
|
||||
private readonly IMediaSourceManager _mediaSourceManager;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AudioFileProber"/> class.
|
||||
/// </summary>
|
||||
/// <param name="mediaSourceManager">Instance of the <see cref="IMediaSourceManager"/> interface.</param>
|
||||
/// <param name="mediaEncoder">Instance of the <see cref="IMediaEncoder"/> interface.</param>
|
||||
/// <param name="itemRepo">Instance of the <see cref="IItemRepository"/> interface.</param>
|
||||
/// <param name="libraryManager">Instance of the <see cref="ILibraryManager"/> interface.</param>
|
||||
public AudioFileProber(
|
||||
IMediaSourceManager mediaSourceManager,
|
||||
IMediaEncoder mediaEncoder,
|
||||
IItemRepository itemRepo,
|
||||
ILibraryManager libraryManager)
|
||||
{
|
||||
_mediaEncoder = mediaEncoder;
|
||||
_itemRepo = itemRepo;
|
||||
_libraryManager = libraryManager;
|
||||
_mediaSourceManager = mediaSourceManager;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Probes the specified item for metadata.
|
||||
/// </summary>
|
||||
/// <param name="item">The item to probe.</param>
|
||||
/// <param name="options">The <see cref="MetadataRefreshOptions"/>.</param>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param>
|
||||
/// <typeparam name="T">The type of item to resolve.</typeparam>
|
||||
/// <returns>A <see cref="Task"/> probing the item for metadata.</returns>
|
||||
public async Task<ItemUpdateType> Probe<T>(
|
||||
T item,
|
||||
MetadataRefreshOptions options,
|
||||
CancellationToken cancellationToken)
|
||||
where T : Audio
|
||||
{
|
||||
var path = item.Path;
|
||||
var protocol = item.PathProtocol ?? MediaProtocol.File;
|
||||
|
||||
if (!item.IsShortcut || options.EnableRemoteContentProbe)
|
||||
{
|
||||
if (item.IsShortcut)
|
||||
{
|
||||
path = item.ShortcutPath;
|
||||
protocol = _mediaSourceManager.GetPathProtocol(path);
|
||||
}
|
||||
|
||||
var result = await _mediaEncoder.GetMediaInfo(
|
||||
new MediaInfoRequest
|
||||
{
|
||||
MediaType = DlnaProfileType.Audio,
|
||||
MediaSource = new MediaSourceInfo
|
||||
{
|
||||
Path = path,
|
||||
Protocol = protocol
|
||||
}
|
||||
},
|
||||
cancellationToken).ConfigureAwait(false);
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
Fetch(item, result, cancellationToken);
|
||||
}
|
||||
|
||||
return ItemUpdateType.MetadataImport;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fetches the specified audio.
|
||||
/// </summary>
|
||||
/// <param name="audio">The <see cref="Audio"/>.</param>
|
||||
/// <param name="mediaInfo">The <see cref="Model.MediaInfo.MediaInfo"/>.</param>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param>
|
||||
protected void Fetch(Audio audio, Model.MediaInfo.MediaInfo mediaInfo, CancellationToken cancellationToken)
|
||||
{
|
||||
audio.Container = mediaInfo.Container;
|
||||
audio.TotalBitrate = mediaInfo.Bitrate;
|
||||
|
||||
audio.RunTimeTicks = mediaInfo.RunTimeTicks;
|
||||
audio.Size = mediaInfo.Size;
|
||||
|
||||
FetchDataFromTags(audio);
|
||||
|
||||
_itemRepo.SaveMediaStreams(audio.Id, mediaInfo.MediaStreams, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fetches data from the tags.
|
||||
/// </summary>
|
||||
/// <param name="audio">The <see cref="Audio"/>.</param>
|
||||
private void FetchDataFromTags(Audio audio)
|
||||
{
|
||||
var file = TagLib.File.Create(audio.Path);
|
||||
var tagTypes = file.TagTypesOnDisk;
|
||||
Tag? tags = null;
|
||||
|
||||
if (tagTypes.HasFlag(TagTypes.Id3v2))
|
||||
{
|
||||
tags = file.GetTag(TagTypes.Id3v2);
|
||||
}
|
||||
else if (tagTypes.HasFlag(TagTypes.Ape))
|
||||
{
|
||||
tags = file.GetTag(TagTypes.Ape);
|
||||
}
|
||||
else if (tagTypes.HasFlag(TagTypes.FlacMetadata))
|
||||
{
|
||||
tags = file.GetTag(TagTypes.FlacMetadata);
|
||||
}
|
||||
else if (tagTypes.HasFlag(TagTypes.Apple))
|
||||
{
|
||||
tags = file.GetTag(TagTypes.Apple);
|
||||
}
|
||||
else if (tagTypes.HasFlag(TagTypes.Xiph))
|
||||
{
|
||||
tags = file.GetTag(TagTypes.Xiph);
|
||||
}
|
||||
else if (tagTypes.HasFlag(TagTypes.AudibleMetadata))
|
||||
{
|
||||
tags = file.GetTag(TagTypes.AudibleMetadata);
|
||||
}
|
||||
else if (tagTypes.HasFlag(TagTypes.Id3v1))
|
||||
{
|
||||
tags = file.GetTag(TagTypes.Id3v1);
|
||||
}
|
||||
|
||||
if (tags != null)
|
||||
{
|
||||
if (audio.SupportsPeople && !audio.LockedFields.Contains(MetadataField.Cast))
|
||||
{
|
||||
var people = new List<PersonInfo>();
|
||||
var albumArtists = tags.AlbumArtists;
|
||||
foreach (var albumArtist in albumArtists)
|
||||
{
|
||||
PeopleHelper.AddPerson(people, new PersonInfo
|
||||
{
|
||||
Name = albumArtist,
|
||||
Type = "AlbumArtist"
|
||||
});
|
||||
}
|
||||
|
||||
var performers = tags.Performers;
|
||||
foreach (var performer in performers)
|
||||
{
|
||||
PeopleHelper.AddPerson(people, new PersonInfo
|
||||
{
|
||||
Name = performer,
|
||||
Type = "Artist"
|
||||
});
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
if (!audio.LockedFields.Contains(MetadataField.Genres))
|
||||
{
|
||||
audio.Genres = tags.Genres.Distinct(StringComparer.OrdinalIgnoreCase).ToArray();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,13 +31,14 @@ namespace MediaBrowser.Providers.MediaInfo
|
||||
"poster",
|
||||
"folder",
|
||||
"cover",
|
||||
"default"
|
||||
"default",
|
||||
"movie",
|
||||
"show"
|
||||
};
|
||||
|
||||
private static readonly string[] _backdropImageFileNames =
|
||||
{
|
||||
"backdrop",
|
||||
"fanart",
|
||||
"background",
|
||||
"art"
|
||||
};
|
||||
|
||||
@@ -1,172 +0,0 @@
|
||||
#nullable disable
|
||||
|
||||
#pragma warning disable CS1591
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Entities.Audio;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.MediaEncoding;
|
||||
using MediaBrowser.Controller.Persistence;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Dlna;
|
||||
using MediaBrowser.Model.Dto;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.MediaInfo;
|
||||
|
||||
namespace MediaBrowser.Providers.MediaInfo
|
||||
{
|
||||
public class FFProbeAudioInfo
|
||||
{
|
||||
private readonly IMediaEncoder _mediaEncoder;
|
||||
private readonly IItemRepository _itemRepo;
|
||||
private readonly ILibraryManager _libraryManager;
|
||||
private readonly IMediaSourceManager _mediaSourceManager;
|
||||
|
||||
public FFProbeAudioInfo(
|
||||
IMediaSourceManager mediaSourceManager,
|
||||
IMediaEncoder mediaEncoder,
|
||||
IItemRepository itemRepo,
|
||||
ILibraryManager libraryManager)
|
||||
{
|
||||
_mediaEncoder = mediaEncoder;
|
||||
_itemRepo = itemRepo;
|
||||
_libraryManager = libraryManager;
|
||||
_mediaSourceManager = mediaSourceManager;
|
||||
}
|
||||
|
||||
public async Task<ItemUpdateType> Probe<T>(
|
||||
T item,
|
||||
MetadataRefreshOptions options,
|
||||
CancellationToken cancellationToken)
|
||||
where T : Audio
|
||||
{
|
||||
var path = item.Path;
|
||||
var protocol = item.PathProtocol ?? MediaProtocol.File;
|
||||
|
||||
if (!item.IsShortcut || options.EnableRemoteContentProbe)
|
||||
{
|
||||
if (item.IsShortcut)
|
||||
{
|
||||
path = item.ShortcutPath;
|
||||
protocol = _mediaSourceManager.GetPathProtocol(path);
|
||||
}
|
||||
|
||||
var result = await _mediaEncoder.GetMediaInfo(
|
||||
new MediaInfoRequest
|
||||
{
|
||||
MediaType = DlnaProfileType.Audio,
|
||||
MediaSource = new MediaSourceInfo
|
||||
{
|
||||
Path = path,
|
||||
Protocol = protocol
|
||||
}
|
||||
},
|
||||
cancellationToken).ConfigureAwait(false);
|
||||
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
Fetch(item, result, cancellationToken);
|
||||
}
|
||||
|
||||
return ItemUpdateType.MetadataImport;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fetches the specified audio.
|
||||
/// </summary>
|
||||
/// <param name="audio">The audio.</param>
|
||||
/// <param name="mediaInfo">The media information.</param>
|
||||
/// <param name="cancellationToken">The cancellation token.</param>
|
||||
protected void Fetch(Audio audio, Model.MediaInfo.MediaInfo mediaInfo, CancellationToken cancellationToken)
|
||||
{
|
||||
audio.Container = mediaInfo.Container;
|
||||
audio.TotalBitrate = mediaInfo.Bitrate;
|
||||
|
||||
audio.RunTimeTicks = mediaInfo.RunTimeTicks;
|
||||
audio.Size = mediaInfo.Size;
|
||||
|
||||
// var extension = (Path.GetExtension(audio.Path) ?? string.Empty).TrimStart('.');
|
||||
// audio.Container = extension;
|
||||
|
||||
FetchDataFromTags(audio, mediaInfo);
|
||||
|
||||
_itemRepo.SaveMediaStreams(audio.Id, mediaInfo.MediaStreams, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fetches data from the tags dictionary.
|
||||
/// </summary>
|
||||
/// <param name="audio">The audio.</param>
|
||||
/// <param name="data">The data.</param>
|
||||
private void FetchDataFromTags(Audio audio, Model.MediaInfo.MediaInfo data)
|
||||
{
|
||||
// Only set Name if title was found in the dictionary
|
||||
if (!string.IsNullOrEmpty(data.Name))
|
||||
{
|
||||
audio.Name = data.Name;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(data.ForcedSortName))
|
||||
{
|
||||
audio.ForcedSortName = data.ForcedSortName;
|
||||
}
|
||||
|
||||
if (audio.SupportsPeople && !audio.LockedFields.Contains(MetadataField.Cast))
|
||||
{
|
||||
var people = new List<PersonInfo>();
|
||||
|
||||
foreach (var person in data.People)
|
||||
{
|
||||
PeopleHelper.AddPerson(people, new PersonInfo
|
||||
{
|
||||
Name = person.Name,
|
||||
Type = person.Type,
|
||||
Role = person.Role
|
||||
});
|
||||
}
|
||||
|
||||
_libraryManager.UpdatePeople(audio, people);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
if (!audio.LockedFields.Contains(MetadataField.Genres))
|
||||
{
|
||||
audio.Genres = Array.Empty<string>();
|
||||
|
||||
foreach (var genre in data.Genres)
|
||||
{
|
||||
audio.AddGenre(genre);
|
||||
}
|
||||
}
|
||||
|
||||
if (!audio.LockedFields.Contains(MetadataField.Studios))
|
||||
{
|
||||
audio.SetStudios(data.Studios);
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -120,6 +120,7 @@ namespace MediaBrowser.Providers.MediaInfo
|
||||
mediaStream.Index = startIndex++;
|
||||
mediaStream.IsDefault = pathInfo.IsDefault || mediaStream.IsDefault;
|
||||
mediaStream.IsForced = pathInfo.IsForced || mediaStream.IsForced;
|
||||
mediaStream.IsHearingImpaired = pathInfo.IsHearingImpaired || mediaStream.IsHearingImpaired;
|
||||
|
||||
mediaStreams.Add(MergeMetadata(mediaStream, pathInfo));
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
#nullable disable
|
||||
|
||||
#pragma warning disable CS1591
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@@ -27,7 +25,10 @@ using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace MediaBrowser.Providers.MediaInfo
|
||||
{
|
||||
public class FFProbeProvider : ICustomMetadataProvider<Episode>,
|
||||
/// <summary>
|
||||
/// The probe provider.
|
||||
/// </summary>
|
||||
public class ProbeProvider : ICustomMetadataProvider<Episode>,
|
||||
ICustomMetadataProvider<MusicVideo>,
|
||||
ICustomMetadataProvider<Movie>,
|
||||
ICustomMetadataProvider<Trailer>,
|
||||
@@ -39,14 +40,30 @@ namespace MediaBrowser.Providers.MediaInfo
|
||||
IPreRefreshProvider,
|
||||
IHasItemChangeMonitor
|
||||
{
|
||||
private readonly ILogger<FFProbeProvider> _logger;
|
||||
private readonly ILogger<ProbeProvider> _logger;
|
||||
private readonly AudioResolver _audioResolver;
|
||||
private readonly SubtitleResolver _subtitleResolver;
|
||||
private readonly FFProbeVideoInfo _videoProber;
|
||||
private readonly FFProbeAudioInfo _audioProber;
|
||||
private readonly AudioFileProber _audioProber;
|
||||
private readonly Task<ItemUpdateType> _cachedTask = Task.FromResult(ItemUpdateType.None);
|
||||
|
||||
public FFProbeProvider(
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="ProbeProvider"/> class.
|
||||
/// </summary>
|
||||
/// <param name="mediaSourceManager">Instance of the <see cref="IMediaSourceManager"/> interface.</param>
|
||||
/// <param name="mediaEncoder">Instance of the <see cref="IMediaEncoder"/> interface.</param>
|
||||
/// <param name="itemRepo">Instance of the <see cref="IItemRepository"/> interface.</param>
|
||||
/// <param name="blurayExaminer">Instance of the <see cref="IBlurayExaminer"/> interface.</param>
|
||||
/// <param name="localization">Instance of the <see cref="ILocalizationManager"/> interface.</param>
|
||||
/// <param name="encodingManager">Instance of the <see cref="IEncodingManager"/> interface.</param>
|
||||
/// <param name="config">Instance of the <see cref="IServerConfigurationManager"/> interface.</param>
|
||||
/// <param name="subtitleManager">Instance of the <see cref="ISubtitleManager"/> interface.</param>
|
||||
/// <param name="chapterManager">Instance of the <see cref="IChapterManager"/> interface.</param>
|
||||
/// <param name="libraryManager">Instance of the <see cref="ILibraryManager"/> interface.</param>
|
||||
/// <param name="loggerFactory">Instance of the <see cref="ILoggerFactory"/>.</param>
|
||||
/// <param name="fileSystem">Instance of the <see cref="IFileSystem"/> interface.</param>
|
||||
/// <param name="namingOptions">The <see cref="NamingOptions"/>.</param>
|
||||
public ProbeProvider(
|
||||
IMediaSourceManager mediaSourceManager,
|
||||
IMediaEncoder mediaEncoder,
|
||||
IItemRepository itemRepo,
|
||||
@@ -61,7 +78,8 @@ namespace MediaBrowser.Providers.MediaInfo
|
||||
ILoggerFactory loggerFactory,
|
||||
NamingOptions namingOptions)
|
||||
{
|
||||
_logger = loggerFactory.CreateLogger<FFProbeProvider>();
|
||||
_logger = loggerFactory.CreateLogger<ProbeProvider>();
|
||||
_audioProber = new AudioFileProber(mediaSourceManager, mediaEncoder, itemRepo, libraryManager);
|
||||
_audioResolver = new AudioResolver(loggerFactory.CreateLogger<AudioResolver>(), localization, mediaEncoder, fileSystem, namingOptions);
|
||||
_subtitleResolver = new SubtitleResolver(loggerFactory.CreateLogger<SubtitleResolver>(), localization, mediaEncoder, fileSystem, namingOptions);
|
||||
_videoProber = new FFProbeVideoInfo(
|
||||
@@ -78,14 +96,15 @@ namespace MediaBrowser.Providers.MediaInfo
|
||||
libraryManager,
|
||||
_audioResolver,
|
||||
_subtitleResolver);
|
||||
_audioProber = new FFProbeAudioInfo(mediaSourceManager, mediaEncoder, itemRepo, libraryManager);
|
||||
}
|
||||
|
||||
public string Name => "ffprobe";
|
||||
/// <inheritdoc />
|
||||
public string Name => "Probe Provider";
|
||||
|
||||
// Run last
|
||||
/// <inheritdoc />
|
||||
public int Order => 100;
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool HasChanged(BaseItem item, IDirectoryService directoryService)
|
||||
{
|
||||
var video = item as Video;
|
||||
@@ -127,41 +146,56 @@ namespace MediaBrowser.Providers.MediaInfo
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<ItemUpdateType> FetchAsync(Episode item, MetadataRefreshOptions options, CancellationToken cancellationToken)
|
||||
{
|
||||
return FetchVideoInfo(item, options, cancellationToken);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<ItemUpdateType> FetchAsync(MusicVideo item, MetadataRefreshOptions options, CancellationToken cancellationToken)
|
||||
{
|
||||
return FetchVideoInfo(item, options, cancellationToken);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<ItemUpdateType> FetchAsync(Movie item, MetadataRefreshOptions options, CancellationToken cancellationToken)
|
||||
{
|
||||
return FetchVideoInfo(item, options, cancellationToken);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<ItemUpdateType> FetchAsync(Trailer item, MetadataRefreshOptions options, CancellationToken cancellationToken)
|
||||
{
|
||||
return FetchVideoInfo(item, options, cancellationToken);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<ItemUpdateType> FetchAsync(Video item, MetadataRefreshOptions options, CancellationToken cancellationToken)
|
||||
{
|
||||
return FetchVideoInfo(item, options, cancellationToken);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<ItemUpdateType> FetchAsync(Audio item, MetadataRefreshOptions options, CancellationToken cancellationToken)
|
||||
{
|
||||
return FetchAudioInfo(item, options, cancellationToken);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<ItemUpdateType> FetchAsync(AudioBook item, MetadataRefreshOptions options, CancellationToken cancellationToken)
|
||||
{
|
||||
return FetchAudioInfo(item, options, cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fetches video information for an item.
|
||||
/// </summary>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <param name="options">The <see cref="MetadataRefreshOptions"/>.</param>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param>
|
||||
/// <typeparam name="T">The type of item to resolve.</typeparam>
|
||||
/// <returns>A <see cref="Task"/> fetching the <see cref="ItemUpdateType"/> for an item.</returns>
|
||||
public Task<ItemUpdateType> FetchVideoInfo<T>(T item, MetadataRefreshOptions options, CancellationToken cancellationToken)
|
||||
where T : Video
|
||||
{
|
||||
@@ -208,6 +242,14 @@ namespace MediaBrowser.Providers.MediaInfo
|
||||
.FirstOrDefault(i => !string.IsNullOrWhiteSpace(i) && !i.StartsWith('#'));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fetches audio information for an item.
|
||||
/// </summary>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <param name="options">The <see cref="MetadataRefreshOptions"/>.</param>
|
||||
/// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param>
|
||||
/// <typeparam name="T">The type of item to resolve.</typeparam>
|
||||
/// <returns>A <see cref="Task"/> fetching the <see cref="ItemUpdateType"/> for an item.</returns>
|
||||
public Task<ItemUpdateType> FetchAudioInfo<T>(T item, MetadataRefreshOptions options, CancellationToken cancellationToken)
|
||||
where T : Audio
|
||||
{
|
||||
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// The album metadata service.
|
||||
/// </summary>
|
||||
public class AlbumMetadataService : MetadataService<MusicAlbum, AlbumInfo>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AlbumMetadataService"/> class.
|
||||
/// </summary>
|
||||
/// <param name="serverConfigurationManager">Instance of the <see cref="IServerConfigurationManager"/>.</param>
|
||||
/// <param name="logger">Instance of the <see cref="ILogger"/> interface.</param>
|
||||
/// <param name="providerManager">Instance of the <see cref="IProviderManager"/> interface.</param>
|
||||
/// <param name="fileSystem">Instance of the <see cref="IFileSystem"/> interface.</param>
|
||||
/// <param name="libraryManager">Instance of the <see cref="ILibraryManager"/> interface.</param>
|
||||
public AlbumMetadataService(
|
||||
IServerConfigurationManager serverConfigurationManager,
|
||||
ILogger<AlbumMetadataService> logger,
|
||||
@@ -61,40 +70,46 @@ namespace MediaBrowser.Providers.Music
|
||||
|
||||
var songs = children.Cast<Audio>().ToArray();
|
||||
|
||||
updateType |= SetAlbumArtistFromSongs(item, songs);
|
||||
updateType |= SetArtistsFromSongs(item, songs);
|
||||
updateType |= SetAlbumArtistFromSongs(item, songs);
|
||||
updateType |= SetAlbumFromSongs(item, songs);
|
||||
updateType |= SetPeople(item);
|
||||
}
|
||||
|
||||
return updateType;
|
||||
}
|
||||
|
||||
private ItemUpdateType SetAlbumArtistFromSongs(MusicAlbum item, IEnumerable<Audio> songs)
|
||||
private ItemUpdateType SetAlbumArtistFromSongs(MusicAlbum item, IReadOnlyList<Audio> songs)
|
||||
{
|
||||
var updateType = ItemUpdateType.None;
|
||||
|
||||
var artists = songs
|
||||
var albumArtists = songs
|
||||
.SelectMany(i => i.AlbumArtists)
|
||||
.Distinct(StringComparer.OrdinalIgnoreCase)
|
||||
.OrderBy(i => i)
|
||||
.GroupBy(i => i)
|
||||
.OrderByDescending(g => g.Count())
|
||||
.Select(g => g.Key)
|
||||
.ToArray();
|
||||
|
||||
if (!item.AlbumArtists.SequenceEqual(artists, StringComparer.OrdinalIgnoreCase))
|
||||
updateType |= SetProviderIdFromSongs(item, songs, MetadataProvider.MusicBrainzAlbumArtist);
|
||||
|
||||
if (!item.AlbumArtists.SequenceEqual(albumArtists, StringComparer.OrdinalIgnoreCase))
|
||||
{
|
||||
item.AlbumArtists = artists;
|
||||
item.AlbumArtists = albumArtists;
|
||||
updateType |= ItemUpdateType.MetadataEdit;
|
||||
}
|
||||
|
||||
return updateType;
|
||||
}
|
||||
|
||||
private ItemUpdateType SetArtistsFromSongs(MusicAlbum item, IEnumerable<Audio> songs)
|
||||
private ItemUpdateType SetArtistsFromSongs(MusicAlbum item, IReadOnlyList<Audio> songs)
|
||||
{
|
||||
var updateType = ItemUpdateType.None;
|
||||
|
||||
var artists = songs
|
||||
.SelectMany(i => i.Artists)
|
||||
.Distinct(StringComparer.OrdinalIgnoreCase)
|
||||
.OrderBy(i => i)
|
||||
.GroupBy(i => i)
|
||||
.OrderByDescending(g => g.Count())
|
||||
.Select(g => g.Key)
|
||||
.ToArray();
|
||||
|
||||
if (!item.Artists.SequenceEqual(artists, StringComparer.OrdinalIgnoreCase))
|
||||
@@ -106,6 +121,85 @@ namespace MediaBrowser.Providers.Music
|
||||
return updateType;
|
||||
}
|
||||
|
||||
private ItemUpdateType SetAlbumFromSongs(MusicAlbum item, IReadOnlyList<Audio> songs)
|
||||
{
|
||||
var updateType = ItemUpdateType.None;
|
||||
|
||||
updateType |= SetProviderIdFromSongs(item, songs, MetadataProvider.MusicBrainzAlbum);
|
||||
updateType |= SetProviderIdFromSongs(item, songs, MetadataProvider.MusicBrainzReleaseGroup);
|
||||
|
||||
return updateType;
|
||||
}
|
||||
|
||||
private ItemUpdateType SetProviderIdFromSongs(BaseItem item, IReadOnlyList<Audio> songs, MetadataProvider provider)
|
||||
{
|
||||
var ids = songs
|
||||
.Select(i => i.GetProviderId(provider))
|
||||
.GroupBy(i => i)
|
||||
.OrderByDescending(g => g.Count())
|
||||
.Select(g => g.Key)
|
||||
.ToArray();
|
||||
|
||||
var id = item.GetProviderId(provider);
|
||||
if (ids.Any())
|
||||
{
|
||||
var firstId = ids[0];
|
||||
if (!string.IsNullOrEmpty(firstId)
|
||||
&& (string.IsNullOrEmpty(id)
|
||||
|| !id.Equals(firstId, StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
item.SetProviderId(provider, firstId);
|
||||
return ItemUpdateType.MetadataEdit;
|
||||
}
|
||||
}
|
||||
return ItemUpdateType.None;
|
||||
}
|
||||
|
||||
private void SetProviderId(MusicAlbum sourceItem, MusicAlbum targetItem, MetadataProvider provider)
|
||||
{
|
||||
var source = sourceItem.GetProviderId(provider);
|
||||
var target = targetItem.GetProviderId(provider);
|
||||
if (!string.IsNullOrEmpty(source)
|
||||
&& (string.IsNullOrEmpty(target)
|
||||
|| !target.Equals(source, StringComparison.Ordinal)))
|
||||
{
|
||||
targetItem.SetProviderId(provider, source);
|
||||
}
|
||||
}
|
||||
|
||||
private ItemUpdateType SetPeople(MusicAlbum item)
|
||||
{
|
||||
var updateType = ItemUpdateType.None;
|
||||
|
||||
if (item.AlbumArtists.Any() || item.Artists.Any())
|
||||
{
|
||||
var people = new List<PersonInfo>();
|
||||
|
||||
foreach (var albumArtist in item.AlbumArtists)
|
||||
{
|
||||
PeopleHelper.AddPerson(people, new PersonInfo
|
||||
{
|
||||
Name = albumArtist,
|
||||
Type = "AlbumArtist"
|
||||
});
|
||||
}
|
||||
|
||||
foreach (var artist in item.Artists)
|
||||
{
|
||||
PeopleHelper.AddPerson(people, new PersonInfo
|
||||
{
|
||||
Name = artist,
|
||||
Type = "Artist"
|
||||
});
|
||||
}
|
||||
|
||||
LibraryManager.UpdatePeople(item, people);
|
||||
updateType |= ItemUpdateType.MetadataEdit;
|
||||
}
|
||||
|
||||
return updateType;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void MergeData(
|
||||
MetadataResult<MusicAlbum> source,
|
||||
@@ -123,6 +217,21 @@ namespace MediaBrowser.Providers.Music
|
||||
{
|
||||
targetItem.Artists = sourceItem.Artists;
|
||||
}
|
||||
|
||||
if (replaceData || string.IsNullOrEmpty(targetItem.GetProviderId(MetadataProvider.MusicBrainzAlbumArtist)))
|
||||
{
|
||||
SetProviderId(sourceItem, targetItem, MetadataProvider.MusicBrainzAlbumArtist);
|
||||
}
|
||||
|
||||
if (replaceData || string.IsNullOrEmpty(targetItem.GetProviderId(MetadataProvider.MusicBrainzAlbum)))
|
||||
{
|
||||
SetProviderId(sourceItem, targetItem, MetadataProvider.MusicBrainzAlbum);
|
||||
}
|
||||
|
||||
if (replaceData || string.IsNullOrEmpty(targetItem.GetProviderId(MetadataProvider.MusicBrainzReleaseGroup)))
|
||||
{
|
||||
SetProviderId(sourceItem, targetItem, MetadataProvider.MusicBrainzReleaseGroup);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#pragma warning disable CS1591
|
||||
|
||||
using System;
|
||||
using MediaBrowser.Controller.Configuration;
|
||||
using MediaBrowser.Controller.Entities.Audio;
|
||||
using MediaBrowser.Controller.Library;
|
||||
@@ -11,8 +10,19 @@ using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace MediaBrowser.Providers.Music
|
||||
{
|
||||
/// <summary>
|
||||
/// The audio metadata service.
|
||||
/// </summary>
|
||||
public class AudioMetadataService : MetadataService<Audio, SongInfo>
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AudioMetadataService"/> class.
|
||||
/// </summary>
|
||||
/// <param name="serverConfigurationManager">Instance of the <see cref="IServerConfigurationManager"/>.</param>
|
||||
/// <param name="logger">Instance of the <see cref="ILogger"/> interface.</param>
|
||||
/// <param name="providerManager">Instance of the <see cref="IProviderManager"/> interface.</param>
|
||||
/// <param name="fileSystem">Instance of the <see cref="IFileSystem"/> interface.</param>
|
||||
/// <param name="libraryManager">Instance of the <see cref="ILibraryManager"/> interface.</param>
|
||||
public AudioMetadataService(
|
||||
IServerConfigurationManager serverConfigurationManager,
|
||||
ILogger<AudioMetadataService> logger,
|
||||
@@ -23,6 +33,21 @@ namespace MediaBrowser.Providers.Music
|
||||
{
|
||||
}
|
||||
|
||||
private void SetProviderId(Audio sourceItem, Audio targetItem, bool replaceData, MetadataProvider provider)
|
||||
{
|
||||
var target = targetItem.GetProviderId(provider);
|
||||
if (replaceData || string.IsNullOrEmpty(target))
|
||||
{
|
||||
var source = sourceItem.GetProviderId(provider);
|
||||
if (!string.IsNullOrEmpty(source)
|
||||
&& (string.IsNullOrEmpty(target)
|
||||
|| !target.Equals(source, StringComparison.Ordinal)))
|
||||
{
|
||||
targetItem.SetProviderId(provider, source);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void MergeData(MetadataResult<Audio> source, MetadataResult<Audio> target, MetadataField[] lockedFields, bool replaceData, bool mergeMetadataSettings)
|
||||
{
|
||||
@@ -40,6 +65,10 @@ namespace MediaBrowser.Providers.Music
|
||||
{
|
||||
targetItem.Album = sourceItem.Album;
|
||||
}
|
||||
|
||||
SetProviderId(sourceItem, targetItem, replaceData, MetadataProvider.MusicBrainzAlbumArtist);
|
||||
SetProviderId(sourceItem, targetItem, replaceData, MetadataProvider.MusicBrainzAlbum);
|
||||
SetProviderId(sourceItem, targetItem, replaceData, MetadataProvider.MusicBrainzReleaseGroup);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,37 +1,52 @@
|
||||
#pragma warning disable CS1591
|
||||
|
||||
using MediaBrowser.Model.Plugins;
|
||||
using MetaBrainz.MusicBrainz;
|
||||
|
||||
namespace MediaBrowser.Providers.Plugins.MusicBrainz
|
||||
namespace MediaBrowser.Providers.Plugins.MusicBrainz.Configuration;
|
||||
|
||||
/// <summary>
|
||||
/// MusicBrainz plugin configuration.
|
||||
/// </summary>
|
||||
public class PluginConfiguration : BasePluginConfiguration
|
||||
{
|
||||
public class PluginConfiguration : BasePluginConfiguration
|
||||
private const string DefaultServer = "musicbrainz.org";
|
||||
|
||||
private const double DefaultRateLimit = 1.0;
|
||||
|
||||
private string _server = DefaultServer;
|
||||
|
||||
private double _rateLimit = DefaultRateLimit;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the server url.
|
||||
/// </summary>
|
||||
public string Server
|
||||
{
|
||||
private string _server = Plugin.DefaultServer;
|
||||
get => _server;
|
||||
|
||||
private long _rateLimit = Plugin.DefaultRateLimit;
|
||||
set => _server = value.TrimEnd('/');
|
||||
}
|
||||
|
||||
public string Server
|
||||
/// <summary>
|
||||
/// Gets or sets the rate limit.
|
||||
/// </summary>
|
||||
public double RateLimit
|
||||
{
|
||||
get => _rateLimit;
|
||||
set
|
||||
{
|
||||
get => _server;
|
||||
set => _server = value.TrimEnd('/');
|
||||
}
|
||||
|
||||
public long RateLimit
|
||||
{
|
||||
get => _rateLimit;
|
||||
set
|
||||
if (value < DefaultRateLimit && _server == DefaultServer)
|
||||
{
|
||||
if (value < Plugin.DefaultRateLimit && _server == Plugin.DefaultServer)
|
||||
{
|
||||
_rateLimit = Plugin.DefaultRateLimit;
|
||||
}
|
||||
else
|
||||
{
|
||||
_rateLimit = value;
|
||||
}
|
||||
_rateLimit = DefaultRateLimit;
|
||||
}
|
||||
else
|
||||
{
|
||||
_rateLimit = value;
|
||||
}
|
||||
}
|
||||
|
||||
public bool ReplaceArtistName { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether to replace the artist name.
|
||||
/// </summary>
|
||||
public bool ReplaceArtistName { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,28 +1,27 @@
|
||||
#pragma warning disable CS1591
|
||||
|
||||
using MediaBrowser.Controller.Entities.Audio;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Providers;
|
||||
using MediaBrowser.Providers.Plugins.MusicBrainz;
|
||||
|
||||
namespace MediaBrowser.Providers.Music
|
||||
namespace MediaBrowser.Providers.Plugins.MusicBrainz;
|
||||
|
||||
/// <summary>
|
||||
/// MusicBrainz album artist external id.
|
||||
/// </summary>
|
||||
public class MusicBrainzAlbumArtistExternalId : IExternalId
|
||||
{
|
||||
public class MusicBrainzAlbumArtistExternalId : IExternalId
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public string ProviderName => "MusicBrainz";
|
||||
/// <inheritdoc />
|
||||
public string ProviderName => "MusicBrainz";
|
||||
|
||||
/// <inheritdoc />
|
||||
public string Key => MetadataProvider.MusicBrainzAlbumArtist.ToString();
|
||||
/// <inheritdoc />
|
||||
public string Key => MetadataProvider.MusicBrainzAlbumArtist.ToString();
|
||||
|
||||
/// <inheritdoc />
|
||||
public ExternalIdMediaType? Type => ExternalIdMediaType.AlbumArtist;
|
||||
/// <inheritdoc />
|
||||
public ExternalIdMediaType? Type => ExternalIdMediaType.AlbumArtist;
|
||||
|
||||
/// <inheritdoc />
|
||||
public string? UrlFormatString => Plugin.Instance.Configuration.Server + "/artist/{0}";
|
||||
/// <inheritdoc />
|
||||
public string? UrlFormatString => Plugin.Instance!.Configuration.Server + "/artist/{0}";
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool Supports(IHasProviderIds item) => item is Audio;
|
||||
}
|
||||
/// <inheritdoc />
|
||||
public bool Supports(IHasProviderIds item) => item is Audio;
|
||||
}
|
||||
|
||||
@@ -1,28 +1,27 @@
|
||||
#pragma warning disable CS1591
|
||||
|
||||
using MediaBrowser.Controller.Entities.Audio;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Providers;
|
||||
using MediaBrowser.Providers.Plugins.MusicBrainz;
|
||||
|
||||
namespace MediaBrowser.Providers.Music
|
||||
namespace MediaBrowser.Providers.Plugins.MusicBrainz;
|
||||
|
||||
/// <summary>
|
||||
/// MusicBrainz album external id.
|
||||
/// </summary>
|
||||
public class MusicBrainzAlbumExternalId : IExternalId
|
||||
{
|
||||
public class MusicBrainzAlbumExternalId : IExternalId
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public string ProviderName => "MusicBrainz";
|
||||
/// <inheritdoc />
|
||||
public string ProviderName => "MusicBrainz";
|
||||
|
||||
/// <inheritdoc />
|
||||
public string Key => MetadataProvider.MusicBrainzAlbum.ToString();
|
||||
/// <inheritdoc />
|
||||
public string Key => MetadataProvider.MusicBrainzAlbum.ToString();
|
||||
|
||||
/// <inheritdoc />
|
||||
public ExternalIdMediaType? Type => ExternalIdMediaType.Album;
|
||||
/// <inheritdoc />
|
||||
public ExternalIdMediaType? Type => ExternalIdMediaType.Album;
|
||||
|
||||
/// <inheritdoc />
|
||||
public string? UrlFormatString => Plugin.Instance.Configuration.Server + "/release/{0}";
|
||||
/// <inheritdoc />
|
||||
public string? UrlFormatString => Plugin.Instance!.Configuration.Server + "/release/{0}";
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool Supports(IHasProviderIds item) => item is Audio || item is MusicAlbum;
|
||||
}
|
||||
/// <inheritdoc />
|
||||
public bool Supports(IHasProviderIds item) => item is Audio || item is MusicAlbum;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,28 +1,27 @@
|
||||
#pragma warning disable CS1591
|
||||
|
||||
using MediaBrowser.Controller.Entities.Audio;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Providers;
|
||||
using MediaBrowser.Providers.Plugins.MusicBrainz;
|
||||
|
||||
namespace MediaBrowser.Providers.Music
|
||||
namespace MediaBrowser.Providers.Plugins.MusicBrainz;
|
||||
|
||||
/// <summary>
|
||||
/// MusicBrainz artist external id.
|
||||
/// </summary>
|
||||
public class MusicBrainzArtistExternalId : IExternalId
|
||||
{
|
||||
public class MusicBrainzArtistExternalId : IExternalId
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public string ProviderName => "MusicBrainz";
|
||||
/// <inheritdoc />
|
||||
public string ProviderName => "MusicBrainz";
|
||||
|
||||
/// <inheritdoc />
|
||||
public string Key => MetadataProvider.MusicBrainzArtist.ToString();
|
||||
/// <inheritdoc />
|
||||
public string Key => MetadataProvider.MusicBrainzArtist.ToString();
|
||||
|
||||
/// <inheritdoc />
|
||||
public ExternalIdMediaType? Type => ExternalIdMediaType.Artist;
|
||||
/// <inheritdoc />
|
||||
public ExternalIdMediaType? Type => ExternalIdMediaType.Artist;
|
||||
|
||||
/// <inheritdoc />
|
||||
public string? UrlFormatString => Plugin.Instance.Configuration.Server + "/artist/{0}";
|
||||
/// <inheritdoc />
|
||||
public string? UrlFormatString => Plugin.Instance!.Configuration.Server + "/artist/{0}";
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool Supports(IHasProviderIds item) => item is MusicArtist;
|
||||
}
|
||||
/// <inheritdoc />
|
||||
public bool Supports(IHasProviderIds item) => item is MusicArtist;
|
||||
}
|
||||
|
||||
@@ -1,15 +1,7 @@
|
||||
#nullable disable
|
||||
|
||||
#pragma warning disable CS1591
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
@@ -18,257 +10,152 @@ using MediaBrowser.Controller.Entities.Audio;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Providers;
|
||||
using MediaBrowser.Providers.Plugins.MusicBrainz;
|
||||
using MediaBrowser.Providers.Music;
|
||||
using MetaBrainz.MusicBrainz;
|
||||
using MetaBrainz.MusicBrainz.Interfaces.Entities;
|
||||
using MetaBrainz.MusicBrainz.Interfaces.Searches;
|
||||
|
||||
namespace MediaBrowser.Providers.Music
|
||||
namespace MediaBrowser.Providers.Plugins.MusicBrainz;
|
||||
|
||||
/// <summary>
|
||||
/// MusicBrainz artist provider.
|
||||
/// </summary>
|
||||
public class MusicBrainzArtistProvider : IRemoteMetadataProvider<MusicArtist, ArtistInfo>, IDisposable
|
||||
{
|
||||
public class MusicBrainzArtistProvider : IRemoteMetadataProvider<MusicArtist, ArtistInfo>
|
||||
private readonly Query _musicBrainzQuery;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="MusicBrainzArtistProvider"/> class.
|
||||
/// </summary>
|
||||
public MusicBrainzArtistProvider()
|
||||
{
|
||||
public string Name => "MusicBrainz";
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(ArtistInfo searchInfo, CancellationToken cancellationToken)
|
||||
{
|
||||
var musicBrainzId = searchInfo.GetMusicBrainzArtistId();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(musicBrainzId))
|
||||
MusicBrainz.Plugin.Instance!.ConfigurationChanged += (_, _) =>
|
||||
{
|
||||
var url = "/ws/2/artist/?query=arid:{0}" + musicBrainzId.ToString(CultureInfo.InvariantCulture);
|
||||
|
||||
using var response = await MusicBrainzAlbumProvider.Current.GetMusicBrainzResponse(url, cancellationToken).ConfigureAwait(false);
|
||||
await using var stream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
|
||||
return GetResultsFromResponse(stream);
|
||||
}
|
||||
else
|
||||
{
|
||||
// They seem to throw bad request failures on any term with a slash
|
||||
var nameToSearch = searchInfo.Name.Replace('/', ' ');
|
||||
|
||||
var url = string.Format(CultureInfo.InvariantCulture, "/ws/2/artist/?query=\"{0}\"&dismax=true", UrlEncode(nameToSearch));
|
||||
|
||||
using (var response = await MusicBrainzAlbumProvider.Current.GetMusicBrainzResponse(url, cancellationToken).ConfigureAwait(false))
|
||||
await using (var stream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false))
|
||||
{
|
||||
var results = GetResultsFromResponse(stream).ToList();
|
||||
|
||||
if (results.Count > 0)
|
||||
{
|
||||
return results;
|
||||
}
|
||||
}
|
||||
|
||||
if (searchInfo.Name.HasDiacritics())
|
||||
{
|
||||
// Try again using the search with accent characters url
|
||||
url = string.Format(CultureInfo.InvariantCulture, "/ws/2/artist/?query=artistaccent:\"{0}\"", UrlEncode(nameToSearch));
|
||||
|
||||
using var response = await MusicBrainzAlbumProvider.Current.GetMusicBrainzResponse(url, cancellationToken).ConfigureAwait(false);
|
||||
await using var stream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
|
||||
return GetResultsFromResponse(stream);
|
||||
}
|
||||
}
|
||||
|
||||
return Enumerable.Empty<RemoteSearchResult>();
|
||||
}
|
||||
|
||||
private IEnumerable<RemoteSearchResult> GetResultsFromResponse(Stream stream)
|
||||
{
|
||||
using var oReader = new StreamReader(stream, Encoding.UTF8);
|
||||
var settings = new XmlReaderSettings()
|
||||
{
|
||||
ValidationType = ValidationType.None,
|
||||
CheckCharacters = false,
|
||||
IgnoreProcessingInstructions = true,
|
||||
IgnoreComments = true
|
||||
Query.DefaultServer = MusicBrainz.Plugin.Instance.Configuration.Server;
|
||||
Query.DelayBetweenRequests = MusicBrainz.Plugin.Instance.Configuration.RateLimit;
|
||||
};
|
||||
|
||||
using var reader = XmlReader.Create(oReader, settings);
|
||||
reader.MoveToContent();
|
||||
reader.Read();
|
||||
_musicBrainzQuery = new Query();
|
||||
}
|
||||
|
||||
// Loop through each element
|
||||
while (!reader.EOF && reader.ReadState == ReadState.Interactive)
|
||||
{
|
||||
if (reader.NodeType == XmlNodeType.Element)
|
||||
{
|
||||
switch (reader.Name)
|
||||
{
|
||||
case "artist-list":
|
||||
{
|
||||
if (reader.IsEmptyElement)
|
||||
{
|
||||
reader.Read();
|
||||
continue;
|
||||
}
|
||||
/// <inheritdoc />
|
||||
public string Name => "MusicBrainz";
|
||||
|
||||
using var subReader = reader.ReadSubtree();
|
||||
return ParseArtistList(subReader).ToList();
|
||||
}
|
||||
/// <inheritdoc />
|
||||
public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(ArtistInfo searchInfo, CancellationToken cancellationToken)
|
||||
{
|
||||
var artistId = searchInfo.GetMusicBrainzArtistId();
|
||||
|
||||
default:
|
||||
{
|
||||
reader.Skip();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
reader.Read();
|
||||
}
|
||||
}
|
||||
|
||||
return Enumerable.Empty<RemoteSearchResult>();
|
||||
if (!string.IsNullOrWhiteSpace(artistId))
|
||||
{
|
||||
var artistResult = await _musicBrainzQuery.LookupArtistAsync(new Guid(artistId), Include.Aliases, null, null, cancellationToken).ConfigureAwait(false);
|
||||
return GetResultFromResponse(artistResult).SingleItemAsEnumerable();
|
||||
}
|
||||
|
||||
private IEnumerable<RemoteSearchResult> ParseArtistList(XmlReader reader)
|
||||
var artistSearchResults = await _musicBrainzQuery.FindArtistsAsync($"\"{searchInfo.Name}\"", null, null, false, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
if (artistSearchResults.Results.Count > 0)
|
||||
{
|
||||
reader.MoveToContent();
|
||||
reader.Read();
|
||||
return GetResultsFromResponse(artistSearchResults.Results);
|
||||
}
|
||||
|
||||
// Loop through each element
|
||||
while (!reader.EOF && reader.ReadState == ReadState.Interactive)
|
||||
if (searchInfo.Name.HasDiacritics())
|
||||
{
|
||||
// Try again using the search with an accented characters query
|
||||
var artistAccentsSearchResults = await _musicBrainzQuery.FindArtistsAsync($"artistaccent:\"{searchInfo.Name}\"", null, null, false, cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
if (artistAccentsSearchResults.Results.Count > 0)
|
||||
{
|
||||
if (reader.NodeType == XmlNodeType.Element)
|
||||
return GetResultsFromResponse(artistAccentsSearchResults.Results);
|
||||
}
|
||||
}
|
||||
|
||||
return Enumerable.Empty<RemoteSearchResult>();
|
||||
}
|
||||
|
||||
private IEnumerable<RemoteSearchResult> GetResultsFromResponse(IEnumerable<ISearchResult<IArtist>>? releaseSearchResults)
|
||||
{
|
||||
if (releaseSearchResults is null)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
foreach (var result in releaseSearchResults)
|
||||
{
|
||||
yield return GetResultFromResponse(result.Item);
|
||||
}
|
||||
}
|
||||
|
||||
private RemoteSearchResult GetResultFromResponse(IArtist artist)
|
||||
{
|
||||
var searchResult = new RemoteSearchResult
|
||||
{
|
||||
Name = artist.Name,
|
||||
ProductionYear = artist.LifeSpan?.Begin?.Year,
|
||||
PremiereDate = artist.LifeSpan?.Begin?.NearestDate
|
||||
};
|
||||
|
||||
searchResult.SetProviderId(MetadataProvider.MusicBrainzArtist, artist.Id.ToString());
|
||||
|
||||
return searchResult;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<MetadataResult<MusicArtist>> GetMetadata(ArtistInfo info, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = new MetadataResult<MusicArtist> { Item = new MusicArtist() };
|
||||
|
||||
var musicBrainzId = info.GetMusicBrainzArtistId();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(musicBrainzId))
|
||||
{
|
||||
var searchResults = await GetSearchResults(info, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
var singleResult = searchResults.FirstOrDefault();
|
||||
|
||||
if (singleResult != null)
|
||||
{
|
||||
musicBrainzId = singleResult.GetProviderId(MetadataProvider.MusicBrainzArtist);
|
||||
result.Item.Overview = singleResult.Overview;
|
||||
|
||||
if (Plugin.Instance!.Configuration.ReplaceArtistName)
|
||||
{
|
||||
switch (reader.Name)
|
||||
{
|
||||
case "artist":
|
||||
{
|
||||
if (reader.IsEmptyElement)
|
||||
{
|
||||
reader.Read();
|
||||
continue;
|
||||
}
|
||||
|
||||
var mbzId = reader.GetAttribute("id");
|
||||
|
||||
using var subReader = reader.ReadSubtree();
|
||||
var artist = ParseArtist(subReader, mbzId);
|
||||
if (artist != null)
|
||||
{
|
||||
yield return artist;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
reader.Skip();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
reader.Read();
|
||||
result.Item.Name = singleResult.Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private RemoteSearchResult ParseArtist(XmlReader reader, string artistId)
|
||||
if (!string.IsNullOrWhiteSpace(musicBrainzId))
|
||||
{
|
||||
var result = new RemoteSearchResult();
|
||||
|
||||
reader.MoveToContent();
|
||||
reader.Read();
|
||||
|
||||
// http://stackoverflow.com/questions/2299632/why-does-xmlreader-skip-every-other-element-if-there-is-no-whitespace-separator
|
||||
|
||||
// Loop through each element
|
||||
while (!reader.EOF && reader.ReadState == ReadState.Interactive)
|
||||
{
|
||||
if (reader.NodeType == XmlNodeType.Element)
|
||||
{
|
||||
switch (reader.Name)
|
||||
{
|
||||
case "name":
|
||||
{
|
||||
result.Name = reader.ReadElementContentAsString();
|
||||
break;
|
||||
}
|
||||
|
||||
case "annotation":
|
||||
{
|
||||
result.Overview = reader.ReadElementContentAsString();
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
// there is sort-name if ever needed
|
||||
reader.Skip();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
reader.Read();
|
||||
}
|
||||
}
|
||||
|
||||
result.SetProviderId(MetadataProvider.MusicBrainzArtist, artistId);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(artistId) || string.IsNullOrWhiteSpace(result.Name))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return result;
|
||||
result.HasMetadata = true;
|
||||
result.Item.SetProviderId(MetadataProvider.MusicBrainzArtist, musicBrainzId);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<MetadataResult<MusicArtist>> GetMetadata(ArtistInfo info, CancellationToken cancellationToken)
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dispose all resources.
|
||||
/// </summary>
|
||||
/// <param name="disposing">Whether to dispose.</param>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
var result = new MetadataResult<MusicArtist>
|
||||
{
|
||||
Item = new MusicArtist()
|
||||
};
|
||||
|
||||
var musicBrainzId = info.GetMusicBrainzArtistId();
|
||||
|
||||
if (string.IsNullOrWhiteSpace(musicBrainzId))
|
||||
{
|
||||
var searchResults = await GetSearchResults(info, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
var singleResult = searchResults.FirstOrDefault();
|
||||
|
||||
if (singleResult != null)
|
||||
{
|
||||
musicBrainzId = singleResult.GetProviderId(MetadataProvider.MusicBrainzArtist);
|
||||
result.Item.Overview = singleResult.Overview;
|
||||
|
||||
if (Plugin.Instance.Configuration.ReplaceArtistName)
|
||||
{
|
||||
result.Item.Name = singleResult.Name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(musicBrainzId))
|
||||
{
|
||||
result.HasMetadata = true;
|
||||
result.Item.SetProviderId(MetadataProvider.MusicBrainzArtist, musicBrainzId);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Encodes an URL.
|
||||
/// </summary>
|
||||
/// <param name="name">The name.</param>
|
||||
/// <returns>System.String.</returns>
|
||||
private static string UrlEncode(string name)
|
||||
{
|
||||
return WebUtility.UrlEncode(name);
|
||||
}
|
||||
|
||||
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
_musicBrainzQuery.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +1,27 @@
|
||||
#pragma warning disable CS1591
|
||||
|
||||
using MediaBrowser.Controller.Entities.Audio;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Providers;
|
||||
using MediaBrowser.Providers.Plugins.MusicBrainz;
|
||||
|
||||
namespace MediaBrowser.Providers.Music
|
||||
namespace MediaBrowser.Providers.Plugins.MusicBrainz;
|
||||
|
||||
/// <summary>
|
||||
/// MusicBrainz other artist external id.
|
||||
/// </summary>
|
||||
public class MusicBrainzOtherArtistExternalId : IExternalId
|
||||
{
|
||||
public class MusicBrainzOtherArtistExternalId : IExternalId
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public string ProviderName => "MusicBrainz";
|
||||
/// <inheritdoc />
|
||||
public string ProviderName => "MusicBrainz";
|
||||
|
||||
/// <inheritdoc />
|
||||
public string Key => MetadataProvider.MusicBrainzArtist.ToString();
|
||||
/// <inheritdoc />
|
||||
public string Key => MetadataProvider.MusicBrainzArtist.ToString();
|
||||
|
||||
/// <inheritdoc />
|
||||
public ExternalIdMediaType? Type => ExternalIdMediaType.OtherArtist;
|
||||
/// <inheritdoc />
|
||||
public ExternalIdMediaType? Type => ExternalIdMediaType.OtherArtist;
|
||||
|
||||
/// <inheritdoc />
|
||||
public string? UrlFormatString => Plugin.Instance.Configuration.Server + "/artist/{0}";
|
||||
/// <inheritdoc />
|
||||
public string? UrlFormatString => Plugin.Instance!.Configuration.Server + "/artist/{0}";
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool Supports(IHasProviderIds item) => item is Audio || item is MusicAlbum;
|
||||
}
|
||||
/// <inheritdoc />
|
||||
public bool Supports(IHasProviderIds item) => item is Audio or MusicAlbum;
|
||||
}
|
||||
|
||||
@@ -1,28 +1,27 @@
|
||||
#pragma warning disable CS1591
|
||||
|
||||
using MediaBrowser.Controller.Entities.Audio;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Providers;
|
||||
using MediaBrowser.Providers.Plugins.MusicBrainz;
|
||||
|
||||
namespace MediaBrowser.Providers.Music
|
||||
namespace MediaBrowser.Providers.Plugins.MusicBrainz;
|
||||
|
||||
/// <summary>
|
||||
/// MusicBrainz release group external id.
|
||||
/// </summary>
|
||||
public class MusicBrainzReleaseGroupExternalId : IExternalId
|
||||
{
|
||||
public class MusicBrainzReleaseGroupExternalId : IExternalId
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public string ProviderName => "MusicBrainz";
|
||||
/// <inheritdoc />
|
||||
public string ProviderName => "MusicBrainz";
|
||||
|
||||
/// <inheritdoc />
|
||||
public string Key => MetadataProvider.MusicBrainzReleaseGroup.ToString();
|
||||
/// <inheritdoc />
|
||||
public string Key => MetadataProvider.MusicBrainzReleaseGroup.ToString();
|
||||
|
||||
/// <inheritdoc />
|
||||
public ExternalIdMediaType? Type => ExternalIdMediaType.ReleaseGroup;
|
||||
/// <inheritdoc />
|
||||
public ExternalIdMediaType? Type => ExternalIdMediaType.ReleaseGroup;
|
||||
|
||||
/// <inheritdoc />
|
||||
public string? UrlFormatString => Plugin.Instance.Configuration.Server + "/release-group/{0}";
|
||||
/// <inheritdoc />
|
||||
public string? UrlFormatString => Plugin.Instance!.Configuration.Server + "/release-group/{0}";
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool Supports(IHasProviderIds item) => item is Audio || item is MusicAlbum;
|
||||
}
|
||||
/// <inheritdoc />
|
||||
public bool Supports(IHasProviderIds item) => item is Audio or MusicAlbum;
|
||||
}
|
||||
|
||||
@@ -1,28 +1,27 @@
|
||||
#pragma warning disable CS1591
|
||||
|
||||
using MediaBrowser.Controller.Entities.Audio;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Providers;
|
||||
using MediaBrowser.Providers.Plugins.MusicBrainz;
|
||||
|
||||
namespace MediaBrowser.Providers.Music
|
||||
namespace MediaBrowser.Providers.Plugins.MusicBrainz;
|
||||
|
||||
/// <summary>
|
||||
/// MusicBrainz track id.
|
||||
/// </summary>
|
||||
public class MusicBrainzTrackId : IExternalId
|
||||
{
|
||||
public class MusicBrainzTrackId : IExternalId
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public string ProviderName => "MusicBrainz";
|
||||
/// <inheritdoc />
|
||||
public string ProviderName => "MusicBrainz";
|
||||
|
||||
/// <inheritdoc />
|
||||
public string Key => MetadataProvider.MusicBrainzTrack.ToString();
|
||||
/// <inheritdoc />
|
||||
public string Key => MetadataProvider.MusicBrainzTrack.ToString();
|
||||
|
||||
/// <inheritdoc />
|
||||
public ExternalIdMediaType? Type => ExternalIdMediaType.Track;
|
||||
/// <inheritdoc />
|
||||
public ExternalIdMediaType? Type => ExternalIdMediaType.Track;
|
||||
|
||||
/// <inheritdoc />
|
||||
public string? UrlFormatString => Plugin.Instance.Configuration.Server + "/track/{0}";
|
||||
/// <inheritdoc />
|
||||
public string? UrlFormatString => Plugin.Instance!.Configuration.Server + "/track/{0}";
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool Supports(IHasProviderIds item) => item is Audio;
|
||||
}
|
||||
/// <inheritdoc />
|
||||
public bool Supports(IHasProviderIds item) => item is Audio;
|
||||
}
|
||||
|
||||
@@ -1,45 +1,64 @@
|
||||
#nullable disable
|
||||
#pragma warning disable CS1591
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http.Headers;
|
||||
using MediaBrowser.Common;
|
||||
using MediaBrowser.Common.Configuration;
|
||||
using MediaBrowser.Common.Plugins;
|
||||
using MediaBrowser.Model.Plugins;
|
||||
using MediaBrowser.Model.Serialization;
|
||||
using MediaBrowser.Providers.Plugins.MusicBrainz.Configuration;
|
||||
using MetaBrainz.MusicBrainz;
|
||||
|
||||
namespace MediaBrowser.Providers.Plugins.MusicBrainz
|
||||
namespace MediaBrowser.Providers.Plugins.MusicBrainz;
|
||||
|
||||
/// <summary>
|
||||
/// Plugin instance.
|
||||
/// </summary>
|
||||
public class Plugin : BasePlugin<PluginConfiguration>, IHasWebPages
|
||||
{
|
||||
public class Plugin : BasePlugin<PluginConfiguration>, IHasWebPages
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Plugin"/> class.
|
||||
/// </summary>
|
||||
/// <param name="applicationPaths">Instance of the <see cref="IApplicationPaths"/> interface.</param>
|
||||
/// <param name="xmlSerializer">Instance of the <see cref="IXmlSerializer"/> interface.</param>
|
||||
/// <param name="applicationHost">Instance of the <see cref="IApplicationHost"/> interface.</param>
|
||||
public Plugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer, IApplicationHost applicationHost)
|
||||
: base(applicationPaths, xmlSerializer)
|
||||
{
|
||||
public const string DefaultServer = "https://musicbrainz.org";
|
||||
Instance = this;
|
||||
|
||||
public const long DefaultRateLimit = 2000u;
|
||||
// TODO: Change this to "JellyfinMusicBrainzPlugin" once we take it out of the server repo.
|
||||
Query.DefaultUserAgent.Add(new ProductInfoHeaderValue(applicationHost.Name.Replace(' ', '-'), applicationHost.ApplicationVersionString));
|
||||
Query.DefaultUserAgent.Add(new ProductInfoHeaderValue($"({applicationHost.ApplicationUserAgentAddress})"));
|
||||
Query.DelayBetweenRequests = Instance.Configuration.RateLimit;
|
||||
Query.DefaultServer = Instance.Configuration.Server;
|
||||
}
|
||||
|
||||
public Plugin(IApplicationPaths applicationPaths, IXmlSerializer xmlSerializer)
|
||||
: base(applicationPaths, xmlSerializer)
|
||||
/// <summary>
|
||||
/// Gets the current plugin instance.
|
||||
/// </summary>
|
||||
public static Plugin? Instance { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override Guid Id => new Guid("8c95c4d2-e50c-4fb0-a4f3-6c06ff0f9a1a");
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string Name => "MusicBrainz";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string Description => "Get artist and album metadata from any MusicBrainz server.";
|
||||
|
||||
/// <inheritdoc />
|
||||
// TODO remove when plugin removed from server.
|
||||
public override string ConfigurationFileName => "Jellyfin.Plugin.MusicBrainz.xml";
|
||||
|
||||
/// <inheritdoc />
|
||||
public IEnumerable<PluginPageInfo> GetPages()
|
||||
{
|
||||
yield return new PluginPageInfo
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
public static Plugin Instance { get; private set; }
|
||||
|
||||
public override Guid Id => new Guid("8c95c4d2-e50c-4fb0-a4f3-6c06ff0f9a1a");
|
||||
|
||||
public override string Name => "MusicBrainz";
|
||||
|
||||
public override string Description => "Get artist and album metadata from any MusicBrainz server.";
|
||||
|
||||
// TODO remove when plugin removed from server.
|
||||
public override string ConfigurationFileName => "Jellyfin.Plugin.MusicBrainz.xml";
|
||||
|
||||
public IEnumerable<PluginPageInfo> GetPages()
|
||||
{
|
||||
yield return new PluginPageInfo
|
||||
{
|
||||
Name = Name,
|
||||
EmbeddedResourcePath = GetType().Namespace + ".Configuration.config.html"
|
||||
};
|
||||
}
|
||||
Name = Name,
|
||||
EmbeddedResourcePath = GetType().Namespace + ".Configuration.config.html"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -408,10 +408,7 @@ namespace MediaBrowser.Providers.Plugins.Omdb
|
||||
}
|
||||
}
|
||||
|
||||
if (isEnglishRequested)
|
||||
{
|
||||
item.Overview = result.Plot;
|
||||
}
|
||||
item.Overview = result.Plot;
|
||||
|
||||
if (!Plugin.Instance.Configuration.CastAndCrew)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user