-
Notifications
You must be signed in to change notification settings - Fork 0
/
TEDDownloaderConfig.py
329 lines (278 loc) · 10.7 KB
/
TEDDownloaderConfig.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
# -*- coding: utf-8 -*-
from Tkinter import *
import ConfigParser
import codecs
import locale
import os
locale.setlocale(locale.LC_ALL, '')
styleTextTemplate='''<STYLE TYPE="text/css">
<!--
P { margin-left:2pt; margin-right:2pt; margin-bottom:1pt;
margin-top:1pt; font-size:20pt; text-align:center;
font-family:Arial, Sans-serif; font-weight:bold; color:white;
}
.%(className)s {Name: %(transLang)s; lang: %(iso639ID)s-%(iso3166ID)s; SAMI_TYPE: CC;}
.ENCC {Name: English; lang: en-US; SAMI_TYPE: CC;}
-->
</STYLE>'''
langfileTextTemplate='''Afrikaans afr af AF
Albanian alb sq AL
Arabic ara ar XX
Armenian arm hy AM
Assamese asm as XX
Azerbaijani aze az AZ
Basque baq eu XX
Bengali ben bn BD
Bislama bis bi XX
Bosnian bos bs BA
Bulgarian bul bg BG
Burmese(Myanmar) bur my MM
Catalan cat ca XX
Chinese(Simplified) chi_hans zh CN
Chinese(Traditional) chi_hant zh CN
Chinese,Yue(Cantonese) yue zh CN
Croatian scr hr HR
Czech cze cs CZ
Danish dan da XX
Dutch dut nl XX
English eng en US
Esperanto epo eo XX
Estonian est et EE
Filipino(Pilipino) fil xx XX
Finnish fin fi XX
French(Canada) fre_ca fr FR
French(France) fre_fr fr FR
Galician glg gl XX
Georgian geo ka GE
German ger de DE
Greek gre el GR
Gujarati guj gu XX
Hausa hau ha XX
Hebrew heb he XX
Hindi hin hi XX
Hungarian hun hu HU
Icelandic ice is IS
Indonesian ind id ID
Italian ita it IT
Japanese jpn ja JP
Kannada kan kn XX
Kazakh kaz kk KZ
Khmer(Cambodian) khm km KH
Kirghiz(Kyrgyz) kir ky KG
Korean kor ko KR
Latvian lav lv LV
Lithuanian lit lt LT
Macedonian mac mk MK
Malay may ms MY
Malayalam mal ml XX
Maltese mlt mt XX
Marathi mar mr XX
Mongolian mon mn MN
Nepali nep ne NP
Norwegian nor no NO
Norwegian,Bokmål(Bokmaal) nob nb NO
Norwegian,Nynorsk nno nn NO
Persian(Farsi) per fa XX
Polish pol pl PL
Portuguese(Brazil) por_br pt BR
Portuguese(Portugal) por_pt pt PT
Romanian rum ro RO
Romanian,Macedo(Aromanian) rup ro RO
Russian rus ru RU
Serbian scc sr CS
Serbo-Croatian hbs hr HR
Slovak slo sk SK
Slovenian slv sl SI
Spanish spa es ES
Swahili swa sw XX
Swedish swe sv SE
Tagalog tgl tl XX
Tamil tam ta XX
Telugu tel te XX
Thai tha th TH
Turkish tur tr TR
Ukrainian ukr uk UA
Urdu urd ur XX
Uzbek uzb uz UZ
Vietnamese vie vi VN'''
def getConfig():
global config, transLang, encoding, autoDown, videoQuality, downAudio, downVideo, className
config = ConfigParser.RawConfigParser()
config.read('./config.ini')
try:
transLang = config.get('Config', 'Lang')
except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
config.add_section('Config')
lang = locale.getlocale()[0].split('_')[0]
config.set('Config', 'Lang', lang)
transLang = lang
try:
encoding = config.get('Config', 'Encoding')
except ConfigParser.NoOptionError:
config.set('Config', 'Encoding', sys.stdout.encoding)
encoding = sys.stdout.encoding
try:
className = config.get('Config', 'ClassName')
except ConfigParser.NoOptionError:
config.set('Config', 'ClassName', 'KRCC')
className = 'KRCC'
try:
autoDown = config.getboolean('Config', 'Auto_Down')
except ConfigParser.NoOptionError:
config.set('Config', 'Auto_Down', 'false')
autoDown = False
try:
videoQuality = config.getint('Config', 'Quality')
except ConfigParser.NoOptionError:
config.set('Config', 'Quality', 1)
videoQuality = 1
try:
downAudio = config.getboolean('Config', 'Down_Audio')
except ConfigParser.NoOptionError:
config.set('Config', 'Down_Audio', 'false')
downAudio = False
try:
downVideo = config.getboolean('Config', 'Down_Video')
except ConfigParser.NoOptionError:
config.set('Config', 'Down_Video', 'true')
downVideo = True
with open('./config.ini', 'w') as configfile:
config.write(configfile)
configfile.close()
def getStyle():
global styleText, styleTextTemplate
try:
with open('./style.txt', 'r') as stylefile:
styleText = stylefile.read()
stylefile.close()
except Exception, msg:
print msg
print 'created a new style file'
styleText = styleTextTemplate
with open('./style.txt', 'w') as stylefile:
stylefile.write(styleText)
stylefile.close()
def initProgram():
print '###################################################################'
print '## TED Video & Subtitle Downloader Configuration ##'
print '## ##'
print '## made by gigony ##'
print '## http://gigony.tistory.com ##'
print '## https://github.com/gigony/TED-Downloader ##'
print '###################################################################'
print
getConfig()
getStyle()
class App:
def __init__(self, master):
global transLang, qualityValue, isAutoDown, isDownAudio, isDownVideo, videoQuality, autoDown, downAudio, downVideo, encoding, className
qualityValue = IntVar()
isAutoDown = IntVar()
isDownAudio = IntVar()
isDownVideo = IntVar()
self.button = Button(master, text='Save', command=self.save)
self.button.pack(side=BOTTOM)
self.encodingLabel = Label(master, text="Encoding")
self.encodingLabel.pack(side=TOP)
self.encodingText = Text(master, width=10, height=1)
self.encodingText.insert(END, encoding)
self.encodingText.pack(side=TOP)
self.classNameLabel = Label(master, text="Class Name")
self.classNameLabel.pack(side=TOP)
self.classNameText = Text(master, width=10, height=1)
self.classNameText.insert(END, className)
self.classNameText.pack(side=TOP)
self.languageLabel = Label(master, text="\nLanguage")
self.languageLabel.pack(side=TOP)
QUALITY = [("Low-res", 0), ("Standard-res", 1), ("Hi-res", 2)]
for text, mode in QUALITY:
resBtn = Radiobutton(master, text=text, variable=qualityValue, value=mode)
resBtn.pack(side=BOTTOM, anchor=W, fill='x')
qualityValue.set(videoQuality)
self.downVideoBtn = Checkbutton(master, text='Download Video', variable=isDownVideo)
self.downVideoBtn.pack(side=BOTTOM)
if downVideo:
self.downVideoBtn.select()
self.downAudioBtn = Checkbutton(master, text='Download Audio', variable=isDownAudio)
self.downAudioBtn.pack(side=BOTTOM)
if downAudio:
self.downAudioBtn.select()
self.autoDownBtn = Checkbutton(master, text='Auto Download', variable=isAutoDown)
self.autoDownBtn.pack(side=BOTTOM)
if autoDown:
self.autoDownBtn.select()
scrollbar = Scrollbar(master)
self.listbox = Listbox(master, yscrollcommand=scrollbar.set, selectmode=SINGLE)
scrollbar.config(command=self.listbox.yview)
scrollbar.pack(side=RIGHT, fill=Y)
self.listbox.pack(side=LEFT, fill=BOTH, expand=1)
self.languageList = self.getLanguageList()
count = 0
found = False
for languageName in self.languageList:
self.listbox.insert(END, languageName)
if languageName == transLang:
found = True
self.listbox.selection_set(count)
self.listbox.see(count)
count += 1
if not found:
self.listbox.selection_set(0)
#delete title-list file
titleAddressFile = './VIDEO/'+'titleList-address.txt'
if os.access(titleAddressFile,os.F_OK):
os.remove(titleAddressFile)
def getLanguageList(self):
global langfileTextTemplate
result = []
try:
with codecs.open('./language.txt', encoding='utf-8') as langfile:
for langText in langfile:
tokens = langText.replace('\r', '').replace('\n', '').split('\t')
result += [tokens[0]]
except Exception, msg:
print msg
print 'created a new language file'
langfileText=langfileTextTemplate.replace(' ','\t')
with open('./language.txt', 'w') as langfile:
langfile.write(langfileText)
langfile.close()
with codecs.open('./language.txt', encoding='utf-8') as langfile:
for langText in langfile:
tokens = langText.replace('\r', '').replace('\n', '').split('\t')
result += [tokens[0]]
return result
def save(self):
global qualityValue, isAutoDown
items = self.listbox.curselection()
language = self.listbox.get(items[0])
encoding = self.encodingText.get(1.0, 2.0)
className = self.classNameText.get(1.0, 2.0)
root.destroy()
config.set('Config', 'Lang', language)
config.set('Config', 'Quality', qualityValue.get())
if isAutoDown.get() == 1:
config.set('Config', 'Auto_Down', 'true')
else:
config.set('Config', 'Auto_Down', 'false')
if isDownVideo.get() == 1:
config.set('Config', 'Down_Video', 'true')
else:
config.set('Config', 'Down_Video', 'false')
if isDownAudio.get() == 1:
config.set('Config', 'Down_Audio', 'true')
else:
config.set('Config', 'Down_Audio', 'false')
config.set('Config', 'Encoding', encoding)
config.set('Config', 'ClassName', className)
with open('./config.ini', 'w') as configfile:
config.write(configfile)
configfile.close()
def initComponent():
global root
root = Tk(className=' TED Downloader Configuration')
root.geometry("%dx%d" % (300, 400))
app = App(root)
root.mainloop()
initProgram()
initComponent()