NamingOptions.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706
  1. #pragma warning disable CS1591
  2. #pragma warning disable SA1600
  3. using System;
  4. using System.Linq;
  5. using System.Text.RegularExpressions;
  6. using Emby.Naming.Video;
  7. using MediaBrowser.Model.Entities;
  8. namespace Emby.Naming.Common
  9. {
  10. public class NamingOptions
  11. {
  12. public string[] AudioFileExtensions { get; set; }
  13. public string[] AlbumStackingPrefixes { get; set; }
  14. public string[] SubtitleFileExtensions { get; set; }
  15. public char[] SubtitleFlagDelimiters { get; set; }
  16. public string[] SubtitleForcedFlags { get; set; }
  17. public string[] SubtitleDefaultFlags { get; set; }
  18. public EpisodeExpression[] EpisodeExpressions { get; set; }
  19. public string[] EpisodeWithoutSeasonExpressions { get; set; }
  20. public string[] EpisodeMultiPartExpressions { get; set; }
  21. public string[] VideoFileExtensions { get; set; }
  22. public string[] StubFileExtensions { get; set; }
  23. public string[] AudioBookPartsExpressions { get; set; }
  24. public StubTypeRule[] StubTypes { get; set; }
  25. public char[] VideoFlagDelimiters { get; set; }
  26. public Format3DRule[] Format3DRules { get; set; }
  27. public string[] VideoFileStackingExpressions { get; set; }
  28. public string[] CleanDateTimes { get; set; }
  29. public string[] CleanStrings { get; set; }
  30. public EpisodeExpression[] MultipleEpisodeExpressions { get; set; }
  31. public ExtraRule[] VideoExtraRules { get; set; }
  32. public NamingOptions()
  33. {
  34. VideoFileExtensions = new[]
  35. {
  36. ".m4v",
  37. ".3gp",
  38. ".nsv",
  39. ".ts",
  40. ".ty",
  41. ".strm",
  42. ".rm",
  43. ".rmvb",
  44. ".ifo",
  45. ".mov",
  46. ".qt",
  47. ".divx",
  48. ".xvid",
  49. ".bivx",
  50. ".vob",
  51. ".nrg",
  52. ".img",
  53. ".iso",
  54. ".pva",
  55. ".wmv",
  56. ".asf",
  57. ".asx",
  58. ".ogm",
  59. ".m2v",
  60. ".avi",
  61. ".bin",
  62. ".dvr-ms",
  63. ".mpg",
  64. ".mpeg",
  65. ".mp4",
  66. ".mkv",
  67. ".avc",
  68. ".vp3",
  69. ".svq3",
  70. ".nuv",
  71. ".viv",
  72. ".dv",
  73. ".fli",
  74. ".flv",
  75. ".001",
  76. ".tp"
  77. };
  78. VideoFlagDelimiters = new[]
  79. {
  80. '(',
  81. ')',
  82. '-',
  83. '.',
  84. '_',
  85. '[',
  86. ']'
  87. };
  88. StubFileExtensions = new[]
  89. {
  90. ".disc"
  91. };
  92. StubTypes = new[]
  93. {
  94. new StubTypeRule
  95. {
  96. StubType = "dvd",
  97. Token = "dvd"
  98. },
  99. new StubTypeRule
  100. {
  101. StubType = "hddvd",
  102. Token = "hddvd"
  103. },
  104. new StubTypeRule
  105. {
  106. StubType = "bluray",
  107. Token = "bluray"
  108. },
  109. new StubTypeRule
  110. {
  111. StubType = "bluray",
  112. Token = "brrip"
  113. },
  114. new StubTypeRule
  115. {
  116. StubType = "bluray",
  117. Token = "bd25"
  118. },
  119. new StubTypeRule
  120. {
  121. StubType = "bluray",
  122. Token = "bd50"
  123. },
  124. new StubTypeRule
  125. {
  126. StubType = "vhs",
  127. Token = "vhs"
  128. },
  129. new StubTypeRule
  130. {
  131. StubType = "tv",
  132. Token = "HDTV"
  133. },
  134. new StubTypeRule
  135. {
  136. StubType = "tv",
  137. Token = "PDTV"
  138. },
  139. new StubTypeRule
  140. {
  141. StubType = "tv",
  142. Token = "DSR"
  143. }
  144. };
  145. VideoFileStackingExpressions = new[]
  146. {
  147. "(.*?)([ _.-]*(?:cd|dvd|p(?:ar)?t|dis[ck])[ _.-]*[0-9]+)(.*?)(\\.[^.]+)$",
  148. "(.*?)([ _.-]*(?:cd|dvd|p(?:ar)?t|dis[ck])[ _.-]*[a-d])(.*?)(\\.[^.]+)$",
  149. "(.*?)([ ._-]*[a-d])(.*?)(\\.[^.]+)$"
  150. };
  151. CleanDateTimes = new[]
  152. {
  153. @"(.+[^_\,\.\(\)\[\]\-])[_\.\(\)\[\]\-](\d{4})([ _\,\.\(\)\[\]\-][^\d]|).*(\d{4})*"
  154. };
  155. CleanStrings = new[]
  156. {
  157. @"[ _\,\.\(\)\[\]\-](ac3|dts|custom|dc|divx|divx5|dsr|dsrip|dutch|dvd|dvdrip|dvdscr|dvdscreener|screener|dvdivx|cam|fragment|fs|hdtv|hdrip|hdtvrip|internal|limited|multisubs|ntsc|ogg|ogm|pal|pdtv|proper|repack|rerip|retail|cd[1-9]|r3|r5|bd5|se|svcd|swedish|german|read.nfo|nfofix|unrated|ws|telesync|ts|telecine|tc|brrip|bdrip|480p|480i|576p|576i|720p|720i|1080p|1080i|2160p|hrhd|hrhdtv|hddvd|bluray|x264|h264|xvid|xvidvd|xxx|www.www|\[.*\])([ _\,\.\(\)\[\]\-]|$)",
  158. @"[ _\,\.\(\)\[\]\-](3d|sbs|tab|hsbs|htab|mvc|\[.*\])([ _\,\.\(\)\[\]\-]|$)",
  159. @"(\[.*\])"
  160. };
  161. SubtitleFileExtensions = new[]
  162. {
  163. ".srt",
  164. ".ssa",
  165. ".ass",
  166. ".sub"
  167. };
  168. SubtitleFlagDelimiters = new[]
  169. {
  170. '.'
  171. };
  172. SubtitleForcedFlags = new[]
  173. {
  174. "foreign",
  175. "forced"
  176. };
  177. SubtitleDefaultFlags = new[]
  178. {
  179. "default"
  180. };
  181. AlbumStackingPrefixes = new[]
  182. {
  183. "disc",
  184. "cd",
  185. "disk",
  186. "vol",
  187. "volume"
  188. };
  189. AudioFileExtensions = new[]
  190. {
  191. ".nsv",
  192. ".m4a",
  193. ".flac",
  194. ".aac",
  195. ".strm",
  196. ".pls",
  197. ".rm",
  198. ".mpa",
  199. ".wav",
  200. ".wma",
  201. ".ogg",
  202. ".opus",
  203. ".mp3",
  204. ".mp2",
  205. ".mod",
  206. ".amf",
  207. ".669",
  208. ".dmf",
  209. ".dsm",
  210. ".far",
  211. ".gdm",
  212. ".imf",
  213. ".it",
  214. ".m15",
  215. ".med",
  216. ".okt",
  217. ".s3m",
  218. ".stm",
  219. ".sfx",
  220. ".ult",
  221. ".uni",
  222. ".xm",
  223. ".sid",
  224. ".ac3",
  225. ".dts",
  226. ".cue",
  227. ".aif",
  228. ".aiff",
  229. ".ape",
  230. ".mac",
  231. ".mpc",
  232. ".mp+",
  233. ".mpp",
  234. ".shn",
  235. ".wv",
  236. ".nsf",
  237. ".spc",
  238. ".gym",
  239. ".adplug",
  240. ".adx",
  241. ".dsp",
  242. ".adp",
  243. ".ymf",
  244. ".ast",
  245. ".afc",
  246. ".hps",
  247. ".xsp",
  248. ".acc",
  249. ".m4b",
  250. ".oga",
  251. ".dsf",
  252. ".mka"
  253. };
  254. EpisodeExpressions = new[]
  255. {
  256. // *** Begin Kodi Standard Naming
  257. // <!-- foo.s01.e01, foo.s01_e01, S01E02 foo, S01 - E02 -->
  258. new EpisodeExpression(@".*(\\|\/)(?<seriesname>((?![Ss]([0-9]+)[][ ._-]*[Ee]([0-9]+))[^\\\/])*)?[Ss](?<seasonnumber>[0-9]+)[][ ._-]*[Ee](?<epnumber>[0-9]+)([^\\/]*)$")
  259. {
  260. IsNamed = true
  261. },
  262. // <!-- foo.ep01, foo.EP_01 -->
  263. new EpisodeExpression(@"[\._ -]()[Ee][Pp]_?([0-9]+)([^\\/]*)$"),
  264. new EpisodeExpression("([0-9]{4})[\\.-]([0-9]{2})[\\.-]([0-9]{2})", true)
  265. {
  266. DateTimeFormats = new[]
  267. {
  268. "yyyy.MM.dd",
  269. "yyyy-MM-dd",
  270. "yyyy_MM_dd"
  271. }
  272. },
  273. new EpisodeExpression("([0-9]{2})[\\.-]([0-9]{2})[\\.-]([0-9]{4})", true)
  274. {
  275. DateTimeFormats = new[]
  276. {
  277. "dd.MM.yyyy",
  278. "dd-MM-yyyy",
  279. "dd_MM_yyyy"
  280. }
  281. },
  282. // This isn't a Kodi naming rule, but the expression below causes false positives,
  283. // so we make sure this one gets tested first.
  284. // "Foo Bar 889"
  285. new EpisodeExpression(@".*[\\\/](?![Ee]pisode)(?<seriesname>[\w\s]+?)\s(?<epnumber>\d{1,3})(-(?<endingepnumber>\d{2,3}))*[^\\\/]*$")
  286. {
  287. IsNamed = true
  288. },
  289. new EpisodeExpression("[\\\\/\\._ \\[\\(-]([0-9]+)x([0-9]+(?:(?:[a-i]|\\.[1-9])(?![0-9]))?)([^\\\\/]*)$")
  290. {
  291. SupportsAbsoluteEpisodeNumbers = true
  292. },
  293. new EpisodeExpression(@"[\\\\/\\._ -](?<seriesname>(?![0-9]+[0-9][0-9])([^\\\/])*)[\\\\/\\._ -](?<seasonnumber>[0-9]+)(?<epnumber>[0-9][0-9](?:(?:[a-i]|\\.[1-9])(?![0-9]))?)([\\._ -][^\\\\/]*)$")
  294. {
  295. IsOptimistic = true,
  296. IsNamed = true,
  297. SupportsAbsoluteEpisodeNumbers = false
  298. },
  299. new EpisodeExpression("[\\/._ -]p(?:ar)?t[_. -]()([ivx]+|[0-9]+)([._ -][^\\/]*)$")
  300. {
  301. SupportsAbsoluteEpisodeNumbers = true
  302. },
  303. // *** End Kodi Standard Naming
  304.                 // [bar] Foo - 1 [baz]
  305. new EpisodeExpression(@".*?(\[.*?\])+.*?(?<seriesname>[\w\s]+?)[-\s_]+(?<epnumber>\d+).*$")
  306. {
  307. IsNamed = true
  308. },
  309. new EpisodeExpression(@".*(\\|\/)[sS]?(?<seasonnumber>\d+)[xX](?<epnumber>\d+)[^\\\/]*$")
  310. {
  311. IsNamed = true
  312. },
  313. new EpisodeExpression(@".*(\\|\/)[sS](?<seasonnumber>\d+)[x,X]?[eE](?<epnumber>\d+)[^\\\/]*$")
  314. {
  315. IsNamed = true
  316. },
  317. new EpisodeExpression(@".*(\\|\/)(?<seriesname>((?![sS]?\d{1,4}[xX]\d{1,3})[^\\\/])*)?([sS]?(?<seasonnumber>\d{1,4})[xX](?<epnumber>\d+))[^\\\/]*$")
  318. {
  319. IsNamed = true
  320. },
  321. new EpisodeExpression(@".*(\\|\/)(?<seriesname>[^\\\/]*)[sS](?<seasonnumber>\d{1,4})[xX\.]?[eE](?<epnumber>\d+)[^\\\/]*$")
  322. {
  323. IsNamed = true
  324. },
  325. // "01.avi"
  326. new EpisodeExpression(@".*[\\\/](?<epnumber>\d+)(-(?<endingepnumber>\d+))*\.\w+$")
  327. {
  328. IsOptimistic = true,
  329. IsNamed = true
  330. },
  331. // "1-12 episode title"
  332. new EpisodeExpression(@"([0-9]+)-([0-9]+)"),
  333. // "01 - blah.avi", "01-blah.avi"
  334. new EpisodeExpression(@".*(\\|\/)(?<epnumber>\d{1,3})(-(?<endingepnumber>\d{2,3}))*\s?-\s?[^\\\/]*$")
  335. {
  336. IsOptimistic = true,
  337. IsNamed = true
  338. },
  339. // "01.blah.avi"
  340. new EpisodeExpression(@".*(\\|\/)(?<epnumber>\d{1,3})(-(?<endingepnumber>\d{2,3}))*\.[^\\\/]+$")
  341. {
  342. IsOptimistic = true,
  343. IsNamed = true
  344. },
  345. // "blah - 01.avi", "blah 2 - 01.avi", "blah - 01 blah.avi", "blah 2 - 01 blah", "blah - 01 - blah.avi", "blah 2 - 01 - blah"
  346. new EpisodeExpression(@".*[\\\/][^\\\/]* - (?<epnumber>\d{1,3})(-(?<endingepnumber>\d{2,3}))*[^\\\/]*$")
  347. {
  348. IsOptimistic = true,
  349. IsNamed = true
  350. },
  351. // "01 episode title.avi"
  352. new EpisodeExpression(@"[Ss]eason[\._ ](?<seasonnumber>[0-9]+)[\\\/](?<epnumber>\d{1,3})([^\\\/]*)$")
  353. {
  354. IsOptimistic = true,
  355. IsNamed = true
  356. },
  357. // "Episode 16", "Episode 16 - Title"
  358. new EpisodeExpression(@".*[\\\/][^\\\/]* (?<epnumber>\d{1,3})(-(?<endingepnumber>\d{2,3}))*[^\\\/]*$")
  359. {
  360. IsOptimistic = true,
  361. IsNamed = true
  362. }
  363. };
  364. EpisodeWithoutSeasonExpressions = new[]
  365. {
  366. @"[/\._ \-]()([0-9]+)(-[0-9]+)?"
  367. };
  368. EpisodeMultiPartExpressions = new[]
  369. {
  370. @"^[-_ex]+([0-9]+(?:(?:[a-i]|\\.[1-9])(?![0-9]))?)"
  371. };
  372. VideoExtraRules = new[]
  373. {
  374. new ExtraRule
  375. {
  376. ExtraType = ExtraType.Trailer,
  377. RuleType = ExtraRuleType.Filename,
  378. Token = "trailer",
  379. MediaType = MediaType.Video
  380. },
  381. new ExtraRule
  382. {
  383. ExtraType = ExtraType.Trailer,
  384. RuleType = ExtraRuleType.Suffix,
  385. Token = "-trailer",
  386. MediaType = MediaType.Video
  387. },
  388. new ExtraRule
  389. {
  390. ExtraType = ExtraType.Trailer,
  391. RuleType = ExtraRuleType.Suffix,
  392. Token = ".trailer",
  393. MediaType = MediaType.Video
  394. },
  395. new ExtraRule
  396. {
  397. ExtraType = ExtraType.Trailer,
  398. RuleType = ExtraRuleType.Suffix,
  399. Token = "_trailer",
  400. MediaType = MediaType.Video
  401. },
  402. new ExtraRule
  403. {
  404. ExtraType = ExtraType.Trailer,
  405. RuleType = ExtraRuleType.Suffix,
  406. Token = " trailer",
  407. MediaType = MediaType.Video
  408. },
  409. new ExtraRule
  410. {
  411. ExtraType = ExtraType.Sample,
  412. RuleType = ExtraRuleType.Filename,
  413. Token = "sample",
  414. MediaType = MediaType.Video
  415. },
  416. new ExtraRule
  417. {
  418. ExtraType = ExtraType.Sample,
  419. RuleType = ExtraRuleType.Suffix,
  420. Token = "-sample",
  421. MediaType = MediaType.Video
  422. },
  423. new ExtraRule
  424. {
  425. ExtraType = ExtraType.Sample,
  426. RuleType = ExtraRuleType.Suffix,
  427. Token = ".sample",
  428. MediaType = MediaType.Video
  429. },
  430. new ExtraRule
  431. {
  432. ExtraType = ExtraType.Sample,
  433. RuleType = ExtraRuleType.Suffix,
  434. Token = "_sample",
  435. MediaType = MediaType.Video
  436. },
  437. new ExtraRule
  438. {
  439. ExtraType = ExtraType.Sample,
  440. RuleType = ExtraRuleType.Suffix,
  441. Token = " sample",
  442. MediaType = MediaType.Video
  443. },
  444. new ExtraRule
  445. {
  446. ExtraType = ExtraType.ThemeSong,
  447. RuleType = ExtraRuleType.Filename,
  448. Token = "theme",
  449. MediaType = MediaType.Audio
  450. },
  451. new ExtraRule
  452. {
  453. ExtraType = ExtraType.Scene,
  454. RuleType = ExtraRuleType.Suffix,
  455. Token = "-scene",
  456. MediaType = MediaType.Video
  457. },
  458. new ExtraRule
  459. {
  460. ExtraType = ExtraType.Clip,
  461. RuleType = ExtraRuleType.Suffix,
  462. Token = "-clip",
  463. MediaType = MediaType.Video
  464. },
  465. new ExtraRule
  466. {
  467. ExtraType = ExtraType.Interview,
  468. RuleType = ExtraRuleType.Suffix,
  469. Token = "-interview",
  470. MediaType = MediaType.Video
  471. },
  472. new ExtraRule
  473. {
  474. ExtraType = ExtraType.BehindTheScenes,
  475. RuleType = ExtraRuleType.Suffix,
  476. Token = "-behindthescenes",
  477. MediaType = MediaType.Video
  478. },
  479. new ExtraRule
  480. {
  481. ExtraType = ExtraType.DeletedScene,
  482. RuleType = ExtraRuleType.Suffix,
  483. Token = "-deleted",
  484. MediaType = MediaType.Video
  485. },
  486. new ExtraRule
  487. {
  488. ExtraType = ExtraType.Clip,
  489. RuleType = ExtraRuleType.Suffix,
  490. Token = "-featurette",
  491. MediaType = MediaType.Video
  492. },
  493. new ExtraRule
  494. {
  495. ExtraType = ExtraType.Clip,
  496. RuleType = ExtraRuleType.Suffix,
  497. Token = "-short",
  498. MediaType = MediaType.Video
  499. }
  500. };
  501. Format3DRules = new[]
  502. {
  503. // Kodi rules:
  504. new Format3DRule
  505. {
  506. PreceedingToken = "3d",
  507. Token = "hsbs"
  508. },
  509. new Format3DRule
  510. {
  511. PreceedingToken = "3d",
  512. Token = "sbs"
  513. },
  514. new Format3DRule
  515. {
  516. PreceedingToken = "3d",
  517. Token = "htab"
  518. },
  519. new Format3DRule
  520. {
  521. PreceedingToken = "3d",
  522. Token = "tab"
  523. },
  524. // Media Browser rules:
  525. new Format3DRule
  526. {
  527. Token = "fsbs"
  528. },
  529. new Format3DRule
  530. {
  531. Token = "hsbs"
  532. },
  533. new Format3DRule
  534. {
  535. Token = "sbs"
  536. },
  537. new Format3DRule
  538. {
  539. Token = "ftab"
  540. },
  541. new Format3DRule
  542. {
  543. Token = "htab"
  544. },
  545. new Format3DRule
  546. {
  547. Token = "tab"
  548. },
  549. new Format3DRule
  550. {
  551. Token = "sbs3d"
  552. },
  553. new Format3DRule
  554. {
  555. Token = "mvc"
  556. }
  557. };
  558. AudioBookPartsExpressions = new[]
  559. {
  560. // Detect specified chapters, like CH 01
  561. @"ch(?:apter)?[\s_-]?(?<chapter>\d+)",
  562. // Detect specified parts, like Part 02
  563. @"p(?:ar)?t[\s_-]?(?<part>\d+)",
  564. // Chapter is often beginning of filename
  565. @"^(?<chapter>\d+)",
  566. // Part if often ending of filename
  567. @"(?<part>\d+)$",
  568. // Sometimes named as 0001_005 (chapter_part)
  569. @"(?<chapter>\d+)_(?<part>\d+)",
  570. // Some audiobooks are ripped from cd's, and will be named by disk number.
  571. @"dis(?:c|k)[\s_-]?(?<chapter>\d+)"
  572. };
  573. var extensions = VideoFileExtensions.ToList();
  574. extensions.AddRange(new[]
  575. {
  576. ".mkv",
  577. ".m2t",
  578. ".m2ts",
  579. ".img",
  580. ".iso",
  581. ".mk3d",
  582. ".ts",
  583. ".rmvb",
  584. ".mov",
  585. ".avi",
  586. ".mpg",
  587. ".mpeg",
  588. ".wmv",
  589. ".mp4",
  590. ".divx",
  591. ".dvr-ms",
  592. ".wtv",
  593. ".ogm",
  594. ".ogv",
  595. ".asf",
  596. ".m4v",
  597. ".flv",
  598. ".f4v",
  599. ".3gp",
  600. ".webm",
  601. ".mts",
  602. ".m2v",
  603. ".rec",
  604. ".mxf"
  605. });
  606. MultipleEpisodeExpressions = new string[]
  607. {
  608. @".*(\\|\/)[sS]?(?<seasonnumber>\d{1,4})[xX](?<epnumber>\d{1,3})((-| - )\d{1,4}[eExX](?<endingepnumber>\d{1,3}))+[^\\\/]*$",
  609. @".*(\\|\/)[sS]?(?<seasonnumber>\d{1,4})[xX](?<epnumber>\d{1,3})((-| - )\d{1,4}[xX][eE](?<endingepnumber>\d{1,3}))+[^\\\/]*$",
  610. @".*(\\|\/)[sS]?(?<seasonnumber>\d{1,4})[xX](?<epnumber>\d{1,3})((-| - )?[xXeE](?<endingepnumber>\d{1,3}))+[^\\\/]*$",
  611. @".*(\\|\/)[sS]?(?<seasonnumber>\d{1,4})[xX](?<epnumber>\d{1,3})(-[xE]?[eE]?(?<endingepnumber>\d{1,3}))+[^\\\/]*$",
  612. @".*(\\|\/)(?<seriesname>((?![sS]?\d{1,4}[xX]\d{1,3})[^\\\/])*)?([sS]?(?<seasonnumber>\d{1,4})[xX](?<epnumber>\d{1,3}))((-| - )\d{1,4}[xXeE](?<endingepnumber>\d{1,3}))+[^\\\/]*$",
  613. @".*(\\|\/)(?<seriesname>((?![sS]?\d{1,4}[xX]\d{1,3})[^\\\/])*)?([sS]?(?<seasonnumber>\d{1,4})[xX](?<epnumber>\d{1,3}))((-| - )\d{1,4}[xX][eE](?<endingepnumber>\d{1,3}))+[^\\\/]*$",
  614. @".*(\\|\/)(?<seriesname>((?![sS]?\d{1,4}[xX]\d{1,3})[^\\\/])*)?([sS]?(?<seasonnumber>\d{1,4})[xX](?<epnumber>\d{1,3}))((-| - )?[xXeE](?<endingepnumber>\d{1,3}))+[^\\\/]*$",
  615. @".*(\\|\/)(?<seriesname>((?![sS]?\d{1,4}[xX]\d{1,3})[^\\\/])*)?([sS]?(?<seasonnumber>\d{1,4})[xX](?<epnumber>\d{1,3}))(-[xX]?[eE]?(?<endingepnumber>\d{1,3}))+[^\\\/]*$",
  616. @".*(\\|\/)(?<seriesname>[^\\\/]*)[sS](?<seasonnumber>\d{1,4})[xX\.]?[eE](?<epnumber>\d{1,3})((-| - )?[xXeE](?<endingepnumber>\d{1,3}))+[^\\\/]*$",
  617. @".*(\\|\/)(?<seriesname>[^\\\/]*)[sS](?<seasonnumber>\d{1,4})[xX\.]?[eE](?<epnumber>\d{1,3})(-[xX]?[eE]?(?<endingepnumber>\d{1,3}))+[^\\\/]*$"
  618. }.Select(i => new EpisodeExpression(i)
  619. {
  620. IsNamed = true
  621. }).ToArray();
  622. VideoFileExtensions = extensions
  623. .Distinct(StringComparer.OrdinalIgnoreCase)
  624. .ToArray();
  625. Compile();
  626. }
  627. public Regex[] VideoFileStackingRegexes { get; private set; }
  628. public Regex[] CleanDateTimeRegexes { get; private set; }
  629. public Regex[] CleanStringRegexes { get; private set; }
  630. public Regex[] EpisodeWithoutSeasonRegexes { get; private set; }
  631. public Regex[] EpisodeMultiPartRegexes { get; private set; }
  632. public void Compile()
  633. {
  634. VideoFileStackingRegexes = VideoFileStackingExpressions.Select(Compile).ToArray();
  635. CleanDateTimeRegexes = CleanDateTimes.Select(Compile).ToArray();
  636. CleanStringRegexes = CleanStrings.Select(Compile).ToArray();
  637. EpisodeWithoutSeasonRegexes = EpisodeWithoutSeasonExpressions.Select(Compile).ToArray();
  638. EpisodeMultiPartRegexes = EpisodeMultiPartExpressions.Select(Compile).ToArray();
  639. }
  640. private Regex Compile(string exp)
  641. {
  642. return new Regex(exp, RegexOptions.IgnoreCase | RegexOptions.Compiled);
  643. }
  644. }
  645. }