Smil to Cue converter

 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
#!/usr/bin/python
import os
import sys
import math
from lxml import etree
directory = '/home/tsvetkov/Desktop/temp'
files = os.listdir(".")
smils = filter(lambda x: x.endswith('.smil'), files)
for i in smils:
time = {}
time_mod = {}
time_temp= {}
counter = 0
filename = i.split('.')[0]
cue_ext = '.cue'
smil_ext = '.smil'
#filename = 'sound_tale001'
cue_file = open(filename + cue_ext, 'w')
smil = etree.parse(filename + smil_ext)
root = smil.getroot()
body = smil.find('{http://www.w3.org/ns/SMIL}body')
seq = body.find('{http://www.w3.org/ns/SMIL}seq')
count = len(seq)
par = seq.findall('{http://www.w3.org/ns/SMIL}par')
src = par[0][1].attrib['src']
src = src.lower()
src_len = len(src)
for par in seq.findall('{http://www.w3.org/ns/SMIL}par'):
counter = counter + 1
for audio in par.findall('{http://www.w3.org/ns/SMIL}audio'):
time[counter] = audio.attrib['clipBegin']
for key in time:
time_temp[key] = time[key].split(":")
time_temp[key][2] = time_temp[key][2].split(".")
try:
time_temp[1][2][1]
except IndexError:
time_temp[1][2].append("0")
for key in time_temp:
time_temp[key][2][1]= str(math.trunc(float(time_temp[key][2][1])*0.75))
time_mod[key] = time_temp[key][1].zfill(2) +":" + time_temp[key][2][0].zfill(2) +":" + time_temp[key][2][1].zfill(2)
cue_performer = 'PERFORMER \"\"'
cue_title = "TITLE \"\""
cue_filesrc = "FILE \"" + src + "\" MP3"
cue_file.write (cue_performer + "\n")
cue_file.write (cue_title + "\n")
cue_file.write (cue_filesrc + "\n")
for key in time:
cue_track = " TRACK " + '%02d' % (key) + " AUDIO"
cue_track_performer = " PERFORMER \"\""
cue_track_title = " TITLE \"" + src[:-4] + "_" +'%03d' % (key) + "\""
cue_track_index = " INDEX 01 " + time_mod[key]
cue_file.write (cue_track + "\n")
cue_file.write (cue_track_performer + "\n")
cue_file.write (cue_track_title + "\n")
cue_file.write (cue_track_index + "\n")
cue_file.close()