DlnaManager.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  1. using MediaBrowser.Common.Configuration;
  2. using MediaBrowser.Common.IO;
  3. using MediaBrowser.Controller.Dlna;
  4. using MediaBrowser.Model.Serialization;
  5. using System.Collections.Generic;
  6. using System.Text.RegularExpressions;
  7. namespace MediaBrowser.Dlna
  8. {
  9. public class DlnaManager : IDlnaManager
  10. {
  11. private IApplicationPaths _appPaths;
  12. private readonly IXmlSerializer _xmlSerializer;
  13. private readonly IFileSystem _fileSystem;
  14. public DlnaManager(IXmlSerializer xmlSerializer, IFileSystem fileSystem)
  15. {
  16. _xmlSerializer = xmlSerializer;
  17. _fileSystem = fileSystem;
  18. //GetProfiles();
  19. }
  20. public IEnumerable<DeviceProfile> GetProfiles()
  21. {
  22. var list = new List<DeviceProfile>();
  23. #region Samsung
  24. list.Add(new DeviceProfile
  25. {
  26. Name = "Samsung TV (B Series)",
  27. ClientType = "DLNA",
  28. FriendlyName = "^TV$",
  29. ModelNumber = @"1\.0",
  30. ModelName = "Samsung DTV DMR",
  31. TranscodingProfiles = new[]
  32. {
  33. new TranscodingProfile
  34. {
  35. Container = "mp3",
  36. Type = DlnaProfileType.Audio
  37. },
  38. new TranscodingProfile
  39. {
  40. Container = "ts",
  41. Type = DlnaProfileType.Video
  42. }
  43. },
  44. DirectPlayProfiles = new[]
  45. {
  46. new DirectPlayProfile
  47. {
  48. Containers = new[]{"mp3"},
  49. Type = DlnaProfileType.Audio
  50. },
  51. new DirectPlayProfile
  52. {
  53. Containers = new[]{"mkv"},
  54. MimeType = "x-mkv",
  55. Type = DlnaProfileType.Video
  56. },
  57. new DirectPlayProfile
  58. {
  59. Containers = new[]{"avi"},
  60. MimeType = "x-msvideo",
  61. Type = DlnaProfileType.Video
  62. },
  63. new DirectPlayProfile
  64. {
  65. Containers = new[]{"mp4"},
  66. Type = DlnaProfileType.Video
  67. }
  68. }
  69. });
  70. list.Add(new DeviceProfile
  71. {
  72. Name = "Samsung TV (E/F-series)",
  73. ClientType = "DLNA",
  74. FriendlyName = @"(^\[TV\][A-Z]{2}\d{2}(E|F)[A-Z]?\d{3,4}.*)|^\[TV\] Samsung",
  75. ModelNumber = @"(1\.0)|(AllShare1\.0)",
  76. TranscodingProfiles = new[]
  77. {
  78. new TranscodingProfile
  79. {
  80. Container = "mp3",
  81. Type = DlnaProfileType.Audio
  82. },
  83. new TranscodingProfile
  84. {
  85. Container = "ts",
  86. Type = DlnaProfileType.Video
  87. }
  88. },
  89. DirectPlayProfiles = new[]
  90. {
  91. new DirectPlayProfile
  92. {
  93. Containers = new[]{"mp3"},
  94. Type = DlnaProfileType.Audio
  95. },
  96. new DirectPlayProfile
  97. {
  98. Containers = new[]{"mkv"},
  99. MimeType = "x-mkv",
  100. Type = DlnaProfileType.Video
  101. },
  102. new DirectPlayProfile
  103. {
  104. Containers = new[]{"avi"},
  105. MimeType = "x-msvideo",
  106. Type = DlnaProfileType.Video
  107. },
  108. new DirectPlayProfile
  109. {
  110. Containers = new[]{"mp4"},
  111. Type = DlnaProfileType.Video
  112. }
  113. }
  114. });
  115. list.Add(new DeviceProfile
  116. {
  117. Name = "Samsung TV (C/D-series)",
  118. ClientType = "DLNA",
  119. FriendlyName = @"(^TV-\d{2}C\d{3}.*)|(^\[TV\][A-Z]{2}\d{2}(D)[A-Z]?\d{3,4}.*)|^\[TV\] Samsung",
  120. ModelNumber = @"(1\.0)|(AllShare1\.0)",
  121. TranscodingProfiles = new[]
  122. {
  123. new TranscodingProfile
  124. {
  125. Container = "mp3",
  126. Type = DlnaProfileType.Audio
  127. },
  128. new TranscodingProfile
  129. {
  130. Container = "ts",
  131. Type = DlnaProfileType.Video
  132. }
  133. },
  134. DirectPlayProfiles = new[]
  135. {
  136. new DirectPlayProfile
  137. {
  138. Containers = new[]{"mp3"},
  139. Type = DlnaProfileType.Audio
  140. },
  141. new DirectPlayProfile
  142. {
  143. Containers = new[]{"mkv"},
  144. MimeType = "x-mkv",
  145. Type = DlnaProfileType.Video
  146. },
  147. new DirectPlayProfile
  148. {
  149. Containers = new[]{"avi"},
  150. MimeType = "x-msvideo",
  151. Type = DlnaProfileType.Video
  152. },
  153. new DirectPlayProfile
  154. {
  155. Containers = new[]{"mp4"},
  156. Type = DlnaProfileType.Video
  157. }
  158. }
  159. });
  160. #endregion
  161. #region Xbox
  162. list.Add(new DeviceProfile
  163. {
  164. Name = "Xbox 360",
  165. ClientType = "DLNA",
  166. ModelName = "Xbox 360",
  167. TranscodingProfiles = new[]
  168. {
  169. new TranscodingProfile
  170. {
  171. Container = "mp3",
  172. Type = DlnaProfileType.Audio
  173. },
  174. new TranscodingProfile
  175. {
  176. Container = "ts",
  177. Type = DlnaProfileType.Video
  178. }
  179. },
  180. DirectPlayProfiles = new[]
  181. {
  182. new DirectPlayProfile
  183. {
  184. Containers = new[]{"mp3"},
  185. Type = DlnaProfileType.Audio
  186. },
  187. new DirectPlayProfile
  188. {
  189. Containers = new[]{"avi"},
  190. MimeType = "avi",
  191. Type = DlnaProfileType.Video
  192. }
  193. }
  194. });
  195. list.Add(new DeviceProfile
  196. {
  197. Name = "Xbox One",
  198. ModelName = "Xbox One",
  199. ClientType = "DLNA",
  200. FriendlyName = "Xbox-SystemOS",
  201. TranscodingProfiles = new[]
  202. {
  203. new TranscodingProfile
  204. {
  205. Container = "mp3",
  206. Type = DlnaProfileType.Audio
  207. },
  208. new TranscodingProfile
  209. {
  210. Container = "ts",
  211. Type = DlnaProfileType.Video
  212. }
  213. },
  214. DirectPlayProfiles = new[]
  215. {
  216. new DirectPlayProfile
  217. {
  218. Containers = new[]{"mp3"},
  219. Type = DlnaProfileType.Audio
  220. },
  221. new DirectPlayProfile
  222. {
  223. Containers = new[]{"avi"},
  224. MimeType = "x-msvideo",
  225. Type = DlnaProfileType.Video
  226. }
  227. }
  228. });
  229. #endregion
  230. #region Sony
  231. list.Add(new DeviceProfile
  232. {
  233. Name = "Sony Bravia (2012)",
  234. ClientType = "DLNA",
  235. FriendlyName = @"BRAVIA KDL-\d{2}[A-Z]X\d5(\d|G).*",
  236. TranscodingProfiles = new[]
  237. {
  238. new TranscodingProfile
  239. {
  240. Container = "mp3",
  241. Type = DlnaProfileType.Audio
  242. },
  243. new TranscodingProfile
  244. {
  245. Container = "ts",
  246. Type = DlnaProfileType.Video
  247. }
  248. },
  249. DirectPlayProfiles = new[]
  250. {
  251. new DirectPlayProfile
  252. {
  253. Containers = new[]{"mp3"},
  254. Type = DlnaProfileType.Audio
  255. },
  256. new DirectPlayProfile
  257. {
  258. Containers = new[]{"avi"},
  259. Type = DlnaProfileType.Video,
  260. MimeType = "avi"
  261. }
  262. }
  263. });
  264. list.Add(new DeviceProfile
  265. {
  266. Name = "Sony Bravia (2013)",
  267. ClientType = "DLNA",
  268. FriendlyName = @"BRAVIA (KDL-\d{2}W[689]\d{2}A.*)|(KD-\d{2}X9\d{3}A.*)",
  269. TranscodingProfiles = new[]
  270. {
  271. new TranscodingProfile
  272. {
  273. Container = "mp3",
  274. Type = DlnaProfileType.Audio
  275. },
  276. new TranscodingProfile
  277. {
  278. Container = "ts",
  279. Type = DlnaProfileType.Video,
  280. MimeType = "mpeg"
  281. }
  282. },
  283. DirectPlayProfiles = new[]
  284. {
  285. new DirectPlayProfile
  286. {
  287. Containers = new[]{"mp3"},
  288. Type = DlnaProfileType.Audio
  289. },
  290. new DirectPlayProfile
  291. {
  292. Containers = new[]{"wma"},
  293. Type = DlnaProfileType.Audio,
  294. MimeType = "x-ms-wma"
  295. },
  296. new DirectPlayProfile
  297. {
  298. Containers = new[]{"avi"},
  299. Type = DlnaProfileType.Video,
  300. MimeType = "avi"
  301. },
  302. new DirectPlayProfile
  303. {
  304. Containers = new[]{"mp4"},
  305. Type = DlnaProfileType.Video,
  306. MimeType = "mp4"
  307. }
  308. }
  309. });
  310. #endregion
  311. #region Panasonic
  312. list.Add(new DeviceProfile
  313. {
  314. //Panasonic Viera (2011|2012) Without AVI Support
  315. Name = "Panasonic Viera E/S/ST/VT (2011)",
  316. ClientType = "DLNA",
  317. FriendlyName = @"(VIERA (E|S)T?(3|5)0?.*)|(VIERA VT30.*)",
  318. Manufacturer = "Panasonic",
  319. TranscodingProfiles = new[]
  320. {
  321. new TranscodingProfile
  322. {
  323. Container = "mp3",
  324. Type = DlnaProfileType.Audio
  325. },
  326. new TranscodingProfile
  327. {
  328. Container = "ts",
  329. Type = DlnaProfileType.Video
  330. }
  331. },
  332. DirectPlayProfiles = new[]
  333. {
  334. new DirectPlayProfile
  335. {
  336. Containers = new[]{"mp3"},
  337. Type = DlnaProfileType.Audio
  338. },
  339. new DirectPlayProfile
  340. {
  341. Containers = new[]{"mkv"},
  342. Type = DlnaProfileType.Video
  343. }
  344. }
  345. });
  346. list.Add(new DeviceProfile
  347. {
  348. //Panasonic Viera (2011|2012) With AVI Support
  349. Name = "Panasonic Viera G/GT/DT/UT/VT (2011/2012)",
  350. ClientType = "DLNA",
  351. FriendlyName = @"(VIERA (G|D|U)T?(3|5)0?.*)|(VIERA VT50.*)",
  352. Manufacturer = "Panasonic",
  353. TranscodingProfiles = new[]
  354. {
  355. new TranscodingProfile
  356. {
  357. Container = "mp3",
  358. Type = DlnaProfileType.Audio
  359. },
  360. new TranscodingProfile
  361. {
  362. Container = "ts",
  363. Type = DlnaProfileType.Video
  364. }
  365. },
  366. DirectPlayProfiles = new[]
  367. {
  368. new DirectPlayProfile
  369. {
  370. Containers = new[]{"mp3"},
  371. Type = DlnaProfileType.Audio
  372. },
  373. new DirectPlayProfile
  374. {
  375. Containers = new[]{"mkv"},
  376. Type = DlnaProfileType.Video
  377. },
  378. new DirectPlayProfile
  379. {
  380. Containers = new[]{"avi"},
  381. Type = DlnaProfileType.Video ,
  382. MimeType="divx"
  383. }
  384. }
  385. });
  386. #endregion
  387. //WDTV does not need any transcoding of the formats we support statically
  388. list.Add(new DeviceProfile
  389. {
  390. Name = "Philips (2010-)",
  391. FriendlyName = ".*PHILIPS.*",
  392. ClientType = "DLNA",
  393. ModelName = "WD TV HD Live",
  394. DirectPlayProfiles = new[]
  395. {
  396. new DirectPlayProfile
  397. {
  398. Containers = new[]{"mp3", "wma"},
  399. Type = DlnaProfileType.Audio
  400. },
  401. new DirectPlayProfile
  402. {
  403. Containers = new[]{"avi"},
  404. Type = DlnaProfileType.Video,
  405. MimeType = "avi"
  406. },
  407. new DirectPlayProfile
  408. {
  409. Containers = new[]{"mkv"},
  410. Type = DlnaProfileType.Video,
  411. MimeType = "x-matroska"
  412. }
  413. }
  414. });
  415. //WDTV does not need any transcoding of the formats we support statically
  416. list.Add(new DeviceProfile
  417. {
  418. Name = "WDTV Live",
  419. ClientType = "DLNA",
  420. ModelName = "WD TV HD Live",
  421. DirectPlayProfiles = new[]
  422. {
  423. new DirectPlayProfile
  424. {
  425. Containers = new[]{"mp3", "flac", "m4a", "wma"},
  426. Type = DlnaProfileType.Audio
  427. },
  428. new DirectPlayProfile
  429. {
  430. Containers = new[]{"avi", "mp4", "mkv", "ts"},
  431. Type = DlnaProfileType.Video
  432. }
  433. }
  434. });
  435. list.Add(new DeviceProfile
  436. {
  437. //Linksys DMA2100us does not need any transcoding of the formats we support statically
  438. Name = "Linksys DMA2100",
  439. ClientType = "DLNA",
  440. ModelName = "DMA2100us",
  441. DirectPlayProfiles = new[]
  442. {
  443. new DirectPlayProfile
  444. {
  445. Containers = new[]{"mp3", "flac", "m4a", "wma"},
  446. Type = DlnaProfileType.Audio
  447. },
  448. new DirectPlayProfile
  449. {
  450. Containers = new[]{"avi", "mp4", "mkv", "ts"},
  451. Type = DlnaProfileType.Video
  452. }
  453. }
  454. });
  455. list.Add(new DeviceProfile
  456. {
  457. Name = "Denon AVR",
  458. FriendlyName = @"Denon:\[AVR:.*",
  459. Manufacturer = "Denon",
  460. ClientType = "DLNA",
  461. DirectPlayProfiles = new[]
  462. {
  463. new DirectPlayProfile
  464. {
  465. Containers = new[]{"mp3", "flac", "m4a", "wma"},
  466. Type = DlnaProfileType.Audio
  467. },
  468. }
  469. });
  470. foreach (var item in list)
  471. {
  472. //_xmlSerializer.SerializeToFile(item, "d:\\" + _fileSystem.GetValidFilename(item.Name));
  473. }
  474. return list;
  475. }
  476. public DeviceProfile GetDefaultProfile()
  477. {
  478. return new DeviceProfile
  479. {
  480. TranscodingProfiles = new[]
  481. {
  482. new TranscodingProfile
  483. {
  484. Container = "mp3",
  485. Type = DlnaProfileType.Audio
  486. },
  487. new TranscodingProfile
  488. {
  489. Container = "ts",
  490. Type = DlnaProfileType.Video
  491. }
  492. },
  493. DirectPlayProfiles = new[]
  494. {
  495. new DirectPlayProfile
  496. {
  497. Containers = new[]{"mp3", "wma"},
  498. Type = DlnaProfileType.Audio
  499. },
  500. new DirectPlayProfile
  501. {
  502. Containers = new[]{"avi", "mp4"},
  503. Type = DlnaProfileType.Video
  504. }
  505. }
  506. };
  507. }
  508. public DeviceProfile GetProfile(string friendlyName, string modelName, string modelNumber, string manufacturer)
  509. {
  510. foreach (var profile in GetProfiles())
  511. {
  512. if (!string.IsNullOrEmpty(profile.FriendlyName))
  513. {
  514. if (!Regex.IsMatch(friendlyName, profile.FriendlyName))
  515. continue;
  516. }
  517. if (!string.IsNullOrEmpty(profile.ModelNumber))
  518. {
  519. if (!Regex.IsMatch(modelNumber, profile.ModelNumber))
  520. continue;
  521. }
  522. if (!string.IsNullOrEmpty(profile.ModelName))
  523. {
  524. if (!Regex.IsMatch(modelName, profile.ModelName))
  525. continue;
  526. }
  527. if (!string.IsNullOrEmpty(profile.Manufacturer))
  528. {
  529. if (!Regex.IsMatch(manufacturer, profile.Manufacturer))
  530. continue;
  531. }
  532. return profile;
  533. }
  534. return GetDefaultProfile();
  535. }
  536. }
  537. }