-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
158 lines (102 loc) · 5.21 KB
/
main.py
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.video import Video
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.clock import Clock
from kivy.uix.popup import Popup
import time, os, sys
from kivy.animation import Animation
class LabelShadow(Label):
pass
class Karaotool(FloatLayout):
def __init__(self, **kwargs):
super(Karaotool, self).__init__(**kwargs)
self.source = kwargs.get('source', None)
if self.source == None:
self.selecttextfile = Popup(title='Select the lirycs')
self.selecttextfile.content = BoxLayout(orientation='vertical')
self.selecttextfile.content.add_widget(Button(text='Seleccionar archivo') )
self.selecttextfile.content.add_widget(Button(text='Insertar texto') )
self.selecttextfile.open()
else:
self.base_filename = os.path.splitext(self.source)[0]
with open(self.base_filename + '.kot') as f: #open karaotool text file
self.content = f.readlines()
self.line = 0;
self.video = Video(source=self.source, state='play', allow_stretch=True, keep_ratio=False)
self.video.bind(on_loaded=self.on_loaded)
self.kar_english = LabelShadow(text='KARAOKELAND',
size_hint_y=None,
color=(0,0,0,1),
font_size=32 )
self.add_widget(self.video)
self.add_widget(self.kar_english)
#si existe el archivo con los tiempos
if os.path.exists(self.base_filename + '.kos'):
self.kar_spanish = LabelShadow(text='KARAOKELAND ESP',
size_hint_y=1,
color=(0,0,0,1),
font_size=32 )
self.add_widget(self.kar_spanish)
self.fsteps = open(self.base_filename + '.kos') #steps
self.steps = self.fsteps.readlines()
try:
self.efsteps = open(self.base_filename + '.koe') #subtitulos en lenguaje traducido
self.esteps = self.efsteps.readlines()
except:
pass
#Clock.schedule_interval(self.stepchecker, .1)
self.video.bind(position=self.on_position)
self.cursteptime = self.steps[self.line]
else:
self.btn_stepline = Button(text='Iniciar !',
#size_hint=(1,None),
on_press=self.nextline
)
self.add_widget(self.btn_stepline, index=len(self.children) )
#open for steps creation
self.fsteps = open(self.base_filename + '.kos', 'w+') #karaotool steps
def on_loaded(self, w):
print("Iniciando video")
def on_position(self, w, val):
if val > float(self.cursteptime):
try:
if hasattr(self, "old_kar_english"):
self.remove_widget(self.old_kar_english)
self.old_kar_english = self.kar_english
#subir titulo
Animation(y=self.old_kar_english.y+50, opacity=.5, duration=.5).start(self.old_kar_english)
#self.kar_english.y += 80
self.kar_english = LabelShadow(text=self.content[self.line],
size_hint_y=None,
color=(0,0,0,1),
font_size=32 )
self.add_widget(self.kar_english)
try:
self.kar_spanish.text = self.esteps[self.line]
except:
pass
self.line += 1
#print "Step: ", self.video.position
self.cursteptime = self.steps[self.line]
except:
self.kar_english.text = "END"
self.kar_spanish.text = "FIN"
def nextline(self, w):
try:
#advance one line
self.kar_english.text = self.content[self.line]
self.line += 1
#self.kar_english.pos.y += 200
self.fsteps.write(str(self.video.position) + '\n')
except:
self.kar_english.text = "FIN"
class Karaolang(FloatLayout):
pass
if __name__ == '__main__':
from kivy.app import App
class KaraolangApp(App):
def build(self):
return Karaotool(source=sys.argv[1])
KaraolangApp().run()