| | 1 | | #pragma warning disable CA1819 |
| | 2 | |
|
| | 3 | | using System; |
| | 4 | | using System.Collections.Generic; |
| | 5 | | using System.Linq; |
| | 6 | | using System.Text.RegularExpressions; |
| | 7 | | using Emby.Naming.Video; |
| | 8 | | using MediaBrowser.Model.Entities; |
| | 9 | |
|
| | 10 | | // ReSharper disable StringLiteralTypo |
| | 11 | |
|
| | 12 | | namespace Emby.Naming.Common |
| | 13 | | { |
| | 14 | | /// <summary> |
| | 15 | | /// Big ugly class containing lot of different naming options that should be split and injected instead of passes ev |
| | 16 | | /// </summary> |
| | 17 | | public class NamingOptions |
| | 18 | | { |
| | 19 | | /// <summary> |
| | 20 | | /// Initializes a new instance of the <see cref="NamingOptions"/> class. |
| | 21 | | /// </summary> |
| | 22 | | public NamingOptions() |
| | 23 | | { |
| 664 | 24 | | VideoFileExtensions = new[] |
| 664 | 25 | | { |
| 664 | 26 | | ".001", |
| 664 | 27 | | ".3g2", |
| 664 | 28 | | ".3gp", |
| 664 | 29 | | ".amv", |
| 664 | 30 | | ".asf", |
| 664 | 31 | | ".asx", |
| 664 | 32 | | ".avi", |
| 664 | 33 | | ".bin", |
| 664 | 34 | | ".bivx", |
| 664 | 35 | | ".divx", |
| 664 | 36 | | ".dv", |
| 664 | 37 | | ".dvr-ms", |
| 664 | 38 | | ".f4v", |
| 664 | 39 | | ".fli", |
| 664 | 40 | | ".flv", |
| 664 | 41 | | ".ifo", |
| 664 | 42 | | ".img", |
| 664 | 43 | | ".iso", |
| 664 | 44 | | ".m2t", |
| 664 | 45 | | ".m2ts", |
| 664 | 46 | | ".m2v", |
| 664 | 47 | | ".m4v", |
| 664 | 48 | | ".mkv", |
| 664 | 49 | | ".mk3d", |
| 664 | 50 | | ".mov", |
| 664 | 51 | | ".mp4", |
| 664 | 52 | | ".mpe", |
| 664 | 53 | | ".mpeg", |
| 664 | 54 | | ".mpg", |
| 664 | 55 | | ".mts", |
| 664 | 56 | | ".mxf", |
| 664 | 57 | | ".nrg", |
| 664 | 58 | | ".nsv", |
| 664 | 59 | | ".nuv", |
| 664 | 60 | | ".ogg", |
| 664 | 61 | | ".ogm", |
| 664 | 62 | | ".ogv", |
| 664 | 63 | | ".pva", |
| 664 | 64 | | ".qt", |
| 664 | 65 | | ".rec", |
| 664 | 66 | | ".rm", |
| 664 | 67 | | ".rmvb", |
| 664 | 68 | | ".strm", |
| 664 | 69 | | ".svq3", |
| 664 | 70 | | ".tp", |
| 664 | 71 | | ".ts", |
| 664 | 72 | | ".ty", |
| 664 | 73 | | ".viv", |
| 664 | 74 | | ".vob", |
| 664 | 75 | | ".vp3", |
| 664 | 76 | | ".webm", |
| 664 | 77 | | ".wmv", |
| 664 | 78 | | ".wtv", |
| 664 | 79 | | ".xvid" |
| 664 | 80 | | }; |
| | 81 | |
|
| 664 | 82 | | VideoFlagDelimiters = new[] |
| 664 | 83 | | { |
| 664 | 84 | | '(', |
| 664 | 85 | | ')', |
| 664 | 86 | | '-', |
| 664 | 87 | | '.', |
| 664 | 88 | | '_', |
| 664 | 89 | | '[', |
| 664 | 90 | | ']' |
| 664 | 91 | | }; |
| | 92 | |
|
| 664 | 93 | | StubFileExtensions = new[] |
| 664 | 94 | | { |
| 664 | 95 | | ".disc" |
| 664 | 96 | | }; |
| | 97 | |
|
| 664 | 98 | | StubTypes = new[] |
| 664 | 99 | | { |
| 664 | 100 | | new StubTypeRule( |
| 664 | 101 | | stubType: "dvd", |
| 664 | 102 | | token: "dvd"), |
| 664 | 103 | |
|
| 664 | 104 | | new StubTypeRule( |
| 664 | 105 | | stubType: "hddvd", |
| 664 | 106 | | token: "hddvd"), |
| 664 | 107 | |
|
| 664 | 108 | | new StubTypeRule( |
| 664 | 109 | | stubType: "bluray", |
| 664 | 110 | | token: "bluray"), |
| 664 | 111 | |
|
| 664 | 112 | | new StubTypeRule( |
| 664 | 113 | | stubType: "bluray", |
| 664 | 114 | | token: "brrip"), |
| 664 | 115 | |
|
| 664 | 116 | | new StubTypeRule( |
| 664 | 117 | | stubType: "bluray", |
| 664 | 118 | | token: "bd25"), |
| 664 | 119 | |
|
| 664 | 120 | | new StubTypeRule( |
| 664 | 121 | | stubType: "bluray", |
| 664 | 122 | | token: "bd50"), |
| 664 | 123 | |
|
| 664 | 124 | | new StubTypeRule( |
| 664 | 125 | | stubType: "vhs", |
| 664 | 126 | | token: "vhs"), |
| 664 | 127 | |
|
| 664 | 128 | | new StubTypeRule( |
| 664 | 129 | | stubType: "tv", |
| 664 | 130 | | token: "HDTV"), |
| 664 | 131 | |
|
| 664 | 132 | | new StubTypeRule( |
| 664 | 133 | | stubType: "tv", |
| 664 | 134 | | token: "PDTV"), |
| 664 | 135 | |
|
| 664 | 136 | | new StubTypeRule( |
| 664 | 137 | | stubType: "tv", |
| 664 | 138 | | token: "DSR") |
| 664 | 139 | | }; |
| | 140 | |
|
| 664 | 141 | | VideoFileStackingRules = new[] |
| 664 | 142 | | { |
| 664 | 143 | | new FileStackRule(@"^(?<filename>.*?)(?:(?<=[\]\)\}])|[ _.-]+)[\(\[]?(?<parttype>cd|dvd|part|pt|dis[ck]) |
| 664 | 144 | | new FileStackRule(@"^(?<filename>.*?)(?:(?<=[\]\)\}])|[ _.-]+)[\(\[]?(?<parttype>cd|dvd|part|pt|dis[ck]) |
| 664 | 145 | | }; |
| | 146 | |
|
| 664 | 147 | | CleanDateTimes = new[] |
| 664 | 148 | | { |
| 664 | 149 | | @"(.+[^_\,\.\(\)\[\]\-])[_\.\(\)\[\]\-](19[0-9]{2}|20[0-9]{2})(?![0-9]+|\W[0-9]{2}\W[0-9]{2})([ _\,\.\(\ |
| 664 | 150 | | @"(.+[^_\,\.\(\)\[\]\-])[ _\.\(\)\[\]\-]+(19[0-9]{2}|20[0-9]{2})(?![0-9]+|\W[0-9]{2}\W[0-9]{2})([ _\,\.\ |
| 664 | 151 | | }; |
| | 152 | |
|
| 664 | 153 | | CleanStrings = new[] |
| 664 | 154 | | { |
| 664 | 155 | | @"^\s*(?<cleaned>.+?)[ _\,\.\(\)\[\]\-](3d|sbs|tab|hsbs|htab|mvc|HDR|HDC|UHD|UltraHD|4k|ac3|dts|custom|d |
| 664 | 156 | | @"^(?<cleaned>.+?)(\[.*\])", |
| 664 | 157 | | @"^\s*(?<cleaned>.+?)\WE[0-9]+(-|~)E?[0-9]+(\W|$)", |
| 664 | 158 | | @"^\s*\[[^\]]+\](?!\.\w+$)\s*(?<cleaned>.+)", |
| 664 | 159 | | @"^\s*(?<cleaned>.+?)\s+-\s+[0-9]+\s*$", |
| 664 | 160 | | @"^\s*(?<cleaned>.+?)(([-._ ](trailer|sample))|-(scene|clip|behindthescenes|deleted|deletedscene|feature |
| 664 | 161 | | }; |
| | 162 | |
|
| 664 | 163 | | SubtitleFileExtensions = new[] |
| 664 | 164 | | { |
| 664 | 165 | | ".ass", |
| 664 | 166 | | ".mks", |
| 664 | 167 | | ".sami", |
| 664 | 168 | | ".smi", |
| 664 | 169 | | ".srt", |
| 664 | 170 | | ".ssa", |
| 664 | 171 | | ".sub", |
| 664 | 172 | | ".sup", |
| 664 | 173 | | ".vtt", |
| 664 | 174 | | }; |
| | 175 | |
|
| 664 | 176 | | LyricFileExtensions = new[] |
| 664 | 177 | | { |
| 664 | 178 | | ".lrc", |
| 664 | 179 | | ".elrc", |
| 664 | 180 | | ".txt" |
| 664 | 181 | | }; |
| | 182 | |
|
| 664 | 183 | | AlbumStackingPrefixes = new[] |
| 664 | 184 | | { |
| 664 | 185 | | "cd", |
| 664 | 186 | | "digital media", |
| 664 | 187 | | "disc", |
| 664 | 188 | | "disk", |
| 664 | 189 | | "vol", |
| 664 | 190 | | "volume" |
| 664 | 191 | | }; |
| | 192 | |
|
| 664 | 193 | | ArtistSubfolders = new[] |
| 664 | 194 | | { |
| 664 | 195 | | "albums", |
| 664 | 196 | | "broadcasts", |
| 664 | 197 | | "bootlegs", |
| 664 | 198 | | "compilations", |
| 664 | 199 | | "dj-mixes", |
| 664 | 200 | | "eps", |
| 664 | 201 | | "live", |
| 664 | 202 | | "mixtapes", |
| 664 | 203 | | "others", |
| 664 | 204 | | "remixes", |
| 664 | 205 | | "singles", |
| 664 | 206 | | "soundtracks", |
| 664 | 207 | | "spokenwords", |
| 664 | 208 | | "streets" |
| 664 | 209 | | }; |
| | 210 | |
|
| 664 | 211 | | AudioFileExtensions = new[] |
| 664 | 212 | | { |
| 664 | 213 | | ".669", |
| 664 | 214 | | ".3gp", |
| 664 | 215 | | ".aa", |
| 664 | 216 | | ".aac", |
| 664 | 217 | | ".aax", |
| 664 | 218 | | ".ac3", |
| 664 | 219 | | ".act", |
| 664 | 220 | | ".adp", |
| 664 | 221 | | ".adplug", |
| 664 | 222 | | ".adx", |
| 664 | 223 | | ".afc", |
| 664 | 224 | | ".amf", |
| 664 | 225 | | ".aif", |
| 664 | 226 | | ".aiff", |
| 664 | 227 | | ".alac", |
| 664 | 228 | | ".amr", |
| 664 | 229 | | ".ape", |
| 664 | 230 | | ".ast", |
| 664 | 231 | | ".au", |
| 664 | 232 | | ".awb", |
| 664 | 233 | | ".cda", |
| 664 | 234 | | ".cue", |
| 664 | 235 | | ".dmf", |
| 664 | 236 | | ".dsf", |
| 664 | 237 | | ".dsm", |
| 664 | 238 | | ".dsp", |
| 664 | 239 | | ".dts", |
| 664 | 240 | | ".dvf", |
| 664 | 241 | | ".eac3", |
| 664 | 242 | | ".far", |
| 664 | 243 | | ".flac", |
| 664 | 244 | | ".gdm", |
| 664 | 245 | | ".gsm", |
| 664 | 246 | | ".gym", |
| 664 | 247 | | ".hps", |
| 664 | 248 | | ".imf", |
| 664 | 249 | | ".it", |
| 664 | 250 | | ".m15", |
| 664 | 251 | | ".m4a", |
| 664 | 252 | | ".m4b", |
| 664 | 253 | | ".mac", |
| 664 | 254 | | ".med", |
| 664 | 255 | | ".mka", |
| 664 | 256 | | ".mmf", |
| 664 | 257 | | ".mod", |
| 664 | 258 | | ".mogg", |
| 664 | 259 | | ".mp2", |
| 664 | 260 | | ".mp3", |
| 664 | 261 | | ".mpa", |
| 664 | 262 | | ".mpc", |
| 664 | 263 | | ".mpp", |
| 664 | 264 | | ".mp+", |
| 664 | 265 | | ".msv", |
| 664 | 266 | | ".nmf", |
| 664 | 267 | | ".nsf", |
| 664 | 268 | | ".nsv", |
| 664 | 269 | | ".oga", |
| 664 | 270 | | ".ogg", |
| 664 | 271 | | ".okt", |
| 664 | 272 | | ".opus", |
| 664 | 273 | | ".pls", |
| 664 | 274 | | ".ra", |
| 664 | 275 | | ".rf64", |
| 664 | 276 | | ".rm", |
| 664 | 277 | | ".s3m", |
| 664 | 278 | | ".sfx", |
| 664 | 279 | | ".shn", |
| 664 | 280 | | ".sid", |
| 664 | 281 | | ".stm", |
| 664 | 282 | | ".strm", |
| 664 | 283 | | ".ult", |
| 664 | 284 | | ".uni", |
| 664 | 285 | | ".vox", |
| 664 | 286 | | ".wav", |
| 664 | 287 | | ".wma", |
| 664 | 288 | | ".wv", |
| 664 | 289 | | ".xm", |
| 664 | 290 | | ".xsp", |
| 664 | 291 | | ".ymf" |
| 664 | 292 | | }; |
| | 293 | |
|
| 664 | 294 | | MediaFlagDelimiters = new[] |
| 664 | 295 | | { |
| 664 | 296 | | '.' |
| 664 | 297 | | }; |
| | 298 | |
|
| 664 | 299 | | MediaForcedFlags = new[] |
| 664 | 300 | | { |
| 664 | 301 | | "foreign", |
| 664 | 302 | | "forced" |
| 664 | 303 | | }; |
| | 304 | |
|
| 664 | 305 | | MediaDefaultFlags = new[] |
| 664 | 306 | | { |
| 664 | 307 | | "default" |
| 664 | 308 | | }; |
| | 309 | |
|
| 664 | 310 | | MediaHearingImpairedFlags = new[] |
| 664 | 311 | | { |
| 664 | 312 | | "cc", |
| 664 | 313 | | "hi", |
| 664 | 314 | | "sdh" |
| 664 | 315 | | }; |
| | 316 | |
|
| 664 | 317 | | EpisodeExpressions = new[] |
| 664 | 318 | | { |
| 664 | 319 | | // *** Begin Kodi Standard Naming |
| 664 | 320 | | // <!-- foo.s01.e01, foo.s01_e01, S01E02 foo, S01 - E02 --> |
| 664 | 321 | | new EpisodeExpression(@".*(\\|\/)(?<seriesname>((?[][ ._-]*[Ee]([0-9]+))[^\\\/])*)?[Ss](?<s |
| 664 | 322 | | { |
| 664 | 323 | | IsNamed = true |
| 664 | 324 | | }, |
| 664 | 325 | | // <!-- foo.ep01, foo.EP_01 --> |
| 664 | 326 | | new EpisodeExpression(@"[\._ -]()[Ee][Pp]_?([0-9]+)([^\\/]*)$"), |
| 664 | 327 | | // <!-- foo.E01., foo.e01. --> |
| 664 | 328 | | new EpisodeExpression(@"[^\\/]*?()\.?[Ee]([0-9]+)\.([^\\/]*)$"), |
| 664 | 329 | | new EpisodeExpression("(?<year>[0-9]{4})[._ -](?<month>[0-9]{2})[._ -](?<day>[0-9]{2})", true) |
| 664 | 330 | | { |
| 664 | 331 | | DateTimeFormats = new[] |
| 664 | 332 | | { |
| 664 | 333 | | "yyyy.MM.dd", |
| 664 | 334 | | "yyyy-MM-dd", |
| 664 | 335 | | "yyyy_MM_dd", |
| 664 | 336 | | "yyyy MM dd" |
| 664 | 337 | | } |
| 664 | 338 | | }, |
| 664 | 339 | | new EpisodeExpression("(?<day>[0-9]{2})[._ -](?<month>[0-9]{2})[._ -](?<year>[0-9]{4})", true) |
| 664 | 340 | | { |
| 664 | 341 | | DateTimeFormats = new[] |
| 664 | 342 | | { |
| 664 | 343 | | "dd.MM.yyyy", |
| 664 | 344 | | "dd-MM-yyyy", |
| 664 | 345 | | "dd_MM_yyyy", |
| 664 | 346 | | "dd MM yyyy" |
| 664 | 347 | | } |
| 664 | 348 | | }, |
| 664 | 349 | |
|
| 664 | 350 | | // This isn't a Kodi naming rule, but the expression below causes false episode numbers for |
| 664 | 351 | | // Title Season X Episode X naming schemes. |
| 664 | 352 | | // "Series Season X Episode X - Title.avi", "Series S03 E09.avi", "s3 e9 - Title.avi" |
| 664 | 353 | | new EpisodeExpression(@".*[\\\/]((?<seriesname>[^\\/]+?)\s)?[Ss](?:eason)?\s*(?<seasonnumber>[0-9]+)\s+[ |
| 664 | 354 | | { |
| 664 | 355 | | IsNamed = true |
| 664 | 356 | | }, |
| 664 | 357 | |
|
| 664 | 358 | | // Not a Kodi rule as well, but the expression below also causes false positives, |
| 664 | 359 | | // so we make sure this one gets tested first. |
| 664 | 360 | | // "Foo Bar 889" |
| 664 | 361 | | new EpisodeExpression(@".*[\\\/](?![Ee]pisode)(?<seriesname>[\w\s]+?)\s(?<epnumber>[0-9]{1,4})(-(?<endin |
| 664 | 362 | | { |
| 664 | 363 | | IsNamed = true |
| 664 | 364 | | }, |
| 664 | 365 | |
|
| 664 | 366 | | new EpisodeExpression(@"[\\\/\._ \[\(-]([0-9]+)x([0-9]+(?:(?:[a-i]|\.[1-9])(?![0-9]))?)([^\\\/]*)$") |
| 664 | 367 | | { |
| 664 | 368 | | SupportsAbsoluteEpisodeNumbers = true |
| 664 | 369 | | }, |
| 664 | 370 | |
|
| 664 | 371 | | // Not a Kodi rule as well, but below rule also causes false positives for triple-digit episode names |
| 664 | 372 | | // [bar] Foo - 1 [baz] special case of below expression to prevent false positives with digits in the se |
| 664 | 373 | | new EpisodeExpression(@".*[\\\/]?.*?(\[.*?\])+.*?(?<seriesname>[-\w\s]+?)[\s_]*-[\s_]*(?<epnumber>[0-9]+ |
| 664 | 374 | | { |
| 664 | 375 | | IsNamed = true |
| 664 | 376 | | }, |
| 664 | 377 | |
|
| 664 | 378 | | // /server/anything_102.mp4 |
| 664 | 379 | | // /server/james.corden.2017.04.20.anne.hathaway.720p.hdtv.x264-crooks.mkv |
| 664 | 380 | | // /server/anything_1996.11.14.mp4 |
| 664 | 381 | | new EpisodeExpression(@"[\\/._ -](?<seriesname>(?![0-9]+[0-9][0-9])([^\\\/_])*)[\\\/._ -](?<seasonnumber |
| 664 | 382 | | { |
| 664 | 383 | | IsOptimistic = true, |
| 664 | 384 | | IsNamed = true, |
| 664 | 385 | | SupportsAbsoluteEpisodeNumbers = false |
| 664 | 386 | | }, |
| 664 | 387 | | new EpisodeExpression(@"[\/._ -]p(?:ar)?t[_. -]()([ivx]+|[0-9]+)([._ -][^\/]*)$") |
| 664 | 388 | | { |
| 664 | 389 | | SupportsAbsoluteEpisodeNumbers = true |
| 664 | 390 | | }, |
| 664 | 391 | |
|
| 664 | 392 | | // *** End Kodi Standard Naming |
| 664 | 393 | |
|
| 664 | 394 | | // "Episode 16", "Episode 16 - Title" |
| 664 | 395 | | new EpisodeExpression(@"[Ee]pisode (?<epnumber>[0-9]+)(-(?<endingepnumber>[0-9]+))?[^\\\/]*$") |
| 664 | 396 | | { |
| 664 | 397 | | IsNamed = true |
| 664 | 398 | | }, |
| 664 | 399 | |
|
| 664 | 400 | | new EpisodeExpression(@".*(\\|\/)[sS]?(?<seasonnumber>[0-9]+)[xX](?<epnumber>[0-9]+)[^\\\/]*$") |
| 664 | 401 | | { |
| 664 | 402 | | IsNamed = true |
| 664 | 403 | | }, |
| 664 | 404 | |
|
| 664 | 405 | | new EpisodeExpression(@".*(\\|\/)[sS](?<seasonnumber>[0-9]+)[x,X]?[eE](?<epnumber>[0-9]+)[^\\\/]*$") |
| 664 | 406 | | { |
| 664 | 407 | | IsNamed = true |
| 664 | 408 | | }, |
| 664 | 409 | |
|
| 664 | 410 | | new EpisodeExpression(@".*(\\|\/)(?<seriesname>((?![sS]?[0-9]{1,4}[xX][0-9]{1,3})[^\\\/])*)?([sS]?(?<sea |
| 664 | 411 | | { |
| 664 | 412 | | IsNamed = true |
| 664 | 413 | | }, |
| 664 | 414 | |
|
| 664 | 415 | | new EpisodeExpression(@".*(\\|\/)(?<seriesname>[^\\\/]*)[sS](?<seasonnumber>[0-9]{1,4})[xX\.]?[eE](?<epn |
| 664 | 416 | | { |
| 664 | 417 | | IsNamed = true |
| 664 | 418 | | }, |
| 664 | 419 | |
|
| 664 | 420 | | // "01.avi" |
| 664 | 421 | | new EpisodeExpression(@".*[\\\/](?<epnumber>[0-9]+)(-(?<endingepnumber>[0-9]+))*\.\w+$") |
| 664 | 422 | | { |
| 664 | 423 | | IsOptimistic = true, |
| 664 | 424 | | IsNamed = true |
| 664 | 425 | | }, |
| 664 | 426 | |
|
| 664 | 427 | | // "1-12 episode title" |
| 664 | 428 | | new EpisodeExpression("([0-9]+)-([0-9]+)"), |
| 664 | 429 | |
|
| 664 | 430 | | // "01 - blah.avi", "01-blah.avi" |
| 664 | 431 | | new EpisodeExpression(@".*(\\|\/)(?<epnumber>[0-9]{1,3})(-(?<endingepnumber>[0-9]{2,3}))*\s?-\s?[^\\\/]* |
| 664 | 432 | | { |
| 664 | 433 | | IsOptimistic = true, |
| 664 | 434 | | IsNamed = true |
| 664 | 435 | | }, |
| 664 | 436 | |
|
| 664 | 437 | | // "01.blah.avi" |
| 664 | 438 | | new EpisodeExpression(@".*(\\|\/)(?<epnumber>[0-9]{1,3})(-(?<endingepnumber>[0-9]{2,3}))*\.[^\\\/]+$") |
| 664 | 439 | | { |
| 664 | 440 | | IsOptimistic = true, |
| 664 | 441 | | IsNamed = true |
| 664 | 442 | | }, |
| 664 | 443 | |
|
| 664 | 444 | | // "blah - 01.avi", "blah 2 - 01.avi", "blah - 01 blah.avi", "blah 2 - 01 blah", "blah - 01 - blah.avi", |
| 664 | 445 | | new EpisodeExpression(@".*[\\\/][^\\\/]* - (?<epnumber>[0-9]{1,3})(-(?<endingepnumber>[0-9]{2,3}))*[^\\\ |
| 664 | 446 | | { |
| 664 | 447 | | IsOptimistic = true, |
| 664 | 448 | | IsNamed = true |
| 664 | 449 | | }, |
| 664 | 450 | |
|
| 664 | 451 | | // "01 episode title.avi" |
| 664 | 452 | | new EpisodeExpression(@"[Ss]eason[\._ ](?<seasonnumber>[0-9]+)[\\\/](?<epnumber>[0-9]{1,3})([^\\\/]*)$") |
| 664 | 453 | | { |
| 664 | 454 | | IsOptimistic = true, |
| 664 | 455 | | IsNamed = true |
| 664 | 456 | | }, |
| 664 | 457 | |
|
| 664 | 458 | | // Series and season only expression |
| 664 | 459 | | // "the show/season 1", "the show/s01" |
| 664 | 460 | | new EpisodeExpression(@"(.*(\\|\/))*(?<seriesname>.+)\/[Ss](eason)?[\. _\-]*(?<seasonnumber>[0-9]+)") |
| 664 | 461 | | { |
| 664 | 462 | | IsNamed = true |
| 664 | 463 | | }, |
| 664 | 464 | |
|
| 664 | 465 | | // Series and season only expression |
| 664 | 466 | | // "the show S01", "the show season 1" |
| 664 | 467 | | new EpisodeExpression(@"(.*(\\|\/))*(?<seriesname>.+)[\. _\-]+[sS](eason)?[\. _\-]*(?<seasonnumber>[0-9] |
| 664 | 468 | | { |
| 664 | 469 | | IsNamed = true |
| 664 | 470 | | }, |
| 664 | 471 | |
|
| 664 | 472 | | // Anime style expression |
| 664 | 473 | | // "[Group][Series Name][21][1080p][FLAC][HASH]" |
| 664 | 474 | | // "[Group] Series Name [04][BDRIP]" |
| 664 | 475 | | new EpisodeExpression(@"(?:\[(?:[^\]]+)\]\s*)?(?<seriesname>\[[^\]]+\]|[^[\]]+)\s*\[(?<epnumber>[0-9]+)\ |
| 664 | 476 | | { |
| 664 | 477 | | IsNamed = true |
| 664 | 478 | | }, |
| 664 | 479 | | }; |
| | 480 | |
|
| 664 | 481 | | VideoExtraRules = new[] |
| 664 | 482 | | { |
| 664 | 483 | | new ExtraRule( |
| 664 | 484 | | ExtraType.Trailer, |
| 664 | 485 | | ExtraRuleType.DirectoryName, |
| 664 | 486 | | "trailers", |
| 664 | 487 | | MediaType.Video), |
| 664 | 488 | |
|
| 664 | 489 | | new ExtraRule( |
| 664 | 490 | | ExtraType.ThemeVideo, |
| 664 | 491 | | ExtraRuleType.DirectoryName, |
| 664 | 492 | | "backdrops", |
| 664 | 493 | | MediaType.Video), |
| 664 | 494 | |
|
| 664 | 495 | | new ExtraRule( |
| 664 | 496 | | ExtraType.ThemeSong, |
| 664 | 497 | | ExtraRuleType.DirectoryName, |
| 664 | 498 | | "theme-music", |
| 664 | 499 | | MediaType.Audio), |
| 664 | 500 | |
|
| 664 | 501 | | new ExtraRule( |
| 664 | 502 | | ExtraType.BehindTheScenes, |
| 664 | 503 | | ExtraRuleType.DirectoryName, |
| 664 | 504 | | "behind the scenes", |
| 664 | 505 | | MediaType.Video), |
| 664 | 506 | |
|
| 664 | 507 | | new ExtraRule( |
| 664 | 508 | | ExtraType.DeletedScene, |
| 664 | 509 | | ExtraRuleType.DirectoryName, |
| 664 | 510 | | "deleted scenes", |
| 664 | 511 | | MediaType.Video), |
| 664 | 512 | |
|
| 664 | 513 | | new ExtraRule( |
| 664 | 514 | | ExtraType.Interview, |
| 664 | 515 | | ExtraRuleType.DirectoryName, |
| 664 | 516 | | "interviews", |
| 664 | 517 | | MediaType.Video), |
| 664 | 518 | |
|
| 664 | 519 | | new ExtraRule( |
| 664 | 520 | | ExtraType.Scene, |
| 664 | 521 | | ExtraRuleType.DirectoryName, |
| 664 | 522 | | "scenes", |
| 664 | 523 | | MediaType.Video), |
| 664 | 524 | |
|
| 664 | 525 | | new ExtraRule( |
| 664 | 526 | | ExtraType.Sample, |
| 664 | 527 | | ExtraRuleType.DirectoryName, |
| 664 | 528 | | "samples", |
| 664 | 529 | | MediaType.Video), |
| 664 | 530 | |
|
| 664 | 531 | | new ExtraRule( |
| 664 | 532 | | ExtraType.Short, |
| 664 | 533 | | ExtraRuleType.DirectoryName, |
| 664 | 534 | | "shorts", |
| 664 | 535 | | MediaType.Video), |
| 664 | 536 | |
|
| 664 | 537 | | new ExtraRule( |
| 664 | 538 | | ExtraType.Featurette, |
| 664 | 539 | | ExtraRuleType.DirectoryName, |
| 664 | 540 | | "featurettes", |
| 664 | 541 | | MediaType.Video), |
| 664 | 542 | |
|
| 664 | 543 | | new ExtraRule( |
| 664 | 544 | | ExtraType.Unknown, |
| 664 | 545 | | ExtraRuleType.DirectoryName, |
| 664 | 546 | | "extras", |
| 664 | 547 | | MediaType.Video), |
| 664 | 548 | |
|
| 664 | 549 | | new ExtraRule( |
| 664 | 550 | | ExtraType.Unknown, |
| 664 | 551 | | ExtraRuleType.DirectoryName, |
| 664 | 552 | | "extra", |
| 664 | 553 | | MediaType.Video), |
| 664 | 554 | |
|
| 664 | 555 | | new ExtraRule( |
| 664 | 556 | | ExtraType.Unknown, |
| 664 | 557 | | ExtraRuleType.DirectoryName, |
| 664 | 558 | | "other", |
| 664 | 559 | | MediaType.Video), |
| 664 | 560 | |
|
| 664 | 561 | | new ExtraRule( |
| 664 | 562 | | ExtraType.Clip, |
| 664 | 563 | | ExtraRuleType.DirectoryName, |
| 664 | 564 | | "clips", |
| 664 | 565 | | MediaType.Video), |
| 664 | 566 | |
|
| 664 | 567 | | new ExtraRule( |
| 664 | 568 | | ExtraType.Trailer, |
| 664 | 569 | | ExtraRuleType.Filename, |
| 664 | 570 | | "trailer", |
| 664 | 571 | | MediaType.Video), |
| 664 | 572 | |
|
| 664 | 573 | | new ExtraRule( |
| 664 | 574 | | ExtraType.Trailer, |
| 664 | 575 | | ExtraRuleType.Suffix, |
| 664 | 576 | | "-trailer", |
| 664 | 577 | | MediaType.Video), |
| 664 | 578 | |
|
| 664 | 579 | | new ExtraRule( |
| 664 | 580 | | ExtraType.Trailer, |
| 664 | 581 | | ExtraRuleType.Suffix, |
| 664 | 582 | | ".trailer", |
| 664 | 583 | | MediaType.Video), |
| 664 | 584 | |
|
| 664 | 585 | | new ExtraRule( |
| 664 | 586 | | ExtraType.Trailer, |
| 664 | 587 | | ExtraRuleType.Suffix, |
| 664 | 588 | | "_trailer", |
| 664 | 589 | | MediaType.Video), |
| 664 | 590 | |
|
| 664 | 591 | | new ExtraRule( |
| 664 | 592 | | ExtraType.Trailer, |
| 664 | 593 | | ExtraRuleType.Suffix, |
| 664 | 594 | | " trailer", |
| 664 | 595 | | MediaType.Video), |
| 664 | 596 | |
|
| 664 | 597 | | new ExtraRule( |
| 664 | 598 | | ExtraType.Sample, |
| 664 | 599 | | ExtraRuleType.Filename, |
| 664 | 600 | | "sample", |
| 664 | 601 | | MediaType.Video), |
| 664 | 602 | |
|
| 664 | 603 | | new ExtraRule( |
| 664 | 604 | | ExtraType.Sample, |
| 664 | 605 | | ExtraRuleType.Suffix, |
| 664 | 606 | | "-sample", |
| 664 | 607 | | MediaType.Video), |
| 664 | 608 | |
|
| 664 | 609 | | new ExtraRule( |
| 664 | 610 | | ExtraType.Sample, |
| 664 | 611 | | ExtraRuleType.Suffix, |
| 664 | 612 | | ".sample", |
| 664 | 613 | | MediaType.Video), |
| 664 | 614 | |
|
| 664 | 615 | | new ExtraRule( |
| 664 | 616 | | ExtraType.Sample, |
| 664 | 617 | | ExtraRuleType.Suffix, |
| 664 | 618 | | "_sample", |
| 664 | 619 | | MediaType.Video), |
| 664 | 620 | |
|
| 664 | 621 | | new ExtraRule( |
| 664 | 622 | | ExtraType.Sample, |
| 664 | 623 | | ExtraRuleType.Suffix, |
| 664 | 624 | | " sample", |
| 664 | 625 | | MediaType.Video), |
| 664 | 626 | |
|
| 664 | 627 | | new ExtraRule( |
| 664 | 628 | | ExtraType.ThemeSong, |
| 664 | 629 | | ExtraRuleType.Filename, |
| 664 | 630 | | "theme", |
| 664 | 631 | | MediaType.Audio), |
| 664 | 632 | |
|
| 664 | 633 | | new ExtraRule( |
| 664 | 634 | | ExtraType.Scene, |
| 664 | 635 | | ExtraRuleType.Suffix, |
| 664 | 636 | | "-scene", |
| 664 | 637 | | MediaType.Video), |
| 664 | 638 | |
|
| 664 | 639 | | new ExtraRule( |
| 664 | 640 | | ExtraType.Clip, |
| 664 | 641 | | ExtraRuleType.Suffix, |
| 664 | 642 | | "-clip", |
| 664 | 643 | | MediaType.Video), |
| 664 | 644 | |
|
| 664 | 645 | | new ExtraRule( |
| 664 | 646 | | ExtraType.Interview, |
| 664 | 647 | | ExtraRuleType.Suffix, |
| 664 | 648 | | "-interview", |
| 664 | 649 | | MediaType.Video), |
| 664 | 650 | |
|
| 664 | 651 | | new ExtraRule( |
| 664 | 652 | | ExtraType.BehindTheScenes, |
| 664 | 653 | | ExtraRuleType.Suffix, |
| 664 | 654 | | "-behindthescenes", |
| 664 | 655 | | MediaType.Video), |
| 664 | 656 | |
|
| 664 | 657 | | new ExtraRule( |
| 664 | 658 | | ExtraType.DeletedScene, |
| 664 | 659 | | ExtraRuleType.Suffix, |
| 664 | 660 | | "-deleted", |
| 664 | 661 | | MediaType.Video), |
| 664 | 662 | |
|
| 664 | 663 | | new ExtraRule( |
| 664 | 664 | | ExtraType.DeletedScene, |
| 664 | 665 | | ExtraRuleType.Suffix, |
| 664 | 666 | | "-deletedscene", |
| 664 | 667 | | MediaType.Video), |
| 664 | 668 | |
|
| 664 | 669 | | new ExtraRule( |
| 664 | 670 | | ExtraType.Featurette, |
| 664 | 671 | | ExtraRuleType.Suffix, |
| 664 | 672 | | "-featurette", |
| 664 | 673 | | MediaType.Video), |
| 664 | 674 | |
|
| 664 | 675 | | new ExtraRule( |
| 664 | 676 | | ExtraType.Short, |
| 664 | 677 | | ExtraRuleType.Suffix, |
| 664 | 678 | | "-short", |
| 664 | 679 | | MediaType.Video), |
| 664 | 680 | |
|
| 664 | 681 | | new ExtraRule( |
| 664 | 682 | | ExtraType.Unknown, |
| 664 | 683 | | ExtraRuleType.Suffix, |
| 664 | 684 | | "-extra", |
| 664 | 685 | | MediaType.Video), |
| 664 | 686 | |
|
| 664 | 687 | | new ExtraRule( |
| 664 | 688 | | ExtraType.Unknown, |
| 664 | 689 | | ExtraRuleType.Suffix, |
| 664 | 690 | | "-other", |
| 664 | 691 | | MediaType.Video) |
| 664 | 692 | | }; |
| | 693 | |
|
| 664 | 694 | | AllExtrasTypesFolderNames = VideoExtraRules |
| 664 | 695 | | .Where(i => i.RuleType == ExtraRuleType.DirectoryName) |
| 664 | 696 | | .ToDictionary(i => i.Token, i => i.ExtraType, StringComparer.OrdinalIgnoreCase); |
| | 697 | |
|
| 664 | 698 | | Format3DRules = new[] |
| 664 | 699 | | { |
| 664 | 700 | | // Kodi rules: |
| 664 | 701 | | new Format3DRule( |
| 664 | 702 | | precedingToken: "3d", |
| 664 | 703 | | token: "hsbs"), |
| 664 | 704 | |
|
| 664 | 705 | | new Format3DRule( |
| 664 | 706 | | precedingToken: "3d", |
| 664 | 707 | | token: "sbs"), |
| 664 | 708 | |
|
| 664 | 709 | | new Format3DRule( |
| 664 | 710 | | precedingToken: "3d", |
| 664 | 711 | | token: "htab"), |
| 664 | 712 | |
|
| 664 | 713 | | new Format3DRule( |
| 664 | 714 | | precedingToken: "3d", |
| 664 | 715 | | token: "tab"), |
| 664 | 716 | |
|
| 664 | 717 | | // Media Browser rules: |
| 664 | 718 | | new Format3DRule("fsbs"), |
| 664 | 719 | | new Format3DRule("hsbs"), |
| 664 | 720 | | new Format3DRule("sbs"), |
| 664 | 721 | | new Format3DRule("ftab"), |
| 664 | 722 | | new Format3DRule("htab"), |
| 664 | 723 | | new Format3DRule("tab"), |
| 664 | 724 | | new Format3DRule("sbs3d"), |
| 664 | 725 | | new Format3DRule("mvc") |
| 664 | 726 | | }; |
| | 727 | |
|
| 664 | 728 | | AudioBookPartsExpressions = new[] |
| 664 | 729 | | { |
| 664 | 730 | | // Detect specified chapters, like CH 01 |
| 664 | 731 | | @"ch(?:apter)?[\s_-]?(?<chapter>[0-9]+)", |
| 664 | 732 | | // Detect specified parts, like Part 02 |
| 664 | 733 | | @"p(?:ar)?t[\s_-]?(?<part>[0-9]+)", |
| 664 | 734 | | // Chapter is often beginning of filename |
| 664 | 735 | | "^(?<chapter>[0-9]+)", |
| 664 | 736 | | // Part if often ending of filename |
| 664 | 737 | | "(?<!ch(?:apter) )(?<part>[0-9]+)$", |
| 664 | 738 | | // Sometimes named as 0001_005 (chapter_part) |
| 664 | 739 | | "(?<chapter>[0-9]+)_(?<part>[0-9]+)", |
| 664 | 740 | | // Some audiobooks are ripped from cd's, and will be named by disk number. |
| 664 | 741 | | @"dis(?:c|k)[\s_-]?(?<chapter>[0-9]+)" |
| 664 | 742 | | }; |
| | 743 | |
|
| 664 | 744 | | AudioBookNamesExpressions = new[] |
| 664 | 745 | | { |
| 664 | 746 | | // Detect year usually in brackets after name Batman (2020) |
| 664 | 747 | | @"^(?<name>.+?)\s*\(\s*(?<year>[0-9]{4})\s*\)\s*$", |
| 664 | 748 | | @"^\s*(?<name>[^ ].*?)\s*$" |
| 664 | 749 | | }; |
| | 750 | |
|
| 664 | 751 | | MultipleEpisodeExpressions = new[] |
| 664 | 752 | | { |
| 664 | 753 | | @".*(\\|\/)[sS]?(?<seasonnumber>[0-9]{1,4})[xX](?<epnumber>[0-9]{1,3})((-| - )[0-9]{1,4}[eExX](?<endinge |
| 664 | 754 | | @".*(\\|\/)[sS]?(?<seasonnumber>[0-9]{1,4})[xX](?<epnumber>[0-9]{1,3})((-| - )[0-9]{1,4}[xX][eE](?<endin |
| 664 | 755 | | @".*(\\|\/)[sS]?(?<seasonnumber>[0-9]{1,4})[xX](?<epnumber>[0-9]{1,3})((-| - )?[xXeE](?<endingepnumber>[ |
| 664 | 756 | | @".*(\\|\/)[sS]?(?<seasonnumber>[0-9]{1,4})[xX](?<epnumber>[0-9]{1,3})(-[xE]?[eE]?(?<endingepnumber>[0-9 |
| 664 | 757 | | @".*(\\|\/)(?<seriesname>((?![sS]?[0-9]{1,4}[xX][0-9]{1,3})[^\\\/])*)?([sS]?(?<seasonnumber>[0-9]{1,4})[ |
| 664 | 758 | | @".*(\\|\/)(?<seriesname>((?![sS]?[0-9]{1,4}[xX][0-9]{1,3})[^\\\/])*)?([sS]?(?<seasonnumber>[0-9]{1,4})[ |
| 664 | 759 | | @".*(\\|\/)(?<seriesname>((?![sS]?[0-9]{1,4}[xX][0-9]{1,3})[^\\\/])*)?([sS]?(?<seasonnumber>[0-9]{1,4})[ |
| 664 | 760 | | @".*(\\|\/)(?<seriesname>((?![sS]?[0-9]{1,4}[xX][0-9]{1,3})[^\\\/])*)?([sS]?(?<seasonnumber>[0-9]{1,4})[ |
| 664 | 761 | | @".*(\\|\/)(?<seriesname>[^\\\/]*)[sS](?<seasonnumber>[0-9]{1,4})[xX\.]?[eE](?<epnumber>[0-9]{1,3})((-| |
| 664 | 762 | | @".*(\\|\/)(?<seriesname>[^\\\/]*)[sS](?<seasonnumber>[0-9]{1,4})[xX\.]?[eE](?<epnumber>[0-9]{1,3})(-[xX |
| 664 | 763 | | }.Select(i => new EpisodeExpression(i) |
| 664 | 764 | | { |
| 664 | 765 | | IsNamed = true |
| 664 | 766 | | }).ToArray(); |
| | 767 | |
|
| 664 | 768 | | Compile(); |
| 664 | 769 | | } |
| | 770 | |
|
| | 771 | | /// <summary> |
| | 772 | | /// Gets or sets the folder name to extra types mapping. |
| | 773 | | /// </summary> |
| | 774 | | public Dictionary<string, ExtraType> AllExtrasTypesFolderNames { get; set; } |
| | 775 | |
|
| | 776 | | /// <summary> |
| | 777 | | /// Gets or sets list of audio file extensions. |
| | 778 | | /// </summary> |
| | 779 | | public string[] AudioFileExtensions { get; set; } |
| | 780 | |
|
| | 781 | | /// <summary> |
| | 782 | | /// Gets or sets list of external media flag delimiters. |
| | 783 | | /// </summary> |
| | 784 | | public char[] MediaFlagDelimiters { get; set; } |
| | 785 | |
|
| | 786 | | /// <summary> |
| | 787 | | /// Gets or sets list of external media forced flags. |
| | 788 | | /// </summary> |
| | 789 | | public string[] MediaForcedFlags { get; set; } |
| | 790 | |
|
| | 791 | | /// <summary> |
| | 792 | | /// Gets or sets list of external media default flags. |
| | 793 | | /// </summary> |
| | 794 | | public string[] MediaDefaultFlags { get; set; } |
| | 795 | |
|
| | 796 | | /// <summary> |
| | 797 | | /// Gets or sets list of external media hearing impaired flags. |
| | 798 | | /// </summary> |
| | 799 | | public string[] MediaHearingImpairedFlags { get; set; } |
| | 800 | |
|
| | 801 | | /// <summary> |
| | 802 | | /// Gets or sets list of album stacking prefixes. |
| | 803 | | /// </summary> |
| | 804 | | public string[] AlbumStackingPrefixes { get; set; } |
| | 805 | |
|
| | 806 | | /// <summary> |
| | 807 | | /// Gets or sets list of artist subfolders. |
| | 808 | | /// </summary> |
| | 809 | | public string[] ArtistSubfolders { get; set; } |
| | 810 | |
|
| | 811 | | /// <summary> |
| | 812 | | /// Gets or sets list of subtitle file extensions. |
| | 813 | | /// </summary> |
| | 814 | | public string[] SubtitleFileExtensions { get; set; } |
| | 815 | |
|
| | 816 | | /// <summary> |
| | 817 | | /// Gets the list of lyric file extensions. |
| | 818 | | /// </summary> |
| | 819 | | public string[] LyricFileExtensions { get; } |
| | 820 | |
|
| | 821 | | /// <summary> |
| | 822 | | /// Gets or sets list of episode regular expressions. |
| | 823 | | /// </summary> |
| | 824 | | public EpisodeExpression[] EpisodeExpressions { get; set; } |
| | 825 | |
|
| | 826 | | /// <summary> |
| | 827 | | /// Gets or sets list of video file extensions. |
| | 828 | | /// </summary> |
| | 829 | | public string[] VideoFileExtensions { get; set; } |
| | 830 | |
|
| | 831 | | /// <summary> |
| | 832 | | /// Gets or sets list of video stub file extensions. |
| | 833 | | /// </summary> |
| | 834 | | public string[] StubFileExtensions { get; set; } |
| | 835 | |
|
| | 836 | | /// <summary> |
| | 837 | | /// Gets or sets list of raw audiobook parts regular expressions strings. |
| | 838 | | /// </summary> |
| | 839 | | public string[] AudioBookPartsExpressions { get; set; } |
| | 840 | |
|
| | 841 | | /// <summary> |
| | 842 | | /// Gets or sets list of raw audiobook names regular expressions strings. |
| | 843 | | /// </summary> |
| | 844 | | public string[] AudioBookNamesExpressions { get; set; } |
| | 845 | |
|
| | 846 | | /// <summary> |
| | 847 | | /// Gets or sets list of stub type rules. |
| | 848 | | /// </summary> |
| | 849 | | public StubTypeRule[] StubTypes { get; set; } |
| | 850 | |
|
| | 851 | | /// <summary> |
| | 852 | | /// Gets or sets list of video flag delimiters. |
| | 853 | | /// </summary> |
| | 854 | | public char[] VideoFlagDelimiters { get; set; } |
| | 855 | |
|
| | 856 | | /// <summary> |
| | 857 | | /// Gets or sets list of 3D Format rules. |
| | 858 | | /// </summary> |
| | 859 | | public Format3DRule[] Format3DRules { get; set; } |
| | 860 | |
|
| | 861 | | /// <summary> |
| | 862 | | /// Gets the file stacking rules. |
| | 863 | | /// </summary> |
| | 864 | | public FileStackRule[] VideoFileStackingRules { get; } |
| | 865 | |
|
| | 866 | | /// <summary> |
| | 867 | | /// Gets or sets list of raw clean DateTimes regular expressions strings. |
| | 868 | | /// </summary> |
| | 869 | | public string[] CleanDateTimes { get; set; } |
| | 870 | |
|
| | 871 | | /// <summary> |
| | 872 | | /// Gets or sets list of raw clean strings regular expressions strings. |
| | 873 | | /// </summary> |
| | 874 | | public string[] CleanStrings { get; set; } |
| | 875 | |
|
| | 876 | | /// <summary> |
| | 877 | | /// Gets or sets list of multi-episode regular expressions. |
| | 878 | | /// </summary> |
| | 879 | | public EpisodeExpression[] MultipleEpisodeExpressions { get; set; } |
| | 880 | |
|
| | 881 | | /// <summary> |
| | 882 | | /// Gets or sets list of extra rules for videos. |
| | 883 | | /// </summary> |
| | 884 | | public ExtraRule[] VideoExtraRules { get; set; } |
| | 885 | |
|
| | 886 | | /// <summary> |
| | 887 | | /// Gets list of clean datetime regular expressions. |
| | 888 | | /// </summary> |
| | 889 | | public Regex[] CleanDateTimeRegexes { get; private set; } = Array.Empty<Regex>(); |
| | 890 | |
|
| | 891 | | /// <summary> |
| | 892 | | /// Gets list of clean string regular expressions. |
| | 893 | | /// </summary> |
| | 894 | | public Regex[] CleanStringRegexes { get; private set; } = Array.Empty<Regex>(); |
| | 895 | |
|
| | 896 | | /// <summary> |
| | 897 | | /// Compiles raw regex strings into regexes. |
| | 898 | | /// </summary> |
| | 899 | | public void Compile() |
| | 900 | | { |
| 665 | 901 | | CleanDateTimeRegexes = CleanDateTimes.Select(Compile).ToArray(); |
| 665 | 902 | | CleanStringRegexes = CleanStrings.Select(Compile).ToArray(); |
| 665 | 903 | | } |
| | 904 | |
|
| | 905 | | private Regex Compile(string exp) |
| | 906 | | { |
| 5320 | 907 | | return new Regex(exp, RegexOptions.IgnoreCase | RegexOptions.Compiled); |
| | 908 | | } |
| | 909 | | } |
| | 910 | | } |