| | | 1 | | using System.Linq; |
| | | 2 | | using System.Threading; |
| | | 3 | | using Jellyfin.Data.Enums; |
| | | 4 | | using MediaBrowser.Controller.Entities; |
| | | 5 | | using MediaBrowser.Controller.Entities.Audio; |
| | | 6 | | using MediaBrowser.Controller.Persistence; |
| | | 7 | | using MediaBrowser.Model.Entities; |
| | | 8 | | using Microsoft.Extensions.Logging; |
| | | 9 | | |
| | | 10 | | namespace Jellyfin.Server.Migrations.Routines |
| | | 11 | | { |
| | | 12 | | /// <summary> |
| | | 13 | | /// Fixes the data column of audio types to be deserializable. |
| | | 14 | | /// </summary> |
| | | 15 | | #pragma warning disable CS0618 // Type or member is obsolete |
| | | 16 | | [JellyfinMigration("2025-04-20T18:00:00", nameof(FixAudioData), "CF6FABC2-9FBE-4933-84A5-FFE52EF22A58")] |
| | | 17 | | [JellyfinMigrationBackup(LegacyLibraryDb = true)] |
| | | 18 | | internal class FixAudioData : IMigrationRoutine |
| | | 19 | | #pragma warning restore CS0618 // Type or member is obsolete |
| | | 20 | | { |
| | | 21 | | private readonly ILogger<FixAudioData> _logger; |
| | | 22 | | private readonly IItemRepository _itemRepository; |
| | | 23 | | private readonly IItemCountService _countService; |
| | | 24 | | private readonly IItemPersistenceService _persistenceService; |
| | | 25 | | |
| | | 26 | | public FixAudioData( |
| | | 27 | | ILoggerFactory loggerFactory, |
| | | 28 | | IItemRepository itemRepository, |
| | | 29 | | IItemCountService countService, |
| | | 30 | | IItemPersistenceService persistenceService) |
| | | 31 | | { |
| | 0 | 32 | | _itemRepository = itemRepository; |
| | 0 | 33 | | _countService = countService; |
| | 0 | 34 | | _persistenceService = persistenceService; |
| | 0 | 35 | | _logger = loggerFactory.CreateLogger<FixAudioData>(); |
| | 0 | 36 | | } |
| | | 37 | | |
| | | 38 | | /// <inheritdoc/> |
| | | 39 | | public void Perform() |
| | | 40 | | { |
| | 0 | 41 | | _logger.LogInformation("Backfilling audio lyrics data to database."); |
| | 0 | 42 | | var startIndex = 0; |
| | 0 | 43 | | var records = _countService.GetCount(new InternalItemsQuery |
| | 0 | 44 | | { |
| | 0 | 45 | | IncludeItemTypes = [BaseItemKind.Audio], |
| | 0 | 46 | | }); |
| | | 47 | | |
| | 0 | 48 | | while (startIndex < records) |
| | | 49 | | { |
| | 0 | 50 | | var results = _itemRepository.GetItemList(new InternalItemsQuery |
| | 0 | 51 | | { |
| | 0 | 52 | | IncludeItemTypes = [BaseItemKind.Audio], |
| | 0 | 53 | | StartIndex = startIndex, |
| | 0 | 54 | | Limit = 5000, |
| | 0 | 55 | | SkipDeserialization = true |
| | 0 | 56 | | }) |
| | 0 | 57 | | .Cast<Audio>() |
| | 0 | 58 | | .ToList(); |
| | | 59 | | |
| | 0 | 60 | | foreach (var audio in results) |
| | | 61 | | { |
| | 0 | 62 | | var lyricMediaStreams = audio.GetMediaStreams().Where(s => s.Type == MediaStreamType.Lyric).Select(s |
| | 0 | 63 | | if (lyricMediaStreams.Count > 0) |
| | | 64 | | { |
| | 0 | 65 | | audio.HasLyrics = true; |
| | 0 | 66 | | audio.LyricFiles = lyricMediaStreams; |
| | | 67 | | } |
| | | 68 | | } |
| | | 69 | | |
| | 0 | 70 | | _persistenceService.SaveItems(results, CancellationToken.None); |
| | 0 | 71 | | startIndex += results.Count; |
| | 0 | 72 | | _logger.LogInformation("Backfilled data for {UpdatedRecords} of {TotalRecords} audio records", startInde |
| | | 73 | | } |
| | 0 | 74 | | } |
| | | 75 | | } |
| | | 76 | | } |