< Summary - Jellyfin

Information
Class: MediaBrowser.LocalMetadata.Parsers.BaseItemXmlParser<T>
Assembly: MediaBrowser.LocalMetadata
File(s): /srv/git/jellyfin/MediaBrowser.LocalMetadata/Parsers/BaseItemXmlParser.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 317
Coverable lines: 317
Total lines: 872
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 376
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%
Fetch(...)0%620%
Fetch(...)0%4260%
FetchDataFromXmlNode(...)0%710222660%
FetchFromSharesNode(...)0%156120%
FetchFromTaglinesNode(...)0%110100%
FetchFromGenresNode(...)0%110100%
FetchFromTagsNode(...)0%110100%
FetchDataFromPersonsNode(...)0%156120%
FetchDataFromTrailersNode(...)0%110100%
FetchFromStudiosNode(...)0%110100%
GetLinkedChild(...)0%210140%
GetShare(...)0%210140%

File(s)

/srv/git/jellyfin/MediaBrowser.LocalMetadata/Parsers/BaseItemXmlParser.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Globalization;
 4using System.IO;
 5using System.Linq;
 6using System.Text;
 7using System.Threading;
 8using System.Xml;
 9using Jellyfin.Data.Enums;
 10using Jellyfin.Extensions;
 11using MediaBrowser.Controller.Entities;
 12using MediaBrowser.Controller.Extensions;
 13using MediaBrowser.Controller.Playlists;
 14using MediaBrowser.Controller.Providers;
 15using MediaBrowser.Model.Entities;
 16using Microsoft.Extensions.Logging;
 17
 18namespace MediaBrowser.LocalMetadata.Parsers
 19{
 20    /// <summary>
 21    /// Provides a base class for parsing metadata xml.
 22    /// </summary>
 23    /// <typeparam name="T">Type of item xml parser.</typeparam>
 24    public class BaseItemXmlParser<T>
 25        where T : BaseItem
 26    {
 27        private Dictionary<string, string>? _validProviderIds;
 28
 29        /// <summary>
 30        /// Initializes a new instance of the <see cref="BaseItemXmlParser{T}" /> class.
 31        /// </summary>
 32        /// <param name="logger">Instance of the <see cref="ILogger{BaseItemXmlParser}"/> interface.</param>
 33        /// <param name="providerManager">Instance of the <see cref="IProviderManager"/> interface.</param>
 34        public BaseItemXmlParser(ILogger<BaseItemXmlParser<T>> logger, IProviderManager providerManager)
 35        {
 036            Logger = logger;
 037            ProviderManager = providerManager;
 038        }
 39
 40        /// <summary>
 41        /// Gets the logger.
 42        /// </summary>
 43        protected ILogger<BaseItemXmlParser<T>> Logger { get; private set; }
 44
 45        /// <summary>
 46        /// Gets the provider manager.
 47        /// </summary>
 48        protected IProviderManager ProviderManager { get; private set; }
 49
 50        /// <summary>
 51        /// Fetches metadata for an item from one xml file.
 52        /// </summary>
 53        /// <param name="item">The item.</param>
 54        /// <param name="metadataFile">The metadata file.</param>
 55        /// <param name="cancellationToken">The cancellation token.</param>
 56        /// <exception cref="ArgumentNullException">Item is null.</exception>
 57        public void Fetch(MetadataResult<T> item, string metadataFile, CancellationToken cancellationToken)
 58        {
 059            ArgumentNullException.ThrowIfNull(item);
 060            ArgumentException.ThrowIfNullOrEmpty(metadataFile);
 61
 062            var settings = new XmlReaderSettings
 063            {
 064                ValidationType = ValidationType.None,
 065                CheckCharacters = false,
 066                IgnoreProcessingInstructions = true,
 067                IgnoreComments = true
 068            };
 69
 070            _validProviderIds = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
 71
 072            var idInfos = ProviderManager.GetExternalIdInfos(item.Item);
 73
 074            foreach (var info in idInfos)
 75            {
 076                var id = info.Key + "Id";
 077                _validProviderIds.TryAdd(id, info.Key);
 78            }
 79
 80            // Additional Mappings
 081            _validProviderIds.Add("IMDB", "Imdb");
 82
 83            // Fetch(item, metadataFile, settings, Encoding.GetEncoding("ISO-8859-1"), cancellationToken);
 084            Fetch(item, metadataFile, settings, Encoding.UTF8, cancellationToken);
 085        }
 86
 87        /// <summary>
 88        /// Fetches the specified item.
 89        /// </summary>
 90        /// <param name="item">The item.</param>
 91        /// <param name="metadataFile">The metadata file.</param>
 92        /// <param name="settings">The settings.</param>
 93        /// <param name="encoding">The encoding.</param>
 94        /// <param name="cancellationToken">The cancellation token.</param>
 95        private void Fetch(MetadataResult<T> item, string metadataFile, XmlReaderSettings settings, Encoding encoding, C
 96        {
 097            item.ResetPeople();
 98
 099            using var fileStream = File.OpenRead(metadataFile);
 0100            using var streamReader = new StreamReader(fileStream, encoding);
 0101            using var reader = XmlReader.Create(streamReader, settings);
 0102            reader.MoveToContent();
 0103            reader.Read();
 104
 105            // Loop through each element
 0106            while (!reader.EOF && reader.ReadState == ReadState.Interactive)
 107            {
 0108                cancellationToken.ThrowIfCancellationRequested();
 109
 0110                if (reader.NodeType == XmlNodeType.Element)
 111                {
 0112                    FetchDataFromXmlNode(reader, item);
 113                }
 114                else
 115                {
 0116                    reader.Read();
 117                }
 118            }
 0119        }
 120
 121        /// <summary>
 122        /// Fetches metadata from one Xml Element.
 123        /// </summary>
 124        /// <param name="reader">The reader.</param>
 125        /// <param name="itemResult">The item result.</param>
 126        protected virtual void FetchDataFromXmlNode(XmlReader reader, MetadataResult<T> itemResult)
 127        {
 0128            var item = itemResult.Item;
 129
 0130            switch (reader.Name)
 131            {
 132                case "Added":
 0133                    if (reader.TryReadDateTime(out var dateCreated))
 134                    {
 0135                        item.DateCreated = dateCreated;
 136                    }
 137
 0138                    break;
 139                case "OriginalTitle":
 0140                    item.OriginalTitle = reader.ReadNormalizedString();
 0141                    break;
 142                case "LocalTitle":
 0143                    item.Name = reader.ReadNormalizedString();
 0144                    break;
 145                case "CriticRating":
 146                {
 0147                    var text = reader.ReadElementContentAsString();
 148
 0149                    if (float.TryParse(text, CultureInfo.InvariantCulture, out var value))
 150                    {
 0151                        item.CriticRating = value;
 152                    }
 153
 0154                    break;
 155                }
 156
 157                case "SortTitle":
 0158                    item.ForcedSortName = reader.ReadNormalizedString();
 0159                    break;
 160                case "Overview":
 161                case "Description":
 0162                    item.Overview = reader.ReadNormalizedString();
 0163                    break;
 164                case "Language":
 0165                    item.PreferredMetadataLanguage = reader.ReadNormalizedString();
 0166                    break;
 167                case "CountryCode":
 0168                    item.PreferredMetadataCountryCode = reader.ReadNormalizedString();
 0169                    break;
 170                case "PlaceOfBirth":
 0171                    var placeOfBirth = reader.ReadNormalizedString();
 0172                    if (!string.IsNullOrEmpty(placeOfBirth) && item is Person person)
 173                    {
 0174                        person.ProductionLocations = new[] { placeOfBirth };
 175                    }
 176
 0177                    break;
 178                case "LockedFields":
 179                {
 0180                    var val = reader.ReadElementContentAsString();
 181
 0182                    if (!string.IsNullOrWhiteSpace(val))
 183                    {
 0184                        item.LockedFields = val.Split('|').Select(i =>
 0185                        {
 0186                            if (Enum.TryParse(i, true, out MetadataField field))
 0187                            {
 0188                                return (MetadataField?)field;
 0189                            }
 0190
 0191                            return null;
 0192                        }).Where(i => i.HasValue).Select(i => i!.Value).ToArray();
 193                    }
 194
 0195                    break;
 196                }
 197
 198                case "TagLines":
 199                {
 0200                    if (!reader.IsEmptyElement)
 201                    {
 0202                        using (var subtree = reader.ReadSubtree())
 203                        {
 0204                            FetchFromTaglinesNode(subtree, item);
 0205                        }
 206                    }
 207                    else
 208                    {
 0209                        reader.Read();
 210                    }
 211
 0212                    break;
 213                }
 214
 215                case "Countries":
 216                {
 0217                    if (!reader.IsEmptyElement)
 218                    {
 0219                        reader.Skip();
 220                    }
 221                    else
 222                    {
 0223                        reader.Read();
 224                    }
 225
 0226                    break;
 227                }
 228
 229                case "ContentRating":
 230                case "MPAARating":
 0231                    item.OfficialRating = reader.ReadNormalizedString();
 0232                    break;
 233                case "CustomRating":
 0234                    item.CustomRating = reader.ReadNormalizedString();
 0235                    break;
 236                case "RunningTime":
 0237                    var runtimeText = reader.ReadNormalizedString();
 0238                    if (!string.IsNullOrEmpty(runtimeText))
 239                    {
 0240                        if (int.TryParse(runtimeText.AsSpan().LeftPart(' '), NumberStyles.Integer, CultureInfo.Invariant
 241                        {
 0242                            item.RunTimeTicks = TimeSpan.FromMinutes(runtime).Ticks;
 243                        }
 244                    }
 245
 0246                    break;
 247                case "AspectRatio":
 0248                    var aspectRatio = reader.ReadNormalizedString();
 0249                    if (!string.IsNullOrEmpty(aspectRatio) && item is IHasAspectRatio hasAspectRatio)
 250                    {
 0251                        hasAspectRatio.AspectRatio = aspectRatio;
 252                    }
 253
 0254                    break;
 255                case "LockData":
 0256                    item.IsLocked = string.Equals(reader.ReadNormalizedString(), "true", StringComparison.OrdinalIgnoreC
 0257                    break;
 258                case "Network":
 0259                    foreach (var name in reader.GetStringArray())
 260                    {
 0261                        item.AddStudio(name);
 262                    }
 263
 264                    break;
 265                case "Director":
 0266                    foreach (var director in reader.GetPersonArray(PersonKind.Director))
 267                    {
 0268                        itemResult.AddPerson(director);
 269                    }
 270
 271                    break;
 272                case "Writer":
 0273                    foreach (var writer in reader.GetPersonArray(PersonKind.Writer))
 274                    {
 0275                        itemResult.AddPerson(writer);
 276                    }
 277
 278                    break;
 279                case "Actors":
 0280                    foreach (var actor in reader.GetPersonArray(PersonKind.Actor))
 281                    {
 0282                        itemResult.AddPerson(actor);
 283                    }
 284
 285                    break;
 286                case "GuestStars":
 0287                    foreach (var guestStar in reader.GetPersonArray(PersonKind.GuestStar))
 288                    {
 0289                        itemResult.AddPerson(guestStar);
 290                    }
 291
 292                    break;
 293                case "Trailer":
 0294                    var trailer = reader.ReadNormalizedString();
 0295                    if (!string.IsNullOrEmpty(trailer))
 296                    {
 0297                        item.AddTrailerUrl(trailer);
 298                    }
 299
 0300                    break;
 301                case "DisplayOrder":
 0302                    var displayOrder = reader.ReadNormalizedString();
 0303                    if (!string.IsNullOrEmpty(displayOrder) && item is IHasDisplayOrder hasDisplayOrder)
 304                    {
 0305                        hasDisplayOrder.DisplayOrder = displayOrder;
 306                    }
 307
 0308                    break;
 309                case "Trailers":
 310                {
 0311                    if (!reader.IsEmptyElement)
 312                    {
 0313                        using var subtree = reader.ReadSubtree();
 0314                        FetchDataFromTrailersNode(subtree, item);
 315                    }
 316                    else
 317                    {
 0318                        reader.Read();
 319                    }
 320
 0321                    break;
 322                }
 323
 324                case "ProductionYear":
 0325                    if (reader.TryReadInt(out var productionYear) && productionYear > 1850)
 326                    {
 0327                        item.ProductionYear = productionYear;
 328                    }
 329
 0330                    break;
 331                case "Rating":
 332                case "IMDBrating":
 333                {
 0334                    var rating = reader.ReadNormalizedString();
 335
 0336                    if (!string.IsNullOrEmpty(rating))
 337                    {
 338                        // All external meta is saving this as '.' for decimal I believe...but just to be sure
 0339                        if (float.TryParse(rating.Replace(',', '.'), NumberStyles.AllowDecimalPoint, CultureInfo.Invaria
 340                        {
 0341                            item.CommunityRating = val;
 342                        }
 343                    }
 344
 0345                    break;
 346                }
 347
 348                case "BirthDate":
 349                case "PremiereDate":
 350                case "FirstAired":
 0351                    if (reader.TryReadDateTimeExact("yyyy-MM-dd", out var firstAired))
 352                    {
 0353                        item.PremiereDate = firstAired;
 0354                        item.ProductionYear = firstAired.Year;
 355                    }
 356
 0357                    break;
 358                case "DeathDate":
 359                case "EndDate":
 0360                    if (reader.TryReadDateTimeExact("yyyy-MM-dd", out var endDate))
 361                    {
 0362                        item.EndDate = endDate;
 363                    }
 364
 0365                    break;
 366                case "CollectionNumber":
 0367                    var tmdbCollection = reader.ReadNormalizedString();
 0368                    item.TrySetProviderId(MetadataProvider.TmdbCollection, tmdbCollection);
 369
 0370                    break;
 371
 372                case "Genres":
 373                {
 0374                    if (!reader.IsEmptyElement)
 375                    {
 0376                        using var subtree = reader.ReadSubtree();
 0377                        FetchFromGenresNode(subtree, item);
 378                    }
 379                    else
 380                    {
 0381                        reader.Read();
 382                    }
 383
 0384                    break;
 385                }
 386
 387                case "Tags":
 388                {
 0389                    if (!reader.IsEmptyElement)
 390                    {
 0391                        using var subtree = reader.ReadSubtree();
 0392                        FetchFromTagsNode(subtree, item);
 393                    }
 394                    else
 395                    {
 0396                        reader.Read();
 397                    }
 398
 0399                    break;
 400                }
 401
 402                case "Persons":
 403                {
 0404                    if (!reader.IsEmptyElement)
 405                    {
 0406                        using var subtree = reader.ReadSubtree();
 0407                        FetchDataFromPersonsNode(subtree, itemResult);
 408                    }
 409                    else
 410                    {
 0411                        reader.Read();
 412                    }
 413
 0414                    break;
 415                }
 416
 417                case "Studios":
 418                {
 0419                    if (!reader.IsEmptyElement)
 420                    {
 0421                        using var subtree = reader.ReadSubtree();
 0422                        FetchFromStudiosNode(subtree, item);
 423                    }
 424                    else
 425                    {
 0426                        reader.Read();
 427                    }
 428
 0429                    break;
 430                }
 431
 432                case "Shares":
 433                {
 0434                    if (!reader.IsEmptyElement)
 435                    {
 0436                        using var subtree = reader.ReadSubtree();
 0437                        if (item is IHasShares hasShares)
 438                        {
 0439                            FetchFromSharesNode(subtree, hasShares);
 440                        }
 441                    }
 442                    else
 443                    {
 0444                        reader.Read();
 445                    }
 446
 0447                    break;
 448                }
 449
 450                case "OwnerUserId":
 451                {
 0452                    var val = reader.ReadNormalizedString();
 453
 0454                    if (Guid.TryParse(val, out var guid) && !guid.Equals(Guid.Empty))
 455                    {
 0456                        if (item is Playlist playlist)
 457                        {
 0458                            playlist.OwnerUserId = guid;
 459                        }
 460                    }
 461
 0462                    break;
 463                }
 464
 465                case "Format3D":
 466                {
 0467                    var val = reader.ReadNormalizedString();
 468
 0469                    if (item is Video video)
 470                    {
 0471                        if (string.Equals("HSBS", val, StringComparison.OrdinalIgnoreCase))
 472                        {
 0473                            video.Video3DFormat = Video3DFormat.HalfSideBySide;
 474                        }
 0475                        else if (string.Equals("HTAB", val, StringComparison.OrdinalIgnoreCase))
 476                        {
 0477                            video.Video3DFormat = Video3DFormat.HalfTopAndBottom;
 478                        }
 0479                        else if (string.Equals("FTAB", val, StringComparison.OrdinalIgnoreCase))
 480                        {
 0481                            video.Video3DFormat = Video3DFormat.FullTopAndBottom;
 482                        }
 0483                        else if (string.Equals("FSBS", val, StringComparison.OrdinalIgnoreCase))
 484                        {
 0485                            video.Video3DFormat = Video3DFormat.FullSideBySide;
 486                        }
 0487                        else if (string.Equals("MVC", val, StringComparison.OrdinalIgnoreCase))
 488                        {
 0489                            video.Video3DFormat = Video3DFormat.MVC;
 490                        }
 491                    }
 492
 0493                    break;
 494                }
 495
 496                default:
 497                {
 0498                    string readerName = reader.Name;
 0499                    if (_validProviderIds!.TryGetValue(readerName, out string? providerIdValue))
 500                    {
 0501                        var id = reader.ReadNormalizedString();
 0502                        item.TrySetProviderId(providerIdValue, id);
 503                    }
 504                    else
 505                    {
 0506                        reader.Skip();
 507                    }
 508
 509                    break;
 510                }
 511            }
 0512        }
 513
 514        private void FetchFromSharesNode(XmlReader reader, IHasShares item)
 515        {
 0516            var list = new List<PlaylistUserPermissions>();
 517
 0518            reader.MoveToContent();
 0519            reader.Read();
 520
 521            // Loop through each element
 0522            while (!reader.EOF && reader.ReadState == ReadState.Interactive)
 523            {
 0524                if (reader.NodeType == XmlNodeType.Element)
 525                {
 0526                    switch (reader.Name)
 527                    {
 528                        case "Share":
 529                        {
 0530                            if (reader.IsEmptyElement)
 531                            {
 0532                                reader.Read();
 0533                                continue;
 534                            }
 535
 0536                            using (var subReader = reader.ReadSubtree())
 537                            {
 0538                                var child = GetShare(subReader);
 539
 0540                                if (child is not null)
 541                                {
 0542                                    list.Add(child);
 543                                }
 0544                            }
 545
 546                            break;
 547                        }
 548
 549                        default:
 550                        {
 0551                            reader.Skip();
 0552                            break;
 553                        }
 554                    }
 555                }
 556                else
 557                {
 0558                    reader.Read();
 559                }
 560            }
 561
 0562            item.Shares = [.. list];
 0563        }
 564
 565        /// <summary>
 566        /// Fetches from taglines node.
 567        /// </summary>
 568        /// <param name="reader">The reader.</param>
 569        /// <param name="item">The item.</param>
 570        private void FetchFromTaglinesNode(XmlReader reader, T item)
 571        {
 0572            reader.MoveToContent();
 0573            reader.Read();
 574
 575            // Loop through each element
 0576            while (!reader.EOF && reader.ReadState == ReadState.Interactive)
 577            {
 0578                if (reader.NodeType == XmlNodeType.Element)
 579                {
 0580                    switch (reader.Name)
 581                    {
 582                        case "Tagline":
 0583                            var val = reader.ReadNormalizedString();
 0584                            if (!string.IsNullOrEmpty(val))
 585                            {
 0586                                item.Tagline = val;
 587                            }
 588
 0589                            break;
 590                        default:
 0591                            reader.Skip();
 0592                            break;
 593                    }
 594                }
 595                else
 596                {
 0597                    reader.Read();
 598                }
 599            }
 0600        }
 601
 602        /// <summary>
 603        /// Fetches from genres node.
 604        /// </summary>
 605        /// <param name="reader">The reader.</param>
 606        /// <param name="item">The item.</param>
 607        private void FetchFromGenresNode(XmlReader reader, T item)
 608        {
 0609            reader.MoveToContent();
 0610            reader.Read();
 611
 612            // Loop through each element
 0613            while (!reader.EOF && reader.ReadState == ReadState.Interactive)
 614            {
 0615                if (reader.NodeType == XmlNodeType.Element)
 616                {
 0617                    switch (reader.Name)
 618                    {
 619                        case "Genre":
 0620                            var genre = reader.ReadNormalizedString();
 0621                            if (!string.IsNullOrEmpty(genre))
 622                            {
 0623                                item.AddGenre(genre);
 624                            }
 625
 0626                            break;
 627                        default:
 0628                            reader.Skip();
 0629                            break;
 630                    }
 631                }
 632                else
 633                {
 0634                    reader.Read();
 635                }
 636            }
 0637        }
 638
 639        private void FetchFromTagsNode(XmlReader reader, BaseItem item)
 640        {
 0641            reader.MoveToContent();
 0642            reader.Read();
 643
 0644            var tags = new List<string>();
 645
 646            // Loop through each element
 0647            while (!reader.EOF && reader.ReadState == ReadState.Interactive)
 648            {
 0649                if (reader.NodeType == XmlNodeType.Element)
 650                {
 0651                    switch (reader.Name)
 652                    {
 653                        case "Tag":
 0654                            var tag = reader.ReadNormalizedString();
 0655                            if (!string.IsNullOrEmpty(tag))
 656                            {
 0657                                tags.Add(tag);
 658                            }
 659
 0660                            break;
 661                        default:
 0662                            reader.Skip();
 0663                            break;
 664                    }
 665                }
 666                else
 667                {
 0668                    reader.Read();
 669                }
 670            }
 671
 0672            item.Tags = tags.Distinct(StringComparer.Ordinal).ToArray();
 0673        }
 674
 675        /// <summary>
 676        /// Fetches the data from persons node.
 677        /// </summary>
 678        /// <param name="reader">The reader.</param>
 679        /// <param name="item">The item.</param>
 680        private void FetchDataFromPersonsNode(XmlReader reader, MetadataResult<T> item)
 681        {
 0682            reader.MoveToContent();
 0683            reader.Read();
 684
 685            // Loop through each element
 0686            while (!reader.EOF && reader.ReadState == ReadState.Interactive)
 687            {
 0688                if (reader.NodeType == XmlNodeType.Element)
 689                {
 0690                    switch (reader.Name)
 691                    {
 692                        case "Person":
 693                        case "Actor":
 0694                            var person = reader.GetPersonFromXmlNode();
 0695                            if (person is not null)
 696                            {
 0697                                item.AddPerson(person);
 698                            }
 699
 0700                            break;
 701                        default:
 0702                            reader.Skip();
 0703                            break;
 704                    }
 705                }
 706                else
 707                {
 0708                    reader.Read();
 709                }
 710            }
 0711        }
 712
 713        private void FetchDataFromTrailersNode(XmlReader reader, T item)
 714        {
 0715            reader.MoveToContent();
 0716            reader.Read();
 717
 718            // Loop through each element
 0719            while (!reader.EOF && reader.ReadState == ReadState.Interactive)
 720            {
 0721                if (reader.NodeType == XmlNodeType.Element)
 722                {
 0723                    switch (reader.Name)
 724                    {
 725                        case "Trailer":
 0726                            var trailer = reader.ReadNormalizedString();
 0727                            if (!string.IsNullOrEmpty(trailer))
 728                            {
 0729                                item.AddTrailerUrl(trailer);
 730                            }
 731
 0732                            break;
 733                        default:
 0734                            reader.Skip();
 0735                            break;
 736                    }
 737                }
 738                else
 739                {
 0740                    reader.Read();
 741                }
 742            }
 0743        }
 744
 745        /// <summary>
 746        /// Fetches from studios node.
 747        /// </summary>
 748        /// <param name="reader">The reader.</param>
 749        /// <param name="item">The item.</param>
 750        private void FetchFromStudiosNode(XmlReader reader, T item)
 751        {
 0752            reader.MoveToContent();
 0753            reader.Read();
 754
 755            // Loop through each element
 0756            while (!reader.EOF && reader.ReadState == ReadState.Interactive)
 757            {
 0758                if (reader.NodeType == XmlNodeType.Element)
 759                {
 0760                    switch (reader.Name)
 761                    {
 762                        case "Studio":
 0763                            var studio = reader.ReadNormalizedString();
 0764                            if (!string.IsNullOrEmpty(studio))
 765                            {
 0766                                item.AddStudio(studio);
 767                            }
 768
 0769                            break;
 770                        default:
 0771                            reader.Skip();
 0772                            break;
 773                    }
 774                }
 775                else
 776                {
 0777                    reader.Read();
 778                }
 779            }
 0780        }
 781
 782        /// <summary>
 783        /// Get linked child.
 784        /// </summary>
 785        /// <param name="reader">The xml reader.</param>
 786        /// <returns>The linked child.</returns>
 787        protected LinkedChild? GetLinkedChild(XmlReader reader)
 788        {
 0789            var linkedItem = new LinkedChild { Type = LinkedChildType.Manual };
 790
 0791            reader.MoveToContent();
 0792            reader.Read();
 793
 794            // Loop through each element
 0795            while (!reader.EOF && reader.ReadState == ReadState.Interactive)
 796            {
 0797                if (reader.NodeType == XmlNodeType.Element)
 798                {
 0799                    switch (reader.Name)
 800                    {
 801                        case "Path":
 0802                            linkedItem.Path = reader.ReadNormalizedString();
 0803                            break;
 804                        case "ItemId":
 0805                            linkedItem.LibraryItemId = reader.ReadNormalizedString();
 0806                            break;
 807                        default:
 0808                            reader.Skip();
 0809                            break;
 810                    }
 811                }
 812                else
 813                {
 0814                    reader.Read();
 815                }
 816            }
 817
 818            // This is valid
 0819            if (!string.IsNullOrWhiteSpace(linkedItem.Path) || !string.IsNullOrWhiteSpace(linkedItem.LibraryItemId))
 820            {
 0821                return linkedItem;
 822            }
 823
 0824            return null;
 825        }
 826
 827        /// <summary>
 828        /// Get share.
 829        /// </summary>
 830        /// <param name="reader">The xml reader.</param>
 831        /// <returns>The share.</returns>
 832        protected PlaylistUserPermissions? GetShare(XmlReader reader)
 833        {
 0834            reader.MoveToContent();
 0835            reader.Read();
 0836            string? userId = null;
 0837            var canEdit = false;
 838
 839            // Loop through each element
 0840            while (!reader.EOF && reader.ReadState == ReadState.Interactive)
 841            {
 0842                if (reader.NodeType == XmlNodeType.Element)
 843                {
 0844                    switch (reader.Name)
 845                    {
 846                        case "UserId":
 0847                            userId = reader.ReadNormalizedString();
 0848                            break;
 849                        case "CanEdit":
 0850                            canEdit = string.Equals(reader.ReadNormalizedString(), "true", StringComparison.OrdinalIgnor
 0851                            break;
 852                        default:
 0853                            reader.Skip();
 0854                            break;
 855                    }
 856                }
 857                else
 858                {
 0859                    reader.Read();
 860                }
 861            }
 862
 863            // This is valid
 0864            if (!string.IsNullOrEmpty(userId) && Guid.TryParse(userId, out var guid))
 865            {
 0866                return new PlaylistUserPermissions(guid, canEdit);
 867            }
 868
 0869            return null;
 870        }
 871    }
 872}