TranscodeSetting.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using System;
  2. using System.Text.RegularExpressions;
  3. namespace MediaBrowser.Dlna.PlayTo.Configuration
  4. {
  5. public class TranscodeSettings
  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. public string MimeType { get; set; }
  22. /// <summary>
  23. /// The default transcoding settings
  24. /// </summary>
  25. private static readonly TranscodeSettings[] DefaultTranscodingSettings =
  26. {
  27. new TranscodeSettings { Container = "mkv", TargetContainer = "ts" },
  28. new TranscodeSettings { Container = "flac", TargetContainer = "mp3" },
  29. new TranscodeSettings { Container = "m4a", TargetContainer = "mp3" }
  30. };
  31. public static TranscodeSettings[] GetDefaultTranscodingSettings()
  32. {
  33. return DefaultTranscodingSettings;
  34. }
  35. /// <summary>
  36. /// Gets the profile settings.
  37. /// </summary>
  38. /// <param name="deviceProperties">The device properties.</param>
  39. /// <returns>The TranscodeSettings for the device</returns>
  40. public static TranscodeSettings[] GetProfileSettings(DeviceProperties deviceProperties)
  41. {
  42. foreach (var profile in PlayToConfiguration.Profiles)
  43. {
  44. if (!string.IsNullOrEmpty(profile.FriendlyName))
  45. {
  46. if (!Regex.IsMatch(deviceProperties.Name, profile.FriendlyName))
  47. continue;
  48. }
  49. if (!string.IsNullOrEmpty(profile.ModelNumber))
  50. {
  51. if (!Regex.IsMatch(deviceProperties.ModelNumber, profile.ModelNumber))
  52. continue;
  53. }
  54. if (!string.IsNullOrEmpty(profile.ModelName))
  55. {
  56. if (!Regex.IsMatch(deviceProperties.ModelName, profile.ModelName))
  57. continue;
  58. }
  59. deviceProperties.DisplayName = profile.Name;
  60. deviceProperties.ClientType = profile.ClientType;
  61. return profile.TranscodeSettings;
  62. }
  63. // Since we don't have alot of info about different devices we go down the safe
  64. // route abd use the default transcoding settings if no profile exist
  65. return GetDefaultTranscodingSettings();
  66. }
  67. }
  68. }