BaseItemExtensions.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading;
  4. using System.Threading.Tasks;
  5. using MediaBrowser.Controller.Library;
  6. using MediaBrowser.Controller.Providers;
  7. using MediaBrowser.Model.Entities;
  8. using MediaBrowser.Model.IO;
  9. using MediaBrowser.Model.Dto;
  10. using MediaBrowser.Model.Querying;
  11. namespace MediaBrowser.Controller.Entities
  12. {
  13. public static class BaseItemExtensions
  14. {
  15. /// <summary>
  16. /// Gets the image path.
  17. /// </summary>
  18. /// <param name="item">The item.</param>
  19. /// <param name="imageType">Type of the image.</param>
  20. /// <returns>System.String.</returns>
  21. public static string GetImagePath(this BaseItem item, ImageType imageType)
  22. {
  23. return item.GetImagePath(imageType, 0);
  24. }
  25. public static bool HasImage(this BaseItem item, ImageType imageType)
  26. {
  27. return item.HasImage(imageType, 0);
  28. }
  29. /// <summary>
  30. /// Sets the image path.
  31. /// </summary>
  32. /// <param name="item">The item.</param>
  33. /// <param name="imageType">Type of the image.</param>
  34. /// <param name="file">The file.</param>
  35. public static void SetImagePath(this BaseItem item, ImageType imageType, FileSystemMetadata file)
  36. {
  37. item.SetImagePath(imageType, 0, file);
  38. }
  39. /// <summary>
  40. /// Sets the image path.
  41. /// </summary>
  42. /// <param name="item">The item.</param>
  43. /// <param name="imageType">Type of the image.</param>
  44. /// <param name="file">The file.</param>
  45. public static void SetImagePath(this BaseItem item, ImageType imageType, string file)
  46. {
  47. if (file.StartsWith("http", System.StringComparison.OrdinalIgnoreCase))
  48. {
  49. item.SetImage(new ItemImageInfo
  50. {
  51. Path = file,
  52. Type = imageType
  53. }, 0);
  54. }
  55. else
  56. {
  57. item.SetImagePath(imageType, BaseItem.FileSystem.GetFileInfo(file));
  58. }
  59. }
  60. }
  61. }