XmlSaverHelpers.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Security;
  7. using System.Text;
  8. using System.Xml;
  9. using MediaBrowser.Controller.Entities;
  10. using MediaBrowser.Controller.Entities.Movies;
  11. using MediaBrowser.Controller.Entities.TV;
  12. using MediaBrowser.Controller.Persistence;
  13. using MediaBrowser.Model.Entities;
  14. namespace MediaBrowser.LocalMetadata.Savers
  15. {
  16. /// <summary>
  17. /// Class XmlHelpers
  18. /// </summary>
  19. public static class XmlSaverHelpers
  20. {
  21. private static readonly Dictionary<string, string> CommonTags = new[] {
  22. "Added",
  23. "AspectRatio",
  24. "AudioDbAlbumId",
  25. "AudioDbArtistId",
  26. "AwardSummary",
  27. "BirthDate",
  28. "Budget",
  29. // Deprecated. No longer saving in this field.
  30. "certification",
  31. "Chapters",
  32. "ContentRating",
  33. "Countries",
  34. "CustomRating",
  35. "CriticRating",
  36. "CriticRatingSummary",
  37. "DeathDate",
  38. "DisplayOrder",
  39. "EndDate",
  40. "Genres",
  41. "Genre",
  42. "GamesDbId",
  43. // Deprecated. No longer saving in this field.
  44. "IMDB_ID",
  45. "IMDB",
  46. // Deprecated. No longer saving in this field.
  47. "IMDbId",
  48. "Language",
  49. "LocalTitle",
  50. "LockData",
  51. "LockedFields",
  52. "Format3D",
  53. "Metascore",
  54. // Deprecated. No longer saving in this field.
  55. "MPAARating",
  56. "MusicBrainzArtistId",
  57. "MusicBrainzAlbumArtistId",
  58. "MusicBrainzAlbumId",
  59. "MusicBrainzReleaseGroupId",
  60. // Deprecated. No longer saving in this field.
  61. "MusicbrainzId",
  62. "Overview",
  63. "ShortOverview",
  64. "Persons",
  65. "PlotKeywords",
  66. "PremiereDate",
  67. "ProductionYear",
  68. "Rating",
  69. "Revenue",
  70. "RottenTomatoesId",
  71. "RunningTime",
  72. // Deprecated. No longer saving in this field.
  73. "Runtime",
  74. "SortTitle",
  75. "Studios",
  76. "Tags",
  77. // Deprecated. No longer saving in this field.
  78. "TagLine",
  79. "Taglines",
  80. "TMDbCollectionId",
  81. "TMDbId",
  82. // Deprecated. No longer saving in this field.
  83. "Trailer",
  84. "Trailers",
  85. "TVcomId",
  86. "TvDbId",
  87. "Type",
  88. "TVRageId",
  89. "VoteCount",
  90. "Website",
  91. "Zap2ItId",
  92. "CollectionItems"
  93. }.ToDictionary(i => i, StringComparer.OrdinalIgnoreCase);
  94. /// <summary>
  95. /// The us culture
  96. /// </summary>
  97. private static readonly CultureInfo UsCulture = new CultureInfo("en-US");
  98. /// <summary>
  99. /// Saves the specified XML.
  100. /// </summary>
  101. /// <param name="xml">The XML.</param>
  102. /// <param name="path">The path.</param>
  103. /// <param name="xmlTagsUsed">The XML tags used.</param>
  104. public static void Save(StringBuilder xml, string path, List<string> xmlTagsUsed)
  105. {
  106. if (File.Exists(path))
  107. {
  108. var position = xml.ToString().LastIndexOf("</", StringComparison.OrdinalIgnoreCase);
  109. xml.Insert(position, GetCustomTags(path, xmlTagsUsed));
  110. }
  111. var xmlDocument = new XmlDocument();
  112. xmlDocument.LoadXml(xml.ToString());
  113. //Add the new node to the document.
  114. xmlDocument.InsertBefore(xmlDocument.CreateXmlDeclaration("1.0", "UTF-8", "yes"), xmlDocument.DocumentElement);
  115. Directory.CreateDirectory(Path.GetDirectoryName(path));
  116. var wasHidden = false;
  117. var file = new FileInfo(path);
  118. // This will fail if the file is hidden
  119. if (file.Exists)
  120. {
  121. if ((file.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
  122. {
  123. file.Attributes &= ~FileAttributes.Hidden;
  124. wasHidden = true;
  125. }
  126. }
  127. using (var filestream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read))
  128. {
  129. using (var streamWriter = new StreamWriter(filestream, Encoding.UTF8))
  130. {
  131. xmlDocument.Save(streamWriter);
  132. }
  133. }
  134. if (wasHidden)
  135. {
  136. file.Refresh();
  137. // Add back the attribute
  138. file.Attributes |= FileAttributes.Hidden;
  139. }
  140. }
  141. /// <summary>
  142. /// Gets the custom tags.
  143. /// </summary>
  144. /// <param name="path">The path.</param>
  145. /// <param name="xmlTagsUsed">The XML tags used.</param>
  146. /// <returns>System.String.</returns>
  147. private static string GetCustomTags(string path, List<string> xmlTagsUsed)
  148. {
  149. var settings = new XmlReaderSettings
  150. {
  151. CheckCharacters = false,
  152. IgnoreProcessingInstructions = true,
  153. IgnoreComments = true,
  154. ValidationType = ValidationType.None
  155. };
  156. var builder = new StringBuilder();
  157. using (var streamReader = new StreamReader(path, Encoding.UTF8))
  158. {
  159. // Use XmlReader for best performance
  160. using (var reader = XmlReader.Create(streamReader, settings))
  161. {
  162. reader.MoveToContent();
  163. // Loop through each element
  164. while (reader.Read())
  165. {
  166. if (reader.NodeType == XmlNodeType.Element)
  167. {
  168. var name = reader.Name;
  169. if (!CommonTags.ContainsKey(name) && !xmlTagsUsed.Contains(name, StringComparer.OrdinalIgnoreCase))
  170. {
  171. builder.AppendLine(reader.ReadOuterXml());
  172. }
  173. else
  174. {
  175. reader.Skip();
  176. }
  177. }
  178. }
  179. }
  180. }
  181. return builder.ToString();
  182. }
  183. /// <summary>
  184. /// Adds the common nodes.
  185. /// </summary>
  186. /// <param name="item">The item.</param>
  187. /// <param name="builder">The builder.</param>
  188. public static void AddCommonNodes(BaseItem item, StringBuilder builder)
  189. {
  190. if (!string.IsNullOrEmpty(item.OfficialRating))
  191. {
  192. builder.Append("<ContentRating>" + SecurityElement.Escape(item.OfficialRating) + "</ContentRating>");
  193. }
  194. builder.Append("<Added>" + SecurityElement.Escape(item.DateCreated.ToLocalTime().ToString("G")) + "</Added>");
  195. builder.Append("<LockData>" + item.IsLocked.ToString().ToLower() + "</LockData>");
  196. if (item.LockedFields.Count > 0)
  197. {
  198. builder.Append("<LockedFields>" + string.Join("|", item.LockedFields.Select(i => i.ToString()).ToArray()) + "</LockedFields>");
  199. }
  200. if (!string.IsNullOrEmpty(item.DisplayMediaType))
  201. {
  202. builder.Append("<Type>" + SecurityElement.Escape(item.DisplayMediaType) + "</Type>");
  203. }
  204. var hasCriticRating = item as IHasCriticRating;
  205. if (hasCriticRating != null)
  206. {
  207. if (hasCriticRating.CriticRating.HasValue)
  208. {
  209. builder.Append("<CriticRating>" + SecurityElement.Escape(hasCriticRating.CriticRating.Value.ToString(UsCulture)) + "</CriticRating>");
  210. }
  211. if (!string.IsNullOrEmpty(hasCriticRating.CriticRatingSummary))
  212. {
  213. builder.Append("<CriticRatingSummary><![CDATA[" + hasCriticRating.CriticRatingSummary + "]]></CriticRatingSummary>");
  214. }
  215. }
  216. if (!string.IsNullOrEmpty(item.Overview))
  217. {
  218. builder.Append("<Overview><![CDATA[" + item.Overview + "]]></Overview>");
  219. }
  220. var hasShortOverview = item as IHasShortOverview;
  221. if (hasShortOverview != null)
  222. {
  223. if (!string.IsNullOrEmpty(hasShortOverview.ShortOverview))
  224. {
  225. builder.Append("<ShortOverview><![CDATA[" + hasShortOverview.ShortOverview + "]]></ShortOverview>");
  226. }
  227. }
  228. if (!string.IsNullOrEmpty(item.CustomRating))
  229. {
  230. builder.Append("<CustomRating>" + SecurityElement.Escape(item.CustomRating) + "</CustomRating>");
  231. }
  232. if (!string.IsNullOrEmpty(item.Name) && !(item is Episode))
  233. {
  234. builder.Append("<LocalTitle>" + SecurityElement.Escape(item.Name) + "</LocalTitle>");
  235. }
  236. if (!string.IsNullOrEmpty(item.ForcedSortName))
  237. {
  238. builder.Append("<SortTitle>" + SecurityElement.Escape(item.ForcedSortName) + "</SortTitle>");
  239. }
  240. if (item.PremiereDate.HasValue)
  241. {
  242. if (item is Person)
  243. {
  244. builder.Append("<BirthDate>" + SecurityElement.Escape(item.PremiereDate.Value.ToLocalTime().ToString("yyyy-MM-dd")) + "</BirthDate>");
  245. }
  246. else if (!(item is Episode))
  247. {
  248. builder.Append("<PremiereDate>" + SecurityElement.Escape(item.PremiereDate.Value.ToLocalTime().ToString("yyyy-MM-dd")) + "</PremiereDate>");
  249. }
  250. }
  251. if (item.EndDate.HasValue)
  252. {
  253. if (item is Person)
  254. {
  255. builder.Append("<DeathDate>" + SecurityElement.Escape(item.EndDate.Value.ToString("yyyy-MM-dd")) + "</DeathDate>");
  256. }
  257. else if (!(item is Episode))
  258. {
  259. builder.Append("<EndDate>" + SecurityElement.Escape(item.EndDate.Value.ToString("yyyy-MM-dd")) + "</EndDate>");
  260. }
  261. }
  262. var hasTrailers = item as IHasTrailers;
  263. if (hasTrailers != null)
  264. {
  265. if (hasTrailers.RemoteTrailers.Count > 0)
  266. {
  267. builder.Append("<Trailers>");
  268. foreach (var trailer in hasTrailers.RemoteTrailers)
  269. {
  270. builder.Append("<Trailer>" + SecurityElement.Escape(trailer.Url) + "</Trailer>");
  271. }
  272. builder.Append("</Trailers>");
  273. }
  274. }
  275. var hasProductionLocations = item as IHasProductionLocations;
  276. if (hasProductionLocations != null)
  277. {
  278. if (hasProductionLocations.ProductionLocations.Count > 0)
  279. {
  280. builder.Append("<Countries>");
  281. foreach (var name in hasProductionLocations.ProductionLocations)
  282. {
  283. builder.Append("<Country>" + SecurityElement.Escape(name) + "</Country>");
  284. }
  285. builder.Append("</Countries>");
  286. }
  287. }
  288. var hasDisplayOrder = item as IHasDisplayOrder;
  289. if (hasDisplayOrder != null && !string.IsNullOrEmpty(hasDisplayOrder.DisplayOrder))
  290. {
  291. builder.Append("<DisplayOrder>" + SecurityElement.Escape(hasDisplayOrder.DisplayOrder) + "</DisplayOrder>");
  292. }
  293. var hasMetascore = item as IHasMetascore;
  294. if (hasMetascore != null && hasMetascore.Metascore.HasValue)
  295. {
  296. builder.Append("<Metascore>" + SecurityElement.Escape(hasMetascore.Metascore.Value.ToString(UsCulture)) + "</Metascore>");
  297. }
  298. var hasAwards = item as IHasAwards;
  299. if (hasAwards != null && !string.IsNullOrEmpty(hasAwards.AwardSummary))
  300. {
  301. builder.Append("<AwardSummary>" + SecurityElement.Escape(hasAwards.AwardSummary) + "</AwardSummary>");
  302. }
  303. var hasBudget = item as IHasBudget;
  304. if (hasBudget != null)
  305. {
  306. if (hasBudget.Budget.HasValue)
  307. {
  308. builder.Append("<Budget>" + SecurityElement.Escape(hasBudget.Budget.Value.ToString(UsCulture)) + "</Budget>");
  309. }
  310. if (hasBudget.Revenue.HasValue)
  311. {
  312. builder.Append("<Revenue>" + SecurityElement.Escape(hasBudget.Revenue.Value.ToString(UsCulture)) + "</Revenue>");
  313. }
  314. }
  315. if (item.CommunityRating.HasValue)
  316. {
  317. builder.Append("<Rating>" + SecurityElement.Escape(item.CommunityRating.Value.ToString(UsCulture)) + "</Rating>");
  318. }
  319. if (item.VoteCount.HasValue)
  320. {
  321. builder.Append("<VoteCount>" + SecurityElement.Escape(item.VoteCount.Value.ToString(UsCulture)) + "</VoteCount>");
  322. }
  323. if (item.ProductionYear.HasValue && !(item is Person))
  324. {
  325. builder.Append("<ProductionYear>" + SecurityElement.Escape(item.ProductionYear.Value.ToString(UsCulture)) + "</ProductionYear>");
  326. }
  327. if (!string.IsNullOrEmpty(item.HomePageUrl))
  328. {
  329. builder.Append("<Website>" + SecurityElement.Escape(item.HomePageUrl) + "</Website>");
  330. }
  331. var hasAspectRatio = item as IHasAspectRatio;
  332. if (hasAspectRatio != null)
  333. {
  334. if (!string.IsNullOrEmpty(hasAspectRatio.AspectRatio))
  335. {
  336. builder.Append("<AspectRatio>" + SecurityElement.Escape(hasAspectRatio.AspectRatio) + "</AspectRatio>");
  337. }
  338. }
  339. var hasLanguage = item as IHasPreferredMetadataLanguage;
  340. if (hasLanguage != null)
  341. {
  342. if (!string.IsNullOrEmpty(hasLanguage.PreferredMetadataLanguage))
  343. {
  344. builder.Append("<Language>" + SecurityElement.Escape(hasLanguage.PreferredMetadataLanguage) + "</Language>");
  345. }
  346. }
  347. // Use original runtime here, actual file runtime later in MediaInfo
  348. var runTimeTicks = item.RunTimeTicks;
  349. if (runTimeTicks.HasValue)
  350. {
  351. var timespan = TimeSpan.FromTicks(runTimeTicks.Value);
  352. builder.Append("<RunningTime>" + Convert.ToInt32(timespan.TotalMinutes).ToString(UsCulture) + "</RunningTime>");
  353. }
  354. var imdb = item.GetProviderId(MetadataProviders.Imdb);
  355. if (!string.IsNullOrEmpty(imdb))
  356. {
  357. builder.Append("<IMDB>" + SecurityElement.Escape(imdb) + "</IMDB>");
  358. }
  359. var tmdb = item.GetProviderId(MetadataProviders.Tmdb);
  360. if (!string.IsNullOrEmpty(tmdb))
  361. {
  362. builder.Append("<TMDbId>" + SecurityElement.Escape(tmdb) + "</TMDbId>");
  363. }
  364. if (!(item is Series))
  365. {
  366. var tvdb = item.GetProviderId(MetadataProviders.Tvdb);
  367. if (!string.IsNullOrEmpty(tvdb))
  368. {
  369. builder.Append("<TvDbId>" + SecurityElement.Escape(tvdb) + "</TvDbId>");
  370. }
  371. }
  372. var externalId = item.GetProviderId(MetadataProviders.Tvcom);
  373. if (!string.IsNullOrEmpty(externalId))
  374. {
  375. builder.Append("<TVcomId>" + SecurityElement.Escape(externalId) + "</TVcomId>");
  376. }
  377. externalId = item.GetProviderId(MetadataProviders.RottenTomatoes);
  378. if (!string.IsNullOrEmpty(externalId))
  379. {
  380. builder.Append("<RottenTomatoesId>" + SecurityElement.Escape(externalId) + "</RottenTomatoesId>");
  381. }
  382. externalId = item.GetProviderId(MetadataProviders.Zap2It);
  383. if (!string.IsNullOrEmpty(externalId))
  384. {
  385. builder.Append("<Zap2ItId>" + SecurityElement.Escape(externalId) + "</Zap2ItId>");
  386. }
  387. externalId = item.GetProviderId(MetadataProviders.MusicBrainzAlbum);
  388. if (!string.IsNullOrEmpty(externalId))
  389. {
  390. builder.Append("<MusicBrainzAlbumId>" + SecurityElement.Escape(externalId) + "</MusicBrainzAlbumId>");
  391. }
  392. externalId = item.GetProviderId(MetadataProviders.MusicBrainzAlbumArtist);
  393. if (!string.IsNullOrEmpty(externalId))
  394. {
  395. builder.Append("<MusicBrainzAlbumArtistId>" + SecurityElement.Escape(externalId) + "</MusicBrainzAlbumArtistId>");
  396. }
  397. externalId = item.GetProviderId(MetadataProviders.MusicBrainzArtist);
  398. if (!string.IsNullOrEmpty(externalId))
  399. {
  400. builder.Append("<MusicBrainzArtistId>" + SecurityElement.Escape(externalId) + "</MusicBrainzArtistId>");
  401. }
  402. externalId = item.GetProviderId(MetadataProviders.MusicBrainzReleaseGroup);
  403. if (!string.IsNullOrEmpty(externalId))
  404. {
  405. builder.Append("<MusicBrainzReleaseGroupId>" + SecurityElement.Escape(externalId) + "</MusicBrainzReleaseGroupId>");
  406. }
  407. externalId = item.GetProviderId(MetadataProviders.Gamesdb);
  408. if (!string.IsNullOrEmpty(externalId))
  409. {
  410. builder.Append("<GamesDbId>" + SecurityElement.Escape(externalId) + "</GamesDbId>");
  411. }
  412. externalId = item.GetProviderId(MetadataProviders.TmdbCollection);
  413. if (!string.IsNullOrEmpty(externalId))
  414. {
  415. builder.Append("<TMDbCollectionId>" + SecurityElement.Escape(externalId) + "</TMDbCollectionId>");
  416. }
  417. externalId = item.GetProviderId(MetadataProviders.AudioDbArtist);
  418. if (!string.IsNullOrEmpty(externalId))
  419. {
  420. builder.Append("<AudioDbArtistId>" + SecurityElement.Escape(externalId) + "</AudioDbArtistId>");
  421. }
  422. externalId = item.GetProviderId(MetadataProviders.AudioDbAlbum);
  423. if (!string.IsNullOrEmpty(externalId))
  424. {
  425. builder.Append("<AudioDbAlbumId>" + SecurityElement.Escape(externalId) + "</AudioDbAlbumId>");
  426. }
  427. externalId = item.GetProviderId(MetadataProviders.TvRage);
  428. if (!string.IsNullOrEmpty(externalId))
  429. {
  430. builder.Append("<TVRageId>" + SecurityElement.Escape(externalId) + "</TVRageId>");
  431. }
  432. var hasTagline = item as IHasTaglines;
  433. if (hasTagline != null)
  434. {
  435. if (hasTagline.Taglines.Count > 0)
  436. {
  437. builder.Append("<Taglines>");
  438. foreach (var tagline in hasTagline.Taglines)
  439. {
  440. builder.Append("<Tagline>" + SecurityElement.Escape(tagline) + "</Tagline>");
  441. }
  442. builder.Append("</Taglines>");
  443. }
  444. }
  445. if (item.Genres.Count > 0)
  446. {
  447. builder.Append("<Genres>");
  448. foreach (var genre in item.Genres)
  449. {
  450. builder.Append("<Genre>" + SecurityElement.Escape(genre) + "</Genre>");
  451. }
  452. builder.Append("</Genres>");
  453. }
  454. if (item.Studios.Count > 0)
  455. {
  456. builder.Append("<Studios>");
  457. foreach (var studio in item.Studios)
  458. {
  459. builder.Append("<Studio>" + SecurityElement.Escape(studio) + "</Studio>");
  460. }
  461. builder.Append("</Studios>");
  462. }
  463. var hasTags = item as IHasTags;
  464. if (hasTags != null)
  465. {
  466. if (hasTags.Tags.Count > 0)
  467. {
  468. builder.Append("<Tags>");
  469. foreach (var tag in hasTags.Tags)
  470. {
  471. builder.Append("<Tag>" + SecurityElement.Escape(tag) + "</Tag>");
  472. }
  473. builder.Append("</Tags>");
  474. }
  475. }
  476. var hasKeywords = item as IHasKeywords;
  477. if (hasKeywords != null)
  478. {
  479. if (hasKeywords.Keywords.Count > 0)
  480. {
  481. builder.Append("<PlotKeywords>");
  482. foreach (var tag in hasKeywords.Keywords)
  483. {
  484. builder.Append("<PlotKeyword>" + SecurityElement.Escape(tag) + "</PlotKeyword>");
  485. }
  486. builder.Append("</PlotKeywords>");
  487. }
  488. }
  489. if (item.People.Count > 0)
  490. {
  491. builder.Append("<Persons>");
  492. foreach (var person in item.People)
  493. {
  494. builder.Append("<Person>");
  495. builder.Append("<Name>" + SecurityElement.Escape(person.Name) + "</Name>");
  496. builder.Append("<Type>" + SecurityElement.Escape(person.Type) + "</Type>");
  497. builder.Append("<Role>" + SecurityElement.Escape(person.Role) + "</Role>");
  498. if (person.SortOrder.HasValue)
  499. {
  500. builder.Append("<SortOrder>" + SecurityElement.Escape(person.SortOrder.Value.ToString(UsCulture)) + "</SortOrder>");
  501. }
  502. builder.Append("</Person>");
  503. }
  504. builder.Append("</Persons>");
  505. }
  506. var folder = item as BoxSet;
  507. if (folder != null)
  508. {
  509. AddCollectionItems(folder, builder);
  510. }
  511. }
  512. public static void AddChapters(Video item, StringBuilder builder, IItemRepository repository)
  513. {
  514. var chapters = repository.GetChapters(item.Id);
  515. builder.Append("<Chapters>");
  516. foreach (var chapter in chapters)
  517. {
  518. builder.Append("<Chapter>");
  519. builder.Append("<Name>" + SecurityElement.Escape(chapter.Name) + "</Name>");
  520. var time = TimeSpan.FromTicks(chapter.StartPositionTicks);
  521. var ms = Convert.ToInt64(time.TotalMilliseconds);
  522. builder.Append("<StartPositionMs>" + SecurityElement.Escape(ms.ToString(UsCulture)) + "</StartPositionMs>");
  523. builder.Append("</Chapter>");
  524. }
  525. builder.Append("</Chapters>");
  526. }
  527. /// <summary>
  528. /// Appends the media info.
  529. /// </summary>
  530. /// <typeparam name="T"></typeparam>
  531. public static void AddMediaInfo<T>(T item, StringBuilder builder, IItemRepository itemRepository)
  532. where T : BaseItem
  533. {
  534. var video = item as Video;
  535. if (video != null)
  536. {
  537. //AddChapters(video, builder, itemRepository);
  538. if (video.Video3DFormat.HasValue)
  539. {
  540. switch (video.Video3DFormat.Value)
  541. {
  542. case Video3DFormat.FullSideBySide:
  543. builder.Append("<Format3D>FSBS</Format3D>");
  544. break;
  545. case Video3DFormat.FullTopAndBottom:
  546. builder.Append("<Format3D>FTAB</Format3D>");
  547. break;
  548. case Video3DFormat.HalfSideBySide:
  549. builder.Append("<Format3D>HSBS</Format3D>");
  550. break;
  551. case Video3DFormat.HalfTopAndBottom:
  552. builder.Append("<Format3D>HTAB</Format3D>");
  553. break;
  554. }
  555. }
  556. }
  557. }
  558. public static void AddCollectionItems(Folder item, StringBuilder builder)
  559. {
  560. var items = item.LinkedChildren
  561. .Where(i => i.Type == LinkedChildType.Manual && !string.IsNullOrWhiteSpace(i.ItemName))
  562. .ToList();
  563. if (items.Count == 0)
  564. {
  565. return;
  566. }
  567. builder.Append("<CollectionItems>");
  568. foreach (var link in items)
  569. {
  570. builder.Append("<CollectionItem>");
  571. builder.Append("<Name>" + SecurityElement.Escape(link.ItemName) + "</Name>");
  572. builder.Append("<Type>" + SecurityElement.Escape(link.ItemType) + "</Type>");
  573. if (link.ItemYear.HasValue)
  574. {
  575. builder.Append("<Year>" + SecurityElement.Escape(link.ItemYear.Value.ToString(UsCulture)) + "</Year>");
  576. }
  577. builder.Append("</CollectionItem>");
  578. }
  579. builder.Append("</CollectionItems>");
  580. }
  581. }
  582. }