< Summary - Jellyfin

Information
Class: Jellyfin.Server.Implementations.Events.Consumers.Library.LyricDownloadFailureLogger
Assembly: Jellyfin.Server.Implementations
File(s): /srv/git/jellyfin/Jellyfin.Server.Implementations/Events/Consumers/Library/LyricDownloadFailureLogger.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 28
Coverable lines: 28
Total lines: 101
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 16
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
GetItemName(...)0%272160%

File(s)

/srv/git/jellyfin/Jellyfin.Server.Implementations/Events/Consumers/Library/LyricDownloadFailureLogger.cs

#LineLine coverage
 1using System;
 2using System.Globalization;
 3using System.Threading.Tasks;
 4using Jellyfin.Data.Entities;
 5using MediaBrowser.Controller.Entities;
 6using MediaBrowser.Controller.Entities.Audio;
 7using MediaBrowser.Controller.Events;
 8using MediaBrowser.Controller.Lyrics;
 9using MediaBrowser.Model.Activity;
 10using MediaBrowser.Model.Globalization;
 11using Episode = MediaBrowser.Controller.Entities.TV.Episode;
 12
 13namespace Jellyfin.Server.Implementations.Events.Consumers.Library;
 14
 15/// <summary>
 16/// Creates an entry in the activity log whenever a lyric download fails.
 17/// </summary>
 18public class LyricDownloadFailureLogger : IEventConsumer<LyricDownloadFailureEventArgs>
 19{
 20    private readonly ILocalizationManager _localizationManager;
 21    private readonly IActivityManager _activityManager;
 22
 23    /// <summary>
 24    /// Initializes a new instance of the <see cref="LyricDownloadFailureLogger"/> class.
 25    /// </summary>
 26    /// <param name="localizationManager">The localization manager.</param>
 27    /// <param name="activityManager">The activity manager.</param>
 28    public LyricDownloadFailureLogger(ILocalizationManager localizationManager, IActivityManager activityManager)
 29    {
 030        _localizationManager = localizationManager;
 031        _activityManager = activityManager;
 032    }
 33
 34    /// <inheritdoc />
 35    public async Task OnEvent(LyricDownloadFailureEventArgs eventArgs)
 36    {
 37        await _activityManager.CreateAsync(new ActivityLog(
 38            string.Format(
 39                CultureInfo.InvariantCulture,
 40                _localizationManager.GetLocalizedString("LyricDownloadFailureFromForItem"),
 41                eventArgs.Provider,
 42                GetItemName(eventArgs.Item)),
 43            "LyricDownloadFailure",
 44            Guid.Empty)
 45        {
 46            ItemId = eventArgs.Item.Id.ToString("N", CultureInfo.InvariantCulture),
 47            ShortOverview = eventArgs.Exception.Message
 48        }).ConfigureAwait(false);
 49    }
 50
 51    private static string GetItemName(BaseItem item)
 52    {
 053        var name = item.Name;
 054        if (item is Episode episode)
 55        {
 056            if (episode.IndexNumber.HasValue)
 57            {
 058                name = string.Format(
 059                    CultureInfo.InvariantCulture,
 060                    "Ep{0} - {1}",
 061                    episode.IndexNumber.Value,
 062                    name);
 63            }
 64
 065            if (episode.ParentIndexNumber.HasValue)
 66            {
 067                name = string.Format(
 068                    CultureInfo.InvariantCulture,
 069                    "S{0}, {1}",
 070                    episode.ParentIndexNumber.Value,
 071                    name);
 72            }
 73        }
 74
 075        if (item is IHasSeries hasSeries)
 76        {
 077            name = hasSeries.SeriesName + " - " + name;
 78        }
 79
 080        if (item is IHasAlbumArtist hasAlbumArtist)
 81        {
 082            var artists = hasAlbumArtist.AlbumArtists;
 83
 084            if (artists.Count > 0)
 85            {
 086                name = artists[0] + " - " + name;
 87            }
 88        }
 089        else if (item is IHasArtist hasArtist)
 90        {
 091            var artists = hasArtist.Artists;
 92
 093            if (artists.Count > 0)
 94            {
 095                name = artists[0] + " - " + name;
 96            }
 97        }
 98
 099        return name;
 100    }
 101}