-
Notifications
You must be signed in to change notification settings - Fork 115
/
Copy pathconfig_defaults.py
527 lines (449 loc) · 21.1 KB
/
config_defaults.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
#!/usr/bin/env python
"""Holds default config values
"""
import typing
if typing.TYPE_CHECKING:
from typing import Dict, Any, List, Optional, Union
from typing import Literal # Note: Python 3.8+ only, but mypy can check this in older Python versions
from mypy_extensions import TypedDict
TypedReplacement = TypedDict('TypedReplacement', {
"is_regex": bool,
"match": str,
"replacement": str,
})
TypedDefaults = TypedDict('TypedDefaults', {
'tvdb_api_key': Optional[str],
'select_first': bool,
'always_rename': bool,
'batch': bool,
'skip_file_on_error': bool,
'skip_behaviour': Literal['skip', 'error'],
'overwrite_destination_on_rename': bool,
'overwrite_destination_on_move': bool,
'verbose': bool,
'dry_run': bool,
'recursive': bool,
'valid_extensions': List[str],
'extension_pattern': str,
'filename_blacklist': List[str],
'windows_safe_filenames': bool,
'normalize_unicode_filenames': bool,
'lowercase_filename': bool,
'titlecase_filename': bool,
'custom_filename_character_blacklist': str,
'replace_invalid_characters_with': str,
'input_filename_replacements': List[TypedReplacement],
'output_filename_replacements': List[TypedReplacement],
'move_files_fullpath_replacements': List[TypedReplacement],
'language': str,
'search_all_languages': bool,
'move_files_enable': bool,
'move_files_confirmation': bool,
'move_files_lowercase_destination': bool,
'move_files_destination_is_filepath': bool,
'move_files_destination': str,
'move_files_destination_date': str,
'always_move': bool,
'leave_symlink': bool,
'move_files_only': bool,
'filename_patterns': List[str],
'filename_with_episode': str,
'filename_without_episode': str,
'filename_with_episode_no_season': str,
'filename_without_episode_no_season': str,
'filename_with_date_and_episode': str,
'filename_with_date_without_episode': str,
'filename_anime_with_episode': str,
'filename_anime_without_episode': str,
'filename_anime_with_episode_without_crc': str,
'filename_anime_without_episode_without_crc': str,
'multiep_join_name_with': str,
'multiep_format': str,
'episode_single': str,
'episode_separator': str,
'series_id': Optional[int],
'force_name': Optional[str],
'input_series_replacements': Dict[str, Union[int, str]],
'output_series_replacements': Dict[str, str],
'order': Literal['dvd', 'aired'],
})
# fmt: off
defaults = {
# Custom API key from www.thetvdb.com - if None, uses tvnamer's default key
'tvdb_api_key': None,
# Select first series search result
'select_first': False,
# Always rename files
'always_rename': False,
# Batch (same as select_first and always_rename)
'batch': False,
# Fail if error finding show data (thetvdb.com is down etc)
# Only functions when always_rename is True
'skip_file_on_error': True,
# Fail if error finding show data (thetvdb.com is down etc)
# Changes the default behaviour for skip_file_on_error from skip to exit
'skip_behaviour': 'skip',
# Forcefully overwrite existing files when renaming or
# moving. This potentially destroys the old file. Default is False
'overwrite_destination_on_rename': False,
'overwrite_destination_on_move': False,
# Verbose mode (debugging info)
'verbose': False,
# Dry-run mode (do nothing)
'dry_run': False,
# Recurse more than one level into folders. When False, only
# desends one level.
'recursive': False,
# When non-empty, only look for files with this extension.
# No leading dot, for example: ['avi', 'mkv', 'mp4']
'valid_extensions': [],
# Pattern for splitting filenames into basename and extension.
# Useful for matching subtitles with language codes, for example
# "extension_pattern": "(\.(eng|cze))?(\.[a-zA-Z0-9]+)$" will split "foo.eng.srt"
# into "foo" and ".eng.srt".
# Note that extensions still pass 'valid_extensions' filter, '.eng.srt' passes
# when 'srt' is specified in 'valid_extensions'.
'extension_pattern': '(\\.[a-zA-Z0-9]+)$',
# When non-empty, filter out filenames that match these expressions. Either simple
# matches or regexs can be used. The following are near enough equivalent:
# [{"is_regex": true, "match": ".*sample.*"}, {"is_regex": false, "match": "sample"}]
'filename_blacklist': [],
# Force Windows safe filenames (always True on Windows)
'windows_safe_filenames': False,
# Replace accented unicode characters with ASCII equivalents,
# removing characters than can't be translated.
'normalize_unicode_filenames': False,
# Convert output filenames to lower case (applied after replacements)
'lowercase_filename': False,
# Convert output filenames to 'Title Case' (applied after replacements)
'titlecase_filename': False,
# Extra characters to consider invalid in output filenames (which are
# replaced by the character in replace_invalid_characters_with)
'custom_filename_character_blacklist': '',
# Replacement characters for invalid filename characters
'replace_invalid_characters_with': '_',
# Replacements performed on input file before parsing.
'input_filename_replacements': [
],
# Replacements performed on files after the new name is generated.
'output_filename_replacements': [
],
# Replacements are performed on the full path used by move_files feature,
# including the filename
'move_files_fullpath_replacements': [
],
# Language to (try) and retrieve episode data in
'language': 'en',
# Search in all possible languages
'search_all_languages': True,
# Move renamed files to directory?
'move_files_enable': False,
# Separate confirmation of moving or copying renamed file? If
# False, will move files when renaming. In batch mode, will never
# prompt.
'move_files_confirmation': True,
# If true, convert the variable/dynamic parts of the destination
# to lower case. Does not affect the static parts; for example,
# if move_files_destination is set to
# '/Foo/Bar/%(seriesname)s/Season %(seasonnumber)d'
# then only the series name will be converted to lower case.
'move_files_lowercase_destination': False,
# If True, the destination path includes the destination filename,
# for example: '/example/tv/%(seriesname)s/season %(seasonnumber)d/%(originalfilename)'
'move_files_destination_is_filepath': False,
# Destination to move files to. Trailing slash is not necessary.
# Use forward slashes, even on Windows. Realtive paths are realtive to
# the existing file's path (not current working dir). A value of '.' will
# not move the file anywhere.
#
# Use Python's string formatting to add dynamic paths. Available variables:
# - %(seriesname)s
# - %(seasonnumber)d
# - %(episodenumbers)s (Note: this is a string, formatted with config
# variable episode_single and joined with episode_separator)
'move_files_destination': '.',
# Same as above, only for date-numbered episodes. The following
# variables are available:
# - %(seriesname)s
# - %(year)s
# - %(month)s
# - %(day)s
'move_files_destination_date': '.',
# Force the move-files feature to always move the file.
#
# If False, when a file is moved between partitions (or from a
# network volume), the original is left untouched (i.e it is
# copied). If True, this will delete the file from the original
# volume, after the copy has complete.
'always_move': False,
# Whenever a file is moved leave a symlink to the new file behind, named
# after the original file.
'leave_symlink': False,
# Allow user to copy files to specified move location without renaming files.
'move_files_only': False,
# Patterns to parse input filenames with
'filename_patterns': [
# [group] Show - 01-02 [crc]
r'''^\[(?P<group>.+?)\][ ]? # group name, captured for [#100]
(?P<seriesname>.*?)[ ]?[-_][ ]? # show name, padding, spaces?
(?P<episodenumberstart>\d+) # first episode number
([-_]\d+)* # optional repeating episodes
[-_](?P<episodenumberend>\d+) # last episode number
(?= # Optional group for crc value (non-capturing)
.* # padding
\[(?P<crc>.+?)\] # CRC value
)? # End optional crc group
[^\/]*$''',
# [group] Show - 01 [crc]
r'''^\[(?P<group>.+?)\][ ]? # group name, captured for [#100]
(?P<seriesname>.*) # show name
[ ]?[-_][ ]? # padding and seperator
(?P<episodenumber>\d+) # episode number
(?= # Optional group for crc value (non-capturing)
.* # padding
\[(?P<crc>.+?)\] # CRC value
)? # End optional crc group
[^\/]*$''',
# foo s01e23 s01e24 s01e25 *
r'''
^((?P<seriesname>.+?)[ \._\-])? # show name
[Ss](?P<seasonnumber>[0-9]+) # s01
[\.\- ]? # separator
[Ee](?P<episodenumberstart>[0-9]+) # first e23
([\.\- ]+ # separator
[Ss](?P=seasonnumber) # s01
[\.\- ]? # separator
[Ee][0-9]+)* # e24 etc (middle groups)
([\.\- ]+ # separator
[Ss](?P=seasonnumber) # last s01
[\.\- ]? # separator
[Ee](?P<episodenumberend>[0-9]+)) # final episode number
[^\/]*$''',
# foo.s01e23e24*
r'''
^((?P<seriesname>.+?)[ \._\-])? # show name
[Ss](?P<seasonnumber>[0-9]+) # s01
[\.\- ]? # separator
[Ee](?P<episodenumberstart>[0-9]+) # first e23
([\.\- ]? # separator
[Ee][0-9]+)* # e24e25 etc
[\.\- ]?[Ee](?P<episodenumberend>[0-9]+) # final episode num
[^\/]*$''',
# foo.1x23 1x24 1x25
r'''
^((?P<seriesname>.+?)[ \._\-])? # show name
(?P<seasonnumber>[0-9]+) # first season number (1)
[xX](?P<episodenumberstart>[0-9]+) # first episode (x23)
([ \._\-]+ # separator
(?P=seasonnumber) # more season numbers (1)
[xX][0-9]+)* # more episode numbers (x24)
([ \._\-]+ # separator
(?P=seasonnumber) # last season number (1)
[xX](?P<episodenumberend>[0-9]+)) # last episode number (x25)
[^\/]*$''',
# foo.1x23x24*
r'''
^((?P<seriesname>.+?)[ \._\-])? # show name
(?P<seasonnumber>[0-9]+) # 1
[xX](?P<episodenumberstart>[0-9]+) # first x23
([xX][0-9]+)* # x24x25 etc
[xX](?P<episodenumberend>[0-9]+) # final episode num
[^\/]*$''',
# foo.s01e23-24*
r'''
^((?P<seriesname>.+?)[ \._\-])? # show name
[Ss](?P<seasonnumber>[0-9]+) # s01
[\.\- ]? # separator
[Ee](?P<episodenumberstart>[0-9]+) # first e23
( # -24 etc
[\-]
[Ee]?[0-9]+
)*
[\-] # separator
[Ee]?(?P<episodenumberend>[0-9]+) # final episode num
[\.\- ] # must have a separator (prevents s01e01-720p from being 720 episodes)
[^\/]*$''',
# foo.1x23-24*
r'''
^((?P<seriesname>.+?)[ \._\-])? # show name
(?P<seasonnumber>[0-9]+) # 1
[xX](?P<episodenumberstart>[0-9]+) # first x23
( # -24 etc
[\-+][0-9]+
)*
[\-+] # separator
(?P<episodenumberend>[0-9]+) # final episode num
([\.\-+ ].* # must have a separator (prevents 1x01-720p from being 720 episodes)
|
$)''',
# foo.[1x09-11]*
r'''^(?P<seriesname>.+?)[ \._\-] # show name and padding
\[ # [
?(?P<seasonnumber>[0-9]+) # season
[xX] # x
(?P<episodenumberstart>[0-9]+) # episode
([\-+] [0-9]+)*
[\-+] # -
(?P<episodenumberend>[0-9]+) # episode
\] # \]
[^\\/]*$''',
# foo - [012]
r'''^((?P<seriesname>.+?)[ \._\-])? # show name and padding
\[ # [ not optional (or too ambigious)
(?P<episodenumber>[0-9]+) # episode
\] # ]
[^\\/]*$''',
# foo.s0101, foo.0201
r'''^(?P<seriesname>.+?)[ \._\-]
[Ss](?P<seasonnumber>[0-9]{2})
[\.\- ]?
(?P<episodenumber>[0-9]{2})
[^0-9]*$''',
# foo.1x09*
r'''^((?P<seriesname>.+?)[ \._\-])? # show name and padding
\[? # [ optional
(?P<seasonnumber>[0-9]+) # season
[xX] # x
(?P<episodenumber>[0-9]+) # episode
\]? # ] optional
[^\\/]*$''',
# foo.s01.e01, foo.s01_e01, "foo.s01 - e01"
r'''^((?P<seriesname>.+?)[ \._\-])?
\[?
[Ss](?P<seasonnumber>[0-9]+)[ ]?[\._\- ]?[ ]?
[Ee]?(?P<episodenumber>[0-9]+)
\]?
[^\\/]*$''',
# foo.2010.01.02.etc
r'''
^((?P<seriesname>.+?)[ \._\-])? # show name
(?P<year>\d{4}) # year
[ \._\-] # separator
(?P<month>\d{2}) # month
[ \._\-] # separator
(?P<day>\d{2}) # day
[^\/]*$''',
# foo - [01.09]
r'''^((?P<seriesname>.+?)) # show name
[ \._\-]? # padding
\[ # [
(?P<seasonnumber>[0-9]+?) # season
[.] # .
(?P<episodenumber>[0-9]+?) # episode
\] # ]
[ \._\-]? # padding
[^\\/]*$''',
# Foo - S2 E 02 - etc
r'''^(?P<seriesname>.+?)[ ]?[ \._\-][ ]?
[Ss](?P<seasonnumber>[0-9]+)[\.\- ]?
[Ee]?[ ]?(?P<episodenumber>[0-9]+)
[^\\/]*$''',
# Show - Episode 9999 [S 12 - Ep 131] - etc
r'''
(?P<seriesname>.+) # Showname
[ ]-[ ] # -
[Ee]pisode[ ]\d+ # Episode 1234 (ignored)
[ ]
\[ # [
[sS][ ]?(?P<seasonnumber>\d+) # s 12
([ ]|[ ]-[ ]|-) # space, or -
([eE]|[eE]p)[ ]?(?P<episodenumber>\d+) # e or ep 12
\] # ]
.*$ # rest of file
''',
# show name 2 of 6 - blah
r'''^(?P<seriesname>.+?) # Show name
[ \._\-] # Padding
(?P<episodenumber>[0-9]+) # 2
of # of
[ \._\-]? # Padding
\d+ # 6
([\._ -]|$|[^\\/]*$) # More padding, then anything
''',
# Show.Name.Part.1.and.Part.2
r'''(?i)^
(?P<seriesname>.+?) # Show name
[ \._\-] # Padding
(?:part|pt)?[\._ -]
(?P<episodenumberstart>[0-9]+) # Part 1
(?:
[ \._-](?:and|&|to) # and
[ \._-](?:part|pt)? # Part 2
[ \._-](?:[0-9]+))* # (middle group, optional, repeating)
[ \._-](?:and|&|to) # and
[ \._-]?(?:part|pt)? # Part 3
[ \._-](?P<episodenumberend>[0-9]+) # last episode number, save it
[\._ -][^\\/]*$ # More padding, then anything
''',
# Show.Name.Part1
r'''^(?P<seriesname>.+?) # Show name\n
[ \\._\\-] # Padding\n
[Pp]art[ ](?P<episodenumber>[0-9]+) # Part 1\n
[\\._ -][^\\/]*$ # More padding, then anything\n
''',
# show name Season 01 Episode 20
r'''^(?P<seriesname>.+?)[ ]? # Show name
[Ss]eason[ ]?(?P<seasonnumber>[0-9]+)[ ]? # Season 1
[Ee]pisode[ ]?(?P<episodenumber>[0-9]+) # Episode 20
[^\\/]*$''', # Anything
# show.name.e123.abc
r'''^(?P<seriesname>.+?) # Show name
[ \._\-] # Padding
[Ee](?P<episodenumber>[0-9]+) # E123
[\._ -][^\\/]*$ # More padding, then anything
''',
],
# Formats for renamed files. Variations for with/without episode,
# and with/without season number.
'filename_with_episode':
'%(seriesname)s - [%(seasonnumber)02dx%(episode)s] - %(episodename)s%(ext)s',
'filename_without_episode':
'%(seriesname)s - [%(seasonnumber)02dx%(episode)s]%(ext)s',
# Seasonless filenames.
'filename_with_episode_no_season':
'%(seriesname)s - [%(episode)s] - %(episodename)s%(ext)s',
'filename_without_episode_no_season':
'%(seriesname)s - [%(episode)s]%(ext)s',
# Date based filenames.
# Series - [2012-01-24] - Ep name.ext
'filename_with_date_and_episode':
'%(seriesname)s - [%(episode)s] - %(episodename)s%(ext)s',
'filename_with_date_without_episode':
'%(seriesname)s - [%(episode)s]%(ext)s',
# Anime filenames.
# [AGroup] Series - 02 - Some Ep Name [CRC1234].ext
# [AGroup] Series - 02 [CRC1234].ext
'filename_anime_with_episode':
'[%(group)s] %(seriesname)s - %(episode)s - %(episodename)s [%(crc)s]%(ext)s',
'filename_anime_without_episode':
'[%(group)s] %(seriesname)s - %(episode)s [%(crc)s]%(ext)s',
# Same, without CRC value
'filename_anime_with_episode_without_crc':
'[%(group)s] %(seriesname)s - %(episode)s - %(episodename)s%(ext)s',
'filename_anime_without_episode_without_crc':
'[%(group)s] %(seriesname)s - %(episode)s%(ext)s',
# Used to join multiple episode names together (only when episode names are different)
'multiep_join_name_with': ', ',
# Format for multi-episode names (only when episode names are the same)
# Formats mapping key 'episodename' (used in variables 'filename_with_episode' etc.)
'multiep_format': '%(epname)s (%(episodemin)s-%(episodemax)s)',
# Format for numbers (python string format), %02d does 2-digit padding, %d will cause no padding
'episode_single': '%02d',
# String to join multiple numbers in mapping key 'episode' (used in variables 'filename_with_episode' etc.)
'episode_separator': '-',
# Series ID to use instead of searching if the value is set
'series_id': None,
# Forced Name to use
'force_name': None,
# replace series names before/after passing to TVDB
# input replacements are regular expressions for the series as parsed from
# filenames, for instance adding or removing the year, or expanding abbreviations
'input_series_replacements': {},
# output replacements are for transforms of the TVDB series names
# since these are perfectly predictable, they are simple strings
# not regular expressions
'output_series_replacements': {},
# use dvd episode order of tvdb, instead of aired order
'order': 'aired',
} # type: TypedDefaults
# fmt: on