-
Notifications
You must be signed in to change notification settings - Fork 0
/
scrapz.txt
101 lines (89 loc) · 4.33 KB
/
scrapz.txt
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
filename:
The.Show.S01E01.The.Episode.Title.avi
parse string:
%show_name%.S%season%E%episode%.%episode_title%.%extension%
rename mask:
%season%%episode% - %episode_title%.%extension%
algorithm brainstorm:
parse the filename splitting on character sets which don't appear between matched '%' in the parse string
split the file on above character sets, storing splits as parse string variables
this could be done without regex by recursively splitting the string
splitTokens = ('.S','E','.','.')
user inputs naming mask variables + regex
create a dictionary entry for each parse string variable
key = parse string variable ( e.g. %season%)
value = related string split in file name
parse naming mask string into dictionary of variables + regex
parse renaming mask and create renamed files dictionary
key = old file name
value = new file name
one (sloppy) algo for doing this is to simply replace every occurrence of a namingMaksk key with its related value
this should be improved later to only replace those keys present in the renaming mask
another approach is to use Python's regex functions and identify mask variables in the renaming mask
then use the groups feature to iteratively assign and substitute variables
rename file according to values in rename_mask dictionary
new dictionary with entries with values for naming mask variables
must parse each file name using naming mask dictionary first
results stored in renaming mask dictionary
processFile():
apply regex patterns in namingMask dictionary and store results for each in renamingMask dictionary
regex search for namingMask variables in renamingMaskString
re.findall() will return all occurrences of a pattern
use the resulting groups to assign values from renamingMask dictionary
assume that, for the time being, you've only defined variables you care about using in the renaming mask
for each key in namingMask:
se
warning conditions:
no splitting tokens given -- i.e. all mask variables passed
e.g. %show_name%%season%%extension%
incomplete parse string variable definitions
i.e. odd number of '%' in parse string
complications:
need to write a parser for the parse string variables
parse string variables may not be the first substrings in the file name
writing the regex using the split
version ideas:
revise the app to be OO
rn object operates on a list of files
file list is internal to the object?
see class interface section
v1 is just a simple regex renamer
takes a regex string and a list of files
outputs an example of the resulting rename
prompts user for continue or abandon
if continue, rename all files according to result
variation on the above:
regex string assigns parse variables to regex, e.g.:
"%season% = S(\d{2}) || %episode% = E(\d{2})"
split the regex string on the separator "||"
for each split regex string:
split each substring on "=", then trim
add %parser var% to dictionary as key with regex as value
iterate over dictionary keys, using their values as regex to search through file name for matches
create second dictionary with same keys, but actual match values
rename file according to rename mask
ideas for extensions:
pass a file which contains formatted file names
identify search string in file name and rename matching files using names in input file
expand the app to become a broad filename utility
replace substrings in all files (e.g. "." -> " ")
maintain a log file for all rename operations
this should be on by default, and can be read back into the app to reverse renamings
description of the program's objectives:
the program should take a list of files and rename them, according to a renaming mask including user-defined variables
the program should accept, as input, a list of similarly-named files to be renamed
the program should also accept, as input, a string defining variables comprised of regex expressions matching
substrings of the file name
the program should accept, as input, a string defining a renaming mask which uses a combination of the
variables and user-input strings
the program should rename the list of files in accordance with the renaming mask
class interface notes:
properties:
file list
naming mask
??should this be abstracted into a class of its own??
renaming mask
methods:
set file list
set matching variables
set renaming mask