forked from lachlan-00/rb-fileorganizer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtools.py
More file actions
54 lines (43 loc) · 1.79 KB
/
tools.py
File metadata and controls
54 lines (43 loc) · 1.79 KB
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
#!/usr/bin/env python3
""" Fileorganizer tools
----------------Authors----------------
Lachlan de Waard <lachlan.00@gmail.com>
Wolter Hellmund <wolterh6@gmail.com>
----------------Licence----------------
Creative Commons - Attribution Share Alike v3.0
"""
import os
import fileops
# Create a folder if non-existant, and return it
def folderize(configurator, folder):
""" Create folders for file operations """
dirpath = ((configurator.get_val('locations'))[0]
+ '/').replace('file:///', '/')
if not os.path.exists(dirpath + folder):
os.makedirs(dirpath + folder)
return os.path.normpath(dirpath + folder)
# Replace the placeholders with the correct values
def data_filler(files, string):
""" replace string data with metadata from current item """
string = str(string)
for key in fileops.RB_METATYPES:
if ('%' + key) in string:
if key == 'aa':
artisttest = files.get_metadata('aa')
if artisttest == '':
string = string.replace(('%' + key),
process(files.get_metadata('ta')))
print(string + ' ALBUM ARTIST NOT FOUND')
else:
string = string.replace(('%' + key),
process(files.get_metadata(key)))
print(string + ' ALBUM ARTIST FOUND')
else:
string = string.replace(('%' + key),
process(files.get_metadata(key)))
return string
# Process names and replace any undesired characters
def process(string):
""" Prevent / character to avoid creating folders """
string = string.replace('/', '_') # if present
return string