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