-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile-recordings
executable file
·81 lines (66 loc) · 2.8 KB
/
file-recordings
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
#!/usr/bin/python
# -*- coding: iso-latin-1 -*-
################################################################################
# Makes a mass conversion of call files
################################################################################
import sys,re,os
files = sys.argv[1:]
def convertCaller(caller):
caller = caller.replace("ö".decode("iso-8859-1").encode("utf-8"), "o")
caller = caller.replace("ä".decode("iso-8859-1").encode("utf-8"), "a")
caller = caller.replace("Ö".decode("iso-8859-1").encode("utf-8"), "o")
caller = caller.replace("Ä".decode("iso-8859-1").encode("utf-8"), "a")
caller = caller.replace(" ", "_")
return caller
for file in files:
slashpos = file.rfind('/')
if slashpos != -1:
filename = file[slashpos+1:]
else:
filename = file
caller = None
newname = None
# Try different name conversions
# Typical for Boldbeast recorder in XCoverS2
m = re.match(r'^([^_]+)_#?\d+_([\d-]+) ([\d\.]+)_([IO])\.(3GP|AMR|MP4)$', filename)
if m:
(caller, date, time, io, filetype) = m.groups()
# Typical for Boldbeast recorder in XperiaZ3
m = re.match(r'^([\d-]+) ([\d\.]+)_([^_]+)_-\d+_([IO])\.(3GP|AMR|MP4)$', filename)
if m:
(date, time, caller, io, filetype) = m.groups()
# Unknown calller in Boldbeast recorder in XperiaZ3
m = re.match(r'^([\d-]+) ([\d\.]+)_-(\d+)_([IO])\.(3GP|AMR|MP4)$', filename)
if m:
(date, time, caller, io, filetype) = m.groups()
if caller:
caller = convertCaller(caller)
newname = "puhelu-%s_%s_%s_%s.mp3" %(date, time, caller, io)
# Create the directory if necessary
m = re.match(r'(\d{4})-(\d{2})-(\d{2})', date)
(year, month, day) = m.groups()
newdir = "%s/%s-%s" % (year, year, month)
if not os.path.exists(newdir):
if os.system("mkdir %s" % (newdir)):
print "Failed to create %s" % (newdir)
sys.exit(1)
newname = "%s/%s" % (newdir, newname)
if not os.path.exists(newname):
filequoted = re.sub(r'([ ])', r'\\\1', file)
if filetype == "AMR":
cmd = "ffmpeg -i %s -ar 22050 %s" % (filequoted, newname)
elif filetype == "MP4":
cmd = "ffmpeg -i %s -ar 22050 %s" % (filequoted, newname)
elif filetype == "3GP":
cmd = "ffmpeg -i %s -c:a libmp3lame -ar 22050 %s" % (filequoted, newname)
else:
print "Do not know how to convert %s" % (filequoted)
cmd = None
if cmd:
print "Converting %s -> %s..." % (file, newname)
if os.system(cmd):
print "Failed:"
print cmd
sys.exit(1)
else:
print "Could not convert %s" % (file)