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
#!/usr/bin/python
import math
from lxml import etree
time = {}
time_mod = {}
time_temp= {}
counter = 0
smil = etree.parse('sound_tale001.smil')
root = smil.getroot()
body = smil.find('body')
seq = body.find('seq')
count = len(seq)
par = seq.findall('par')
src = par[0][1].attrib['src']
src = src.lower()
src_len = len(src)
for par in seq.findall('par'):
counter = counter + 1
for audio in par.findall('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)
print("time_mod")
print (time_mod)
print("--------")
cue_performer = "PERFORMER \"\""
cue_title = "TITLE \"\""
cue_file = "FILE \"" + src + "\" MP3"
print (cue_performer)
print (cue_title)
print (cue_file)
for key in time:
cue_track = " TRACK " + '%0*d' % (2, key) + " AUDIO"
cue_track_performer = " PERFORMER \"\""
cue_track_title = " TITLE \"" + src[:-4] + "_" +'%0*d' % (3, key) + "\""
cue_track_index = " INDEX 01 " + time_mod[key]
print (cue_track)
print (cue_track_performer)
print (cue_track_title)
print (cue_track_index)
#S.ljust(width, fillchar=" ") Делает длину строки не меньшей width, по необходимости заполняя последние символы символом fillchar
#S.rjust(width, fillchar=" ") Делает длину строки не меньшей width, по необходимости заполняя первые символы символом fillchar
#not work - <smil xmlns="http://www.w3.org/ns/SMIL" xmlns:smil="http://www.w3.org/ns/SMIL"
#work - <smil xmlns:xhtml="http://www.w3.org/ns/SMIL" xmlns:smil="http://www.w3.org/ns/SMIL"