| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using System.Globalization; |
| | 4 | | using System.IO; |
| | 5 | | using System.Linq; |
| | 6 | | using System.Text; |
| | 7 | | using System.Threading; |
| | 8 | | using System.Xml; |
| | 9 | | using Jellyfin.Data.Enums; |
| | 10 | | using Jellyfin.Extensions; |
| | 11 | | using MediaBrowser.Controller.Entities; |
| | 12 | | using MediaBrowser.Controller.Extensions; |
| | 13 | | using MediaBrowser.Controller.Playlists; |
| | 14 | | using MediaBrowser.Controller.Providers; |
| | 15 | | using MediaBrowser.Model.Entities; |
| | 16 | | using Microsoft.Extensions.Logging; |
| | 17 | |
|
| | 18 | | namespace 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 | | { |
| 0 | 36 | | Logger = logger; |
| 0 | 37 | | ProviderManager = providerManager; |
| 0 | 38 | | } |
| | 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 | | { |
| 0 | 59 | | ArgumentNullException.ThrowIfNull(item); |
| 0 | 60 | | ArgumentException.ThrowIfNullOrEmpty(metadataFile); |
| | 61 | |
|
| 0 | 62 | | var settings = new XmlReaderSettings |
| 0 | 63 | | { |
| 0 | 64 | | ValidationType = ValidationType.None, |
| 0 | 65 | | CheckCharacters = false, |
| 0 | 66 | | IgnoreProcessingInstructions = true, |
| 0 | 67 | | IgnoreComments = true |
| 0 | 68 | | }; |
| | 69 | |
|
| 0 | 70 | | _validProviderIds = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); |
| | 71 | |
|
| 0 | 72 | | var idInfos = ProviderManager.GetExternalIdInfos(item.Item); |
| | 73 | |
|
| 0 | 74 | | foreach (var info in idInfos) |
| | 75 | | { |
| 0 | 76 | | var id = info.Key + "Id"; |
| 0 | 77 | | _validProviderIds.TryAdd(id, info.Key); |
| | 78 | | } |
| | 79 | |
|
| | 80 | | // Additional Mappings |
| 0 | 81 | | _validProviderIds.Add("IMDB", "Imdb"); |
| | 82 | |
|
| | 83 | | // Fetch(item, metadataFile, settings, Encoding.GetEncoding("ISO-8859-1"), cancellationToken); |
| 0 | 84 | | Fetch(item, metadataFile, settings, Encoding.UTF8, cancellationToken); |
| 0 | 85 | | } |
| | 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 | | { |
| 0 | 97 | | item.ResetPeople(); |
| | 98 | |
|
| 0 | 99 | | using var fileStream = File.OpenRead(metadataFile); |
| 0 | 100 | | using var streamReader = new StreamReader(fileStream, encoding); |
| 0 | 101 | | using var reader = XmlReader.Create(streamReader, settings); |
| 0 | 102 | | reader.MoveToContent(); |
| 0 | 103 | | reader.Read(); |
| | 104 | |
|
| | 105 | | // Loop through each element |
| 0 | 106 | | while (!reader.EOF && reader.ReadState == ReadState.Interactive) |
| | 107 | | { |
| 0 | 108 | | cancellationToken.ThrowIfCancellationRequested(); |
| | 109 | |
|
| 0 | 110 | | if (reader.NodeType == XmlNodeType.Element) |
| | 111 | | { |
| 0 | 112 | | FetchDataFromXmlNode(reader, item); |
| | 113 | | } |
| | 114 | | else |
| | 115 | | { |
| 0 | 116 | | reader.Read(); |
| | 117 | | } |
| | 118 | | } |
| 0 | 119 | | } |
| | 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 | | { |
| 0 | 128 | | var item = itemResult.Item; |
| | 129 | |
|
| 0 | 130 | | switch (reader.Name) |
| | 131 | | { |
| | 132 | | case "Added": |
| 0 | 133 | | if (reader.TryReadDateTime(out var dateCreated)) |
| | 134 | | { |
| 0 | 135 | | item.DateCreated = dateCreated; |
| | 136 | | } |
| | 137 | |
|
| 0 | 138 | | break; |
| | 139 | | case "OriginalTitle": |
| 0 | 140 | | item.OriginalTitle = reader.ReadNormalizedString(); |
| 0 | 141 | | break; |
| | 142 | | case "LocalTitle": |
| 0 | 143 | | item.Name = reader.ReadNormalizedString(); |
| 0 | 144 | | break; |
| | 145 | | case "CriticRating": |
| | 146 | | { |
| 0 | 147 | | var text = reader.ReadElementContentAsString(); |
| | 148 | |
|
| 0 | 149 | | if (float.TryParse(text, CultureInfo.InvariantCulture, out var value)) |
| | 150 | | { |
| 0 | 151 | | item.CriticRating = value; |
| | 152 | | } |
| | 153 | |
|
| 0 | 154 | | break; |
| | 155 | | } |
| | 156 | |
|
| | 157 | | case "SortTitle": |
| 0 | 158 | | item.ForcedSortName = reader.ReadNormalizedString(); |
| 0 | 159 | | break; |
| | 160 | | case "Overview": |
| | 161 | | case "Description": |
| 0 | 162 | | item.Overview = reader.ReadNormalizedString(); |
| 0 | 163 | | break; |
| | 164 | | case "Language": |
| 0 | 165 | | item.PreferredMetadataLanguage = reader.ReadNormalizedString(); |
| 0 | 166 | | break; |
| | 167 | | case "CountryCode": |
| 0 | 168 | | item.PreferredMetadataCountryCode = reader.ReadNormalizedString(); |
| 0 | 169 | | break; |
| | 170 | | case "PlaceOfBirth": |
| 0 | 171 | | var placeOfBirth = reader.ReadNormalizedString(); |
| 0 | 172 | | if (!string.IsNullOrEmpty(placeOfBirth) && item is Person person) |
| | 173 | | { |
| 0 | 174 | | person.ProductionLocations = new[] { placeOfBirth }; |
| | 175 | | } |
| | 176 | |
|
| 0 | 177 | | break; |
| | 178 | | case "LockedFields": |
| | 179 | | { |
| 0 | 180 | | var val = reader.ReadElementContentAsString(); |
| | 181 | |
|
| 0 | 182 | | if (!string.IsNullOrWhiteSpace(val)) |
| | 183 | | { |
| 0 | 184 | | item.LockedFields = val.Split('|').Select(i => |
| 0 | 185 | | { |
| 0 | 186 | | if (Enum.TryParse(i, true, out MetadataField field)) |
| 0 | 187 | | { |
| 0 | 188 | | return (MetadataField?)field; |
| 0 | 189 | | } |
| 0 | 190 | |
|
| 0 | 191 | | return null; |
| 0 | 192 | | }).Where(i => i.HasValue).Select(i => i!.Value).ToArray(); |
| | 193 | | } |
| | 194 | |
|
| 0 | 195 | | break; |
| | 196 | | } |
| | 197 | |
|
| | 198 | | case "TagLines": |
| | 199 | | { |
| 0 | 200 | | if (!reader.IsEmptyElement) |
| | 201 | | { |
| 0 | 202 | | using (var subtree = reader.ReadSubtree()) |
| | 203 | | { |
| 0 | 204 | | FetchFromTaglinesNode(subtree, item); |
| 0 | 205 | | } |
| | 206 | | } |
| | 207 | | else |
| | 208 | | { |
| 0 | 209 | | reader.Read(); |
| | 210 | | } |
| | 211 | |
|
| 0 | 212 | | break; |
| | 213 | | } |
| | 214 | |
|
| | 215 | | case "Countries": |
| | 216 | | { |
| 0 | 217 | | if (!reader.IsEmptyElement) |
| | 218 | | { |
| 0 | 219 | | reader.Skip(); |
| | 220 | | } |
| | 221 | | else |
| | 222 | | { |
| 0 | 223 | | reader.Read(); |
| | 224 | | } |
| | 225 | |
|
| 0 | 226 | | break; |
| | 227 | | } |
| | 228 | |
|
| | 229 | | case "ContentRating": |
| | 230 | | case "MPAARating": |
| 0 | 231 | | item.OfficialRating = reader.ReadNormalizedString(); |
| 0 | 232 | | break; |
| | 233 | | case "CustomRating": |
| 0 | 234 | | item.CustomRating = reader.ReadNormalizedString(); |
| 0 | 235 | | break; |
| | 236 | | case "RunningTime": |
| 0 | 237 | | var runtimeText = reader.ReadNormalizedString(); |
| 0 | 238 | | if (!string.IsNullOrEmpty(runtimeText)) |
| | 239 | | { |
| 0 | 240 | | if (int.TryParse(runtimeText.AsSpan().LeftPart(' '), NumberStyles.Integer, CultureInfo.Invariant |
| | 241 | | { |
| 0 | 242 | | item.RunTimeTicks = TimeSpan.FromMinutes(runtime).Ticks; |
| | 243 | | } |
| | 244 | | } |
| | 245 | |
|
| 0 | 246 | | break; |
| | 247 | | case "AspectRatio": |
| 0 | 248 | | var aspectRatio = reader.ReadNormalizedString(); |
| 0 | 249 | | if (!string.IsNullOrEmpty(aspectRatio) && item is IHasAspectRatio hasAspectRatio) |
| | 250 | | { |
| 0 | 251 | | hasAspectRatio.AspectRatio = aspectRatio; |
| | 252 | | } |
| | 253 | |
|
| 0 | 254 | | break; |
| | 255 | | case "LockData": |
| 0 | 256 | | item.IsLocked = string.Equals(reader.ReadNormalizedString(), "true", StringComparison.OrdinalIgnoreC |
| 0 | 257 | | break; |
| | 258 | | case "Network": |
| 0 | 259 | | foreach (var name in reader.GetStringArray()) |
| | 260 | | { |
| 0 | 261 | | item.AddStudio(name); |
| | 262 | | } |
| | 263 | |
|
| | 264 | | break; |
| | 265 | | case "Director": |
| 0 | 266 | | foreach (var director in reader.GetPersonArray(PersonKind.Director)) |
| | 267 | | { |
| 0 | 268 | | itemResult.AddPerson(director); |
| | 269 | | } |
| | 270 | |
|
| | 271 | | break; |
| | 272 | | case "Writer": |
| 0 | 273 | | foreach (var writer in reader.GetPersonArray(PersonKind.Writer)) |
| | 274 | | { |
| 0 | 275 | | itemResult.AddPerson(writer); |
| | 276 | | } |
| | 277 | |
|
| | 278 | | break; |
| | 279 | | case "Actors": |
| 0 | 280 | | foreach (var actor in reader.GetPersonArray(PersonKind.Actor)) |
| | 281 | | { |
| 0 | 282 | | itemResult.AddPerson(actor); |
| | 283 | | } |
| | 284 | |
|
| | 285 | | break; |
| | 286 | | case "GuestStars": |
| 0 | 287 | | foreach (var guestStar in reader.GetPersonArray(PersonKind.GuestStar)) |
| | 288 | | { |
| 0 | 289 | | itemResult.AddPerson(guestStar); |
| | 290 | | } |
| | 291 | |
|
| | 292 | | break; |
| | 293 | | case "Trailer": |
| 0 | 294 | | var trailer = reader.ReadNormalizedString(); |
| 0 | 295 | | if (!string.IsNullOrEmpty(trailer)) |
| | 296 | | { |
| 0 | 297 | | item.AddTrailerUrl(trailer); |
| | 298 | | } |
| | 299 | |
|
| 0 | 300 | | break; |
| | 301 | | case "DisplayOrder": |
| 0 | 302 | | var displayOrder = reader.ReadNormalizedString(); |
| 0 | 303 | | if (!string.IsNullOrEmpty(displayOrder) && item is IHasDisplayOrder hasDisplayOrder) |
| | 304 | | { |
| 0 | 305 | | hasDisplayOrder.DisplayOrder = displayOrder; |
| | 306 | | } |
| | 307 | |
|
| 0 | 308 | | break; |
| | 309 | | case "Trailers": |
| | 310 | | { |
| 0 | 311 | | if (!reader.IsEmptyElement) |
| | 312 | | { |
| 0 | 313 | | using var subtree = reader.ReadSubtree(); |
| 0 | 314 | | FetchDataFromTrailersNode(subtree, item); |
| | 315 | | } |
| | 316 | | else |
| | 317 | | { |
| 0 | 318 | | reader.Read(); |
| | 319 | | } |
| | 320 | |
|
| 0 | 321 | | break; |
| | 322 | | } |
| | 323 | |
|
| | 324 | | case "ProductionYear": |
| 0 | 325 | | if (reader.TryReadInt(out var productionYear) && productionYear > 1850) |
| | 326 | | { |
| 0 | 327 | | item.ProductionYear = productionYear; |
| | 328 | | } |
| | 329 | |
|
| 0 | 330 | | break; |
| | 331 | | case "Rating": |
| | 332 | | case "IMDBrating": |
| | 333 | | { |
| 0 | 334 | | var rating = reader.ReadNormalizedString(); |
| | 335 | |
|
| 0 | 336 | | if (!string.IsNullOrEmpty(rating)) |
| | 337 | | { |
| | 338 | | // All external meta is saving this as '.' for decimal I believe...but just to be sure |
| 0 | 339 | | if (float.TryParse(rating.Replace(',', '.'), NumberStyles.AllowDecimalPoint, CultureInfo.Invaria |
| | 340 | | { |
| 0 | 341 | | item.CommunityRating = val; |
| | 342 | | } |
| | 343 | | } |
| | 344 | |
|
| 0 | 345 | | break; |
| | 346 | | } |
| | 347 | |
|
| | 348 | | case "BirthDate": |
| | 349 | | case "PremiereDate": |
| | 350 | | case "FirstAired": |
| 0 | 351 | | if (reader.TryReadDateTimeExact("yyyy-MM-dd", out var firstAired)) |
| | 352 | | { |
| 0 | 353 | | item.PremiereDate = firstAired; |
| 0 | 354 | | item.ProductionYear = firstAired.Year; |
| | 355 | | } |
| | 356 | |
|
| 0 | 357 | | break; |
| | 358 | | case "DeathDate": |
| | 359 | | case "EndDate": |
| 0 | 360 | | if (reader.TryReadDateTimeExact("yyyy-MM-dd", out var endDate)) |
| | 361 | | { |
| 0 | 362 | | item.EndDate = endDate; |
| | 363 | | } |
| | 364 | |
|
| 0 | 365 | | break; |
| | 366 | | case "CollectionNumber": |
| 0 | 367 | | var tmdbCollection = reader.ReadNormalizedString(); |
| 0 | 368 | | item.TrySetProviderId(MetadataProvider.TmdbCollection, tmdbCollection); |
| | 369 | |
|
| 0 | 370 | | break; |
| | 371 | |
|
| | 372 | | case "Genres": |
| | 373 | | { |
| 0 | 374 | | if (!reader.IsEmptyElement) |
| | 375 | | { |
| 0 | 376 | | using var subtree = reader.ReadSubtree(); |
| 0 | 377 | | FetchFromGenresNode(subtree, item); |
| | 378 | | } |
| | 379 | | else |
| | 380 | | { |
| 0 | 381 | | reader.Read(); |
| | 382 | | } |
| | 383 | |
|
| 0 | 384 | | break; |
| | 385 | | } |
| | 386 | |
|
| | 387 | | case "Tags": |
| | 388 | | { |
| 0 | 389 | | if (!reader.IsEmptyElement) |
| | 390 | | { |
| 0 | 391 | | using var subtree = reader.ReadSubtree(); |
| 0 | 392 | | FetchFromTagsNode(subtree, item); |
| | 393 | | } |
| | 394 | | else |
| | 395 | | { |
| 0 | 396 | | reader.Read(); |
| | 397 | | } |
| | 398 | |
|
| 0 | 399 | | break; |
| | 400 | | } |
| | 401 | |
|
| | 402 | | case "Persons": |
| | 403 | | { |
| 0 | 404 | | if (!reader.IsEmptyElement) |
| | 405 | | { |
| 0 | 406 | | using var subtree = reader.ReadSubtree(); |
| 0 | 407 | | FetchDataFromPersonsNode(subtree, itemResult); |
| | 408 | | } |
| | 409 | | else |
| | 410 | | { |
| 0 | 411 | | reader.Read(); |
| | 412 | | } |
| | 413 | |
|
| 0 | 414 | | break; |
| | 415 | | } |
| | 416 | |
|
| | 417 | | case "Studios": |
| | 418 | | { |
| 0 | 419 | | if (!reader.IsEmptyElement) |
| | 420 | | { |
| 0 | 421 | | using var subtree = reader.ReadSubtree(); |
| 0 | 422 | | FetchFromStudiosNode(subtree, item); |
| | 423 | | } |
| | 424 | | else |
| | 425 | | { |
| 0 | 426 | | reader.Read(); |
| | 427 | | } |
| | 428 | |
|
| 0 | 429 | | break; |
| | 430 | | } |
| | 431 | |
|
| | 432 | | case "Shares": |
| | 433 | | { |
| 0 | 434 | | if (!reader.IsEmptyElement) |
| | 435 | | { |
| 0 | 436 | | using var subtree = reader.ReadSubtree(); |
| 0 | 437 | | if (item is IHasShares hasShares) |
| | 438 | | { |
| 0 | 439 | | FetchFromSharesNode(subtree, hasShares); |
| | 440 | | } |
| | 441 | | } |
| | 442 | | else |
| | 443 | | { |
| 0 | 444 | | reader.Read(); |
| | 445 | | } |
| | 446 | |
|
| 0 | 447 | | break; |
| | 448 | | } |
| | 449 | |
|
| | 450 | | case "OwnerUserId": |
| | 451 | | { |
| 0 | 452 | | var val = reader.ReadNormalizedString(); |
| | 453 | |
|
| 0 | 454 | | if (Guid.TryParse(val, out var guid) && !guid.Equals(Guid.Empty)) |
| | 455 | | { |
| 0 | 456 | | if (item is Playlist playlist) |
| | 457 | | { |
| 0 | 458 | | playlist.OwnerUserId = guid; |
| | 459 | | } |
| | 460 | | } |
| | 461 | |
|
| 0 | 462 | | break; |
| | 463 | | } |
| | 464 | |
|
| | 465 | | case "Format3D": |
| | 466 | | { |
| 0 | 467 | | var val = reader.ReadNormalizedString(); |
| | 468 | |
|
| 0 | 469 | | if (item is Video video) |
| | 470 | | { |
| 0 | 471 | | if (string.Equals("HSBS", val, StringComparison.OrdinalIgnoreCase)) |
| | 472 | | { |
| 0 | 473 | | video.Video3DFormat = Video3DFormat.HalfSideBySide; |
| | 474 | | } |
| 0 | 475 | | else if (string.Equals("HTAB", val, StringComparison.OrdinalIgnoreCase)) |
| | 476 | | { |
| 0 | 477 | | video.Video3DFormat = Video3DFormat.HalfTopAndBottom; |
| | 478 | | } |
| 0 | 479 | | else if (string.Equals("FTAB", val, StringComparison.OrdinalIgnoreCase)) |
| | 480 | | { |
| 0 | 481 | | video.Video3DFormat = Video3DFormat.FullTopAndBottom; |
| | 482 | | } |
| 0 | 483 | | else if (string.Equals("FSBS", val, StringComparison.OrdinalIgnoreCase)) |
| | 484 | | { |
| 0 | 485 | | video.Video3DFormat = Video3DFormat.FullSideBySide; |
| | 486 | | } |
| 0 | 487 | | else if (string.Equals("MVC", val, StringComparison.OrdinalIgnoreCase)) |
| | 488 | | { |
| 0 | 489 | | video.Video3DFormat = Video3DFormat.MVC; |
| | 490 | | } |
| | 491 | | } |
| | 492 | |
|
| 0 | 493 | | break; |
| | 494 | | } |
| | 495 | |
|
| | 496 | | default: |
| | 497 | | { |
| 0 | 498 | | string readerName = reader.Name; |
| 0 | 499 | | if (_validProviderIds!.TryGetValue(readerName, out string? providerIdValue)) |
| | 500 | | { |
| 0 | 501 | | var id = reader.ReadNormalizedString(); |
| 0 | 502 | | item.TrySetProviderId(providerIdValue, id); |
| | 503 | | } |
| | 504 | | else |
| | 505 | | { |
| 0 | 506 | | reader.Skip(); |
| | 507 | | } |
| | 508 | |
|
| | 509 | | break; |
| | 510 | | } |
| | 511 | | } |
| 0 | 512 | | } |
| | 513 | |
|
| | 514 | | private void FetchFromSharesNode(XmlReader reader, IHasShares item) |
| | 515 | | { |
| 0 | 516 | | var list = new List<PlaylistUserPermissions>(); |
| | 517 | |
|
| 0 | 518 | | reader.MoveToContent(); |
| 0 | 519 | | reader.Read(); |
| | 520 | |
|
| | 521 | | // Loop through each element |
| 0 | 522 | | while (!reader.EOF && reader.ReadState == ReadState.Interactive) |
| | 523 | | { |
| 0 | 524 | | if (reader.NodeType == XmlNodeType.Element) |
| | 525 | | { |
| 0 | 526 | | switch (reader.Name) |
| | 527 | | { |
| | 528 | | case "Share": |
| | 529 | | { |
| 0 | 530 | | if (reader.IsEmptyElement) |
| | 531 | | { |
| 0 | 532 | | reader.Read(); |
| 0 | 533 | | continue; |
| | 534 | | } |
| | 535 | |
|
| 0 | 536 | | using (var subReader = reader.ReadSubtree()) |
| | 537 | | { |
| 0 | 538 | | var child = GetShare(subReader); |
| | 539 | |
|
| 0 | 540 | | if (child is not null) |
| | 541 | | { |
| 0 | 542 | | list.Add(child); |
| | 543 | | } |
| 0 | 544 | | } |
| | 545 | |
|
| | 546 | | break; |
| | 547 | | } |
| | 548 | |
|
| | 549 | | default: |
| | 550 | | { |
| 0 | 551 | | reader.Skip(); |
| 0 | 552 | | break; |
| | 553 | | } |
| | 554 | | } |
| | 555 | | } |
| | 556 | | else |
| | 557 | | { |
| 0 | 558 | | reader.Read(); |
| | 559 | | } |
| | 560 | | } |
| | 561 | |
|
| 0 | 562 | | item.Shares = [.. list]; |
| 0 | 563 | | } |
| | 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 | | { |
| 0 | 572 | | reader.MoveToContent(); |
| 0 | 573 | | reader.Read(); |
| | 574 | |
|
| | 575 | | // Loop through each element |
| 0 | 576 | | while (!reader.EOF && reader.ReadState == ReadState.Interactive) |
| | 577 | | { |
| 0 | 578 | | if (reader.NodeType == XmlNodeType.Element) |
| | 579 | | { |
| 0 | 580 | | switch (reader.Name) |
| | 581 | | { |
| | 582 | | case "Tagline": |
| 0 | 583 | | var val = reader.ReadNormalizedString(); |
| 0 | 584 | | if (!string.IsNullOrEmpty(val)) |
| | 585 | | { |
| 0 | 586 | | item.Tagline = val; |
| | 587 | | } |
| | 588 | |
|
| 0 | 589 | | break; |
| | 590 | | default: |
| 0 | 591 | | reader.Skip(); |
| 0 | 592 | | break; |
| | 593 | | } |
| | 594 | | } |
| | 595 | | else |
| | 596 | | { |
| 0 | 597 | | reader.Read(); |
| | 598 | | } |
| | 599 | | } |
| 0 | 600 | | } |
| | 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 | | { |
| 0 | 609 | | reader.MoveToContent(); |
| 0 | 610 | | reader.Read(); |
| | 611 | |
|
| | 612 | | // Loop through each element |
| 0 | 613 | | while (!reader.EOF && reader.ReadState == ReadState.Interactive) |
| | 614 | | { |
| 0 | 615 | | if (reader.NodeType == XmlNodeType.Element) |
| | 616 | | { |
| 0 | 617 | | switch (reader.Name) |
| | 618 | | { |
| | 619 | | case "Genre": |
| 0 | 620 | | var genre = reader.ReadNormalizedString(); |
| 0 | 621 | | if (!string.IsNullOrEmpty(genre)) |
| | 622 | | { |
| 0 | 623 | | item.AddGenre(genre); |
| | 624 | | } |
| | 625 | |
|
| 0 | 626 | | break; |
| | 627 | | default: |
| 0 | 628 | | reader.Skip(); |
| 0 | 629 | | break; |
| | 630 | | } |
| | 631 | | } |
| | 632 | | else |
| | 633 | | { |
| 0 | 634 | | reader.Read(); |
| | 635 | | } |
| | 636 | | } |
| 0 | 637 | | } |
| | 638 | |
|
| | 639 | | private void FetchFromTagsNode(XmlReader reader, BaseItem item) |
| | 640 | | { |
| 0 | 641 | | reader.MoveToContent(); |
| 0 | 642 | | reader.Read(); |
| | 643 | |
|
| 0 | 644 | | var tags = new List<string>(); |
| | 645 | |
|
| | 646 | | // Loop through each element |
| 0 | 647 | | while (!reader.EOF && reader.ReadState == ReadState.Interactive) |
| | 648 | | { |
| 0 | 649 | | if (reader.NodeType == XmlNodeType.Element) |
| | 650 | | { |
| 0 | 651 | | switch (reader.Name) |
| | 652 | | { |
| | 653 | | case "Tag": |
| 0 | 654 | | var tag = reader.ReadNormalizedString(); |
| 0 | 655 | | if (!string.IsNullOrEmpty(tag)) |
| | 656 | | { |
| 0 | 657 | | tags.Add(tag); |
| | 658 | | } |
| | 659 | |
|
| 0 | 660 | | break; |
| | 661 | | default: |
| 0 | 662 | | reader.Skip(); |
| 0 | 663 | | break; |
| | 664 | | } |
| | 665 | | } |
| | 666 | | else |
| | 667 | | { |
| 0 | 668 | | reader.Read(); |
| | 669 | | } |
| | 670 | | } |
| | 671 | |
|
| 0 | 672 | | item.Tags = tags.Distinct(StringComparer.Ordinal).ToArray(); |
| 0 | 673 | | } |
| | 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 | | { |
| 0 | 682 | | reader.MoveToContent(); |
| 0 | 683 | | reader.Read(); |
| | 684 | |
|
| | 685 | | // Loop through each element |
| 0 | 686 | | while (!reader.EOF && reader.ReadState == ReadState.Interactive) |
| | 687 | | { |
| 0 | 688 | | if (reader.NodeType == XmlNodeType.Element) |
| | 689 | | { |
| 0 | 690 | | switch (reader.Name) |
| | 691 | | { |
| | 692 | | case "Person": |
| | 693 | | case "Actor": |
| 0 | 694 | | var person = reader.GetPersonFromXmlNode(); |
| 0 | 695 | | if (person is not null) |
| | 696 | | { |
| 0 | 697 | | item.AddPerson(person); |
| | 698 | | } |
| | 699 | |
|
| 0 | 700 | | break; |
| | 701 | | default: |
| 0 | 702 | | reader.Skip(); |
| 0 | 703 | | break; |
| | 704 | | } |
| | 705 | | } |
| | 706 | | else |
| | 707 | | { |
| 0 | 708 | | reader.Read(); |
| | 709 | | } |
| | 710 | | } |
| 0 | 711 | | } |
| | 712 | |
|
| | 713 | | private void FetchDataFromTrailersNode(XmlReader reader, T item) |
| | 714 | | { |
| 0 | 715 | | reader.MoveToContent(); |
| 0 | 716 | | reader.Read(); |
| | 717 | |
|
| | 718 | | // Loop through each element |
| 0 | 719 | | while (!reader.EOF && reader.ReadState == ReadState.Interactive) |
| | 720 | | { |
| 0 | 721 | | if (reader.NodeType == XmlNodeType.Element) |
| | 722 | | { |
| 0 | 723 | | switch (reader.Name) |
| | 724 | | { |
| | 725 | | case "Trailer": |
| 0 | 726 | | var trailer = reader.ReadNormalizedString(); |
| 0 | 727 | | if (!string.IsNullOrEmpty(trailer)) |
| | 728 | | { |
| 0 | 729 | | item.AddTrailerUrl(trailer); |
| | 730 | | } |
| | 731 | |
|
| 0 | 732 | | break; |
| | 733 | | default: |
| 0 | 734 | | reader.Skip(); |
| 0 | 735 | | break; |
| | 736 | | } |
| | 737 | | } |
| | 738 | | else |
| | 739 | | { |
| 0 | 740 | | reader.Read(); |
| | 741 | | } |
| | 742 | | } |
| 0 | 743 | | } |
| | 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 | | { |
| 0 | 752 | | reader.MoveToContent(); |
| 0 | 753 | | reader.Read(); |
| | 754 | |
|
| | 755 | | // Loop through each element |
| 0 | 756 | | while (!reader.EOF && reader.ReadState == ReadState.Interactive) |
| | 757 | | { |
| 0 | 758 | | if (reader.NodeType == XmlNodeType.Element) |
| | 759 | | { |
| 0 | 760 | | switch (reader.Name) |
| | 761 | | { |
| | 762 | | case "Studio": |
| 0 | 763 | | var studio = reader.ReadNormalizedString(); |
| 0 | 764 | | if (!string.IsNullOrEmpty(studio)) |
| | 765 | | { |
| 0 | 766 | | item.AddStudio(studio); |
| | 767 | | } |
| | 768 | |
|
| 0 | 769 | | break; |
| | 770 | | default: |
| 0 | 771 | | reader.Skip(); |
| 0 | 772 | | break; |
| | 773 | | } |
| | 774 | | } |
| | 775 | | else |
| | 776 | | { |
| 0 | 777 | | reader.Read(); |
| | 778 | | } |
| | 779 | | } |
| 0 | 780 | | } |
| | 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 | | { |
| 0 | 789 | | var linkedItem = new LinkedChild { Type = LinkedChildType.Manual }; |
| | 790 | |
|
| 0 | 791 | | reader.MoveToContent(); |
| 0 | 792 | | reader.Read(); |
| | 793 | |
|
| | 794 | | // Loop through each element |
| 0 | 795 | | while (!reader.EOF && reader.ReadState == ReadState.Interactive) |
| | 796 | | { |
| 0 | 797 | | if (reader.NodeType == XmlNodeType.Element) |
| | 798 | | { |
| 0 | 799 | | switch (reader.Name) |
| | 800 | | { |
| | 801 | | case "Path": |
| 0 | 802 | | linkedItem.Path = reader.ReadNormalizedString(); |
| 0 | 803 | | break; |
| | 804 | | case "ItemId": |
| 0 | 805 | | linkedItem.LibraryItemId = reader.ReadNormalizedString(); |
| 0 | 806 | | break; |
| | 807 | | default: |
| 0 | 808 | | reader.Skip(); |
| 0 | 809 | | break; |
| | 810 | | } |
| | 811 | | } |
| | 812 | | else |
| | 813 | | { |
| 0 | 814 | | reader.Read(); |
| | 815 | | } |
| | 816 | | } |
| | 817 | |
|
| | 818 | | // This is valid |
| 0 | 819 | | if (!string.IsNullOrWhiteSpace(linkedItem.Path) || !string.IsNullOrWhiteSpace(linkedItem.LibraryItemId)) |
| | 820 | | { |
| 0 | 821 | | return linkedItem; |
| | 822 | | } |
| | 823 | |
|
| 0 | 824 | | 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 | | { |
| 0 | 834 | | reader.MoveToContent(); |
| 0 | 835 | | reader.Read(); |
| 0 | 836 | | string? userId = null; |
| 0 | 837 | | var canEdit = false; |
| | 838 | |
|
| | 839 | | // Loop through each element |
| 0 | 840 | | while (!reader.EOF && reader.ReadState == ReadState.Interactive) |
| | 841 | | { |
| 0 | 842 | | if (reader.NodeType == XmlNodeType.Element) |
| | 843 | | { |
| 0 | 844 | | switch (reader.Name) |
| | 845 | | { |
| | 846 | | case "UserId": |
| 0 | 847 | | userId = reader.ReadNormalizedString(); |
| 0 | 848 | | break; |
| | 849 | | case "CanEdit": |
| 0 | 850 | | canEdit = string.Equals(reader.ReadNormalizedString(), "true", StringComparison.OrdinalIgnor |
| 0 | 851 | | break; |
| | 852 | | default: |
| 0 | 853 | | reader.Skip(); |
| 0 | 854 | | break; |
| | 855 | | } |
| | 856 | | } |
| | 857 | | else |
| | 858 | | { |
| 0 | 859 | | reader.Read(); |
| | 860 | | } |
| | 861 | | } |
| | 862 | |
|
| | 863 | | // This is valid |
| 0 | 864 | | if (!string.IsNullOrEmpty(userId) && Guid.TryParse(userId, out var guid)) |
| | 865 | | { |
| 0 | 866 | | return new PlaylistUserPermissions(guid, canEdit); |
| | 867 | | } |
| | 868 | |
|
| 0 | 869 | | return null; |
| | 870 | | } |
| | 871 | | } |
| | 872 | | } |