TranscodeSetting.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using System;
  2. using System.Text.RegularExpressions;
  3. namespace MediaBrowser.Dlna.PlayTo.Configuration
  4. {
  5. public class TranscodeSetting
  6. {
  7. /// <summary>
  8. /// Gets or sets the container.
  9. /// </summary>
  10. /// <value>
  11. /// The container.
  12. /// </value>
  13. public string Container { get; set; }
  14. /// <summary>
  15. /// Gets or sets the target container.
  16. /// </summary>
  17. /// <value>
  18. /// The target container.
  19. /// </value>
  20. public string TargetContainer { get; set; }
  21. /// <summary>
  22. /// Gets or sets the Mimetype to enforce
  23. /// </summary>
  24. /// <value>
  25. /// The MimeType.
  26. /// </value>
  27. public string MimeType { get; set; }
  28. /// <summary>
  29. /// The default transcoding settings
  30. /// </summary>
  31. private static readonly TranscodeSetting[] DefaultTranscodingSettings =
  32. {
  33. new TranscodeSetting { Container = "mkv", TargetContainer = "ts" },
  34. new TranscodeSetting { Container = "flac", TargetContainer = "mp3" },
  35. new TranscodeSetting { Container = "m4a", TargetContainer = "mp3" }
  36. };
  37. public static TranscodeSetting[] GetDefaultTranscodingSettings()
  38. {
  39. return DefaultTranscodingSettings;
  40. }
  41. /// <summary>
  42. /// Gets the profile settings.
  43. /// </summary>
  44. /// <param name="deviceProperties">The device properties.</param>
  45. /// <returns>The TranscodeSettings for the device</returns>
  46. public static TranscodeSetting[] GetProfileSettings(DeviceProperties deviceProperties)
  47. {
  48. foreach (var profile in PlayToConfiguration.Instance.Profiles)
  49. {
  50. if (!string.IsNullOrEmpty(profile.FriendlyName))
  51. {
  52. if (!Regex.IsMatch(deviceProperties.Name, profile.FriendlyName))
  53. continue;
  54. }
  55. if (!string.IsNullOrEmpty(profile.ModelNumber))
  56. {
  57. if (!Regex.IsMatch(deviceProperties.ModelNumber, profile.ModelNumber))
  58. continue;
  59. }
  60. if (!string.IsNullOrEmpty(profile.ModelName))
  61. {
  62. if (!Regex.IsMatch(deviceProperties.ModelName, profile.ModelName))
  63. continue;
  64. }
  65. deviceProperties.DisplayName = profile.Name;
  66. deviceProperties.ClientType = profile.ClientType;
  67. return profile.TranscodeSettings;
  68. }
  69. // Since we don't have alot of info about different devices we go down the safe
  70. // route abd use the default transcoding settings if no profile exist
  71. return GetDefaultTranscodingSettings();
  72. }
  73. }
  74. }