-
Notifications
You must be signed in to change notification settings - Fork 0
/
TEDDownloaderGUI.py
660 lines (579 loc) · 25.4 KB
/
TEDDownloaderGUI.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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
# -*- coding: utf-8 -*-
import locale
from bs4 import BeautifulSoup
locale.setlocale(locale.LC_ALL, '')
import os
import sys
import json
import urllib
import urllib2
import ConfigParser
import codecs
import time
import socket
import glob
from urllib import *
from Tkinter import *
import Queue
import threading,thread
import functools
class myURLOpener(urllib.FancyURLopener):
"""Create sub-class in order to overide error 206. This error means a
partial file is being sent,
which is ok in this case. Do nothing with this error.
"""
def http_error_206(self, url, fp, errcode, errmsg, headers, data=None):
pass
# Convert TED Subtitles to SMI Subtitles
def convertTEDSubtitlesToSMISubtitles(jsonString,talkIntroDuration) :
global className,transLang,iso639ID,iso3166ID
smiContent = '''<SAMI>
<HEAD>
<TITLE> TED Downloader by gigony (http://gigony.tistory.com ) </TITLE>
'''+styleText%{"className":className,"transLang":transLang,"iso639ID":iso639ID,"iso3166ID":iso3166ID}+'''
</HEAD>
<BODY>
'''
if not transLang=='English':
jsonObject = json.loads( jsonString[0])
for caption in jsonObject['captions'] :
smiContent+='<SYNC Start=%s><P Class=%s>%s'%(str(talkIntroDuration + caption['startTime']),className,os.linesep)
smiContent+= caption['content'] +os.linesep
jsonObject = json.loads( jsonString[1])
if not jsonObject.has_key('captions'):
smiContent+='<SYNC Start=%s><P Class=ENCC>%s'%(str(talkIntroDuration),os.linesep)
smiContent+= "Subtitle is not prepared yet."+os.linesep
smiContent+= "Please re-download the subtitle a few days later"+os.linesep
else:
for caption in jsonObject['captions'] :
smiContent+='<SYNC Start=%s><P Class=ENCC>%s'%(str(talkIntroDuration + caption['startTime']),os.linesep)
smiContent+= caption['content'] +os.linesep
smiContent+='''</BODY>
</SAMI>'''
return smiContent
# Convert TED Subtitles to TXT Subtitles
def convertTEDSubtitlesToTXTSubtitles(jsonString) :
global transLang
txtContent=''
if not transLang=='English':
jsonObject = json.loads( jsonString[0])
txtContent='##'+transLang+'##'+ os.linesep
for caption in jsonObject['captions'] :
if not txtContent.endswith(' '):
txtContent+=' '
txtContent+= caption['content']
jsonObject = json.loads( jsonString[1])
txtContent+=os.linesep +'##English##'+ os.linesep
if not jsonObject.has_key('captions'):
return None
else:
for caption in jsonObject['captions'] :
if not txtContent.endswith(' '):
txtContent+=' '
txtContent+= caption['content']
return txtContent
def getTEDSubtitlesByTalkID ( talkId , language ) :
tedSubtitleUrl = 'http://www.ted.com/talks/subtitles/id/' + str(talkId) + '/lang/' + language
req = urllib2.Request(tedSubtitleUrl)
response = urllib2.urlopen(req)
result = response.read()
return ( result )
def getTranslationList(language):
global encoding,stopRetriveList
resultList=[]
titleList=[]
oldtext=""
pageIndex=1
while True:
try:
req = urllib2.Request('http://www.ted.com/talks?lang=%s&event=&duration=&sort=newest&tag=&page=%d'%(language,pageIndex))
req.add_header("Host","www.ted.com")
req.add_header("Connection","keep-alive")
req.add_header("Connection","close")
req.add_header("X-Requested-With","XMLHttpRequest")
req.add_header("User-Agent","Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.52 Safari/536.5")
req.add_header("Accept","*/*")
req.add_header("Referer","http://www.ted.com/talks?lang=ko&event=&duration=&sort=newest&tag=")
# req.add_header("Accept-Encoding","gzip,deflate,sdch")
req.add_header("Accept-Language","ko-KR,ko;q=0.8,en-US;q=0.6,en;q=0.4")
r = urllib2.urlopen(req,timeout=1.5)
text=r.read()
r.close()
if text==oldtext:
break
oldtext=text
soup = BeautifulSoup(text)
for link in soup.find_all('li'):
em=link.find('em')
postInfo=em.get_text().replace("\n","").replace("\t","")
a=link.find('a')
title=a['title']
href=a['href']
resultList+=['http://www.ted.com'+href]
titleList+=[postInfo+"|"+title]
pageIndex=pageIndex+1
if stopRetriveList: # if canceled
return ([],[])
print ".",
except Exception,msg:
print 't',
time.sleep(0.1)
txtFile = open ( './VIDEO/'+'titleList.txt' , 'w' )
addFile = open ( './VIDEO/'+'titleList-address.txt' , 'w' )
for i in range(len(titleList)):
#for element in titleList:
txtFile.write( titleList[i].encode ( encoding,'xmlcharrefreplace').strip() )
txtFile.write(os.linesep)
addFile.write( titleList[i].encode ( encoding,'xmlcharrefreplace').strip() )
addFile.write("\t|"+resultList[i].strip())
addFile.write(os.linesep)
txtFile.close()
addFile.close()
return ( resultList,titleList )
def getConfig():
global config,transLang,tedLangID,iso639ID,iso3166ID,encoding,autoDown,videoQuality,downVideo,downAudio,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:
downVideo=config.getboolean('Config','Down_Video')
except ConfigParser.NoOptionError:
config.set('Config','Down_Video','true')
downVideo=True
try:
downAudio=config.getboolean('Config','Down_Audio')
except ConfigParser.NoOptionError:
config.set('Config','Down_Audio','false')
downAudio=False
with open('./config.ini', 'w') as configfile:
config.write(configfile)
configfile.close()
isFound=False
with codecs.open('./language.txt',encoding='utf-8') as langfile:
for langText in langfile:
tokens=langText.replace('\r','').replace('\n','').split('\t')
if tokens[0]==transLang:
tedLangID,iso639ID,iso3166ID=(tokens[2],tokens[2],tokens[3])
isFound=True
langfile.close()
return isFound
def getStyle():
global styleText
try:
with open('./style.txt','r') as stylefile:
styleText=stylefile.read()
stylefile.close()
except Exception,msg:
print msg
return False
return True
def isExistTEDFile(address,fileList):
splits = address.split ( '/' )
pattern = '_'+splits[len ( splits )-1].split ('.')[0]
for filename in fileList:
if filename.find(pattern)>=0:
filename=filename[:-3]
if os.access(filename+'url',os.F_OK) or (((os.access(filename+'mp3',os.F_OK) and os.path.getsize(filename+'mp3')>0) or (os.access(filename+'mp4',os.F_OK) and os.path.getsize(filename+'mp4')>0)) and os.access(filename+'smi',os.F_OK) and os.path.getsize(filename+'smi')>0 and os.access(filename+'txt',os.F_OK) and os.path.getsize(filename+'txt')>0):
return True
return False
def initProgram():
global stopRetriveList
socket.setdefaulttimeout(300)
print '##########################################################'
print '## TED Video & Subtitle Downloader Ver 2.4.1(2013-03-24)##'
print '## ##'
print '## made by gigony ##'
print '## http://gigony.tistory.com ##'
print '## https://github.com/gigony/TED-Downloader ##'
print '##########################################################'
print
isConfigOK=getConfig()
if not isConfigOK:
print "Config.ini file is not correct! Please run 'config.exe'"
return False
isStyleOK=getStyle()
if not isStyleOK:
print "style.txt file is not correct! Please modify 'style.txt'"
return False
# make VIDEO folder
if not os.path.exists("./VIDEO/"):
os.makedirs("./VIDEO/")
stopRetriveList=False
return True
def getTEDFileList():
return glob.glob('VIDEO/*.mp4')+glob.glob('VIDEO/*.url')
class App:
def __init__(self):
global tedLangID
print 'Loading the talk list...',
self.tedAddressList,self.titleList=getTranslationList(tedLangID)
fileList=getTEDFileList()
count=0
self.listbox=[]
for title in self.titleList:
if not isExistTEDFile(self.tedAddressList[count],fileList):
self.listbox+=[count]
count=count+1
print 'Done!'
def download(self):
global tedList
tedList=[]
print '== List =='
for item in self.listbox:
tedList+=[(self.titleList[self.item],self.tedAddressList[item])]
print self.tedAddressList[item]
print
class GUIApp:
def __init__(self,master):
global qualityValue,tedLangID,videoQuality,downAudio,isDownAudio
self.root=master
qualityValue=IntVar()
isDownAudio=IntVar()
master.configure(width=600,height=400)
self.button=Button(master,text='Download',command=self.download)
self.button.pack(side=BOTTOM)
self.refreshBtn=Button(master,text='Refresh List',command=self.refresh_list)
self.refreshBtn.pack(side=BOTTOM)
self.downAudioBtn=Checkbutton(master,text='Download Audio',variable=isDownAudio)
self.downAudioBtn.pack(side=BOTTOM)
if downAudio:
self.downAudioBtn.select()
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)
scrollbar = Scrollbar(master)
self.listbox=Listbox(master,yscrollcommand=scrollbar.set,selectmode=EXTENDED)
scrollbar.config(command=self.listbox.yview)
scrollbar.pack(side=RIGHT,fill=Y)
self.listbox.pack(side=BOTTOM,fill=BOTH,expand=1)
Label(master,text='Text to find:').pack(side=LEFT)
self.edit = Entry(master)
self.edit.pack(side=LEFT, fill=BOTH, expand=1)
self.edit.focus_set()
self.edit.bind('<Return>', self.on_enterkey)
butt = Button(master, text='Find')
butt.pack(side=RIGHT)
butt.config(command=self.find_btn)
self.queue=None
self.isRefreshing=False
self.titleList=[]
self.resultList=[]
self.fileList=[]
self.load_video_list()
def find_btn(self):
pattern=self.edit.get().lower()
selectedSet=set()
curSel=self.listbox.curselection()
for i in curSel:
selectedSet.add(self.indexList[int(i)])
if pattern=='':
idxList=list(set(range(len(self.titleList)))-selectedSet)
else:
self.fileList=getTEDFileList()
idxList=set()
count=0
for title in self.titleList:
if title.lower().find(pattern)>=0:
idxList.add(count)
count+=1
idxList=list(idxList-selectedSet)
idxList.sort()
selectedList=list(selectedSet)
selectedList.sort()
idxList=selectedList+idxList
self.indexList=idxList
self.update_video_list(selectedSet)
self.edit.delete(0,END)
self.listbox.see(len(selectedList)-1)
self.listbox.focus_set()
def on_enterkey(self,key):
self.find_btn()
def load_video_list(self):
if os.access('./VIDEO/'+'titleList-address.txt',os.F_OK):
print 'Loading the talk list...',
addFile = open ( './VIDEO/'+'titleList-address.txt' , 'r' )
lines=addFile.readlines()
resultList=[]
titleList=[]
for line in lines:
item=line.split("\t|")
if len(item)==2:
titleList+=[item[0].decode(encoding)]
resultList+=[item[1].decode(encoding)]
addFile.close()
self.tedAddressList,self.titleList=(resultList,titleList)
self.indexList=range(len(titleList))
self.update_video_list()
else:
self.refresh_list()
def check_me(self):
try:
while True:
isOK= self.queue.get_nowait()
self.queue=None
if isOK:
self.indexList=range(len(self.titleList))
self.update_video_list()
self.isRefreshing=False
return
except Queue.Empty:
pass
self.root.after(1000, self.check_me)
def refresh_list(self):
if self.isRefreshing:
return
print 'Loading the talk list...',
self.isRefreshing=True
self.queue = Queue.Queue()
self.check_me()
thread.start_new_thread(self.get_video_list,())
def update_video_list(self,selSet=set()):
self.fileList=getTEDFileList()
size=self.listbox.size()
self.listbox.delete(0,size-1)
count=0
for item in self.indexList:
self.listbox.insert(END,self.titleList[item])
if isExistTEDFile(self.tedAddressList[item],self.fileList):
self.listbox.itemconfig(count,bg='white',fg='gray')
if item in selSet:
self.listbox.select_set(count)
count=count+1
print count,"^^"
print 'Done!'
def get_video_list(self):
self.tedAddressList,self.titleList=getTranslationList(tedLangID)
self.queue.put(True)
def download(self):
global config,tedList,qualityValue,videoQuality,downAudio,isDownAudio
if self.queue is not None:
self.queue.put(False)
items=self.listbox.curselection()
videoQuality=qualityValue.get()
if isDownAudio.get()==1:
downAudio=True
else:
downAudio=False
try:
items=map(int,items)
except ValueError:pass
tedList=[]
print '== List =='
for item in items:
tedList+=[(self.titleList[self.indexList[item]],self.tedAddressList[self.indexList[item]])]
print self.tedAddressList[self.indexList[item]]
print
self.root.destroy()
config.set('Config','Quality',qualityValue.get())
with open('./config.ini', 'w') as configfile:
config.write(configfile)
configfile.close()
def initComponent():
global autoDown
if autoDown:
app=App()
app.download()
else:
root=Tk(className=' TED Downloader by gigony')
root.geometry("%dx%d" % (600,400))
app=GUIApp(root)
root.mainloop()
def downloadHook(blockNumber,blockSize,totalSize):
global downloadCount
if downloadCount==-1:
print ' Total Size:'+str(totalSize) + ' bytes'
print " Downloading...",
if int(blockNumber*blockSize*10/totalSize)>downloadCount:
downloadCount=int(blockNumber*blockSize*10/totalSize)
print downloadCount,
# this method refer to http://code.activestate.com/recipes/83208-resuming-download-of-a-file/
def download_file(videoURL,filename,isStopped):
global downloadCount
if isStopped:
filePath='./VIDEO/' + filename
loop = True
existSize = 0
myUrlclass = myURLOpener()
if os.path.exists(filePath):
outputFile = open(filePath,"ab")
existSize = os.path.getsize(filePath)
#If the file exists, then only download the remainder
myUrlclass.addheader("Range","bytes=%s-" % (existSize))
else:
outputFile = open(filePath,"wb")
webPage = myUrlclass.open(videoURL)
totalSize=int(webPage.headers['Content-Length'])
#If the file exists, but we already have the whole thing, don't download again
if totalSize == existSize:
loop = False
print "File already downloaded"
numBytes = 0
while loop:
data = webPage.read(8192)
if not data:
break
outputFile.write(data)
numBytes = numBytes + len(data)
if downloadCount==-1:
print ' Total Size:'+str(totalSize) + ' bytes'
print ' Starts from '+str(existSize) + ' bytes'
print " Downloading...",
if int(numBytes*10/totalSize)>downloadCount:
downloadCount=int(numBytes*10/totalSize)
print downloadCount,
webPage.close()
outputFile.close()
# for k,v in webPage.headers.items():
# print k, "=",v
# print "downloaded", numBytes, "bytes from", webPage.url
return filename
else:
fname,header=urlretrieve(videoURL,'./VIDEO/' + filename,downloadHook)
return fname
def download(tedList,videoQuality):
global downloadCount,tedLangID,encoding,downVideo,downAudio,stopRetriveList
stopRetriveList=True
logFile = './VIDEO/'+'log.txt'
if os.access(logFile,os.F_OK):
os.remove(logFile)
if not os.access('./VIDEO',os.F_OK):
os.mkdir('./VIDEO')
for tedItem in tedList:
ted=tedItem[1]
isStopped=False
tryCount=3
while tryCount>0 :
try:
log_print(logFile,"")
filename=None
log_print(logFile,tedItem[0].encode(sys.stdout.encoding,'xmlcharrefreplace'))
log_print(logFile,' '+ted)
req = urllib2.Request(ted)
response = urllib2.urlopen(req)
result = response.read()
## Get Talk ID value
splits = result.split ( '''ti:"''' )
talkId = splits[1].split ( '"' )[0]
# Generate file name
splits = ted.split ( '/' )
filename = ('00000'+str(talkId))[-5:]+'_'+splits[len ( splits )-1].split ('.')[0]
log_print(logFile,' '+filename)
## Get Talk Intro Duration value
splits = result.split ('''<a id="no-flash-video-download" href="http://download.ted.com/talks/''')
if len(splits)==1:
log_print(logFile,' '+"This is a Youtube video")
splits = result.split ( '''<iframe src="''')
youtubeURL=splits[1].split('"')[0]
log_print(logFile,' '+youtubeURL)
urlFile = open ( './VIDEO/'+filename + '.url' , 'w' )
urlFile.write ("""[InternetShortcut]\r\nURL="""+youtubeURL)
urlFile.close()
break
videoName = splits[1].split(".")[0]
talkIntroDuration = splits[1].split ( "</script>" )[0]
talkIntroDuration = unquote(talkIntroDuration)
talkIntroDuration = talkIntroDuration.split('''"introDuration":''')[1].split(",")[0]
talkIntroDuration = int(float ( talkIntroDuration )*1000)
downloadURL='http://www.ted.com/download/links/slug/%s/type/talks/ext/mp4'%(videoName)
req = urllib2.Request(downloadURL)
response = urllib2.urlopen(req)
result = response.read()
# Get Talk Audio
if downAudio:
audioResult=result.split('''<dt><a href="''')
if len(audioResult)>1:
audioURL=audioResult[1].split('''">Download to desktop (MP3)</a></dt>''')[0]
downloadCount=-1
log_print(logFile, " Downloading from "+audioURL)
fname=download_file(audioURL,filename+'.mp3',isStopped)
log_print(logFile,'')
log_print(logFile,' %s is saved' % fname)
else:
log_print(logFile, ' '+'No audio file existed')
#check mp4/smi/txt file
if os.access('./VIDEO/'+filename+'.mp4',os.F_OK) and os.path.getsize('./VIDEO/'+filename+'.mp4')>0 and os.access('./VIDEO/'+filename+'.smi',os.F_OK)and os.path.getsize('./VIDEO/'+filename+'.smi')>0 and os.access('./VIDEO/'+filename+'.txt',os.F_OK)and os.path.getsize('./VIDEO/'+filename+'.txt')>0:
log_print(logFile,' '+filename+'.mp4/smi/txt is already exist')
break
## Get Talk Video
if downVideo and not(os.access('./VIDEO/'+filename+'.mp4',os.F_OK) and os.path.getsize('./VIDEO/'+filename+'.mp4')>0 and os.access('./VIDEO/'+filename+'.smi',os.F_OK)and os.path.getsize('./VIDEO/'+filename+'.smi')>0):
downloadSplits=result.split('''<input name="download_quality"''')
numOfDownloadLink=len(downloadSplits)-1
postFixList=[]
for i in range(1,numOfDownloadLink+1):
postFixList=postFixList+[downloadSplits[i].split(''' value="''')[1].split('"')[0]]
if videoQuality>=numOfDownloadLink:
videoQuality=numOfDownloadLink-1
videoURL="http://download.ted.com/talks/%s%s.mp4?apikey=TEDDOWNLOAD"%(videoName,postFixList[videoQuality])
downloadCount=-1
log_print(logFile," Downloading from "+videoURL)
#fname,header=urlretrieve(videoURL,'./VIDEO/' + filename + '.mp4',downloadHook)
fname=download_file(videoURL,filename+'.mp4',isStopped)
log_print(logFile,'')
log_print(logFile,' %s is saved' % fname)
#download smi file
if not transLang=='English':
jsonString1 = getTEDSubtitlesByTalkID ( talkId , tedLangID )
else:
jsonString1 = ''
jsonString2 = getTEDSubtitlesByTalkID ( talkId , 'eng' )
smiContent=convertTEDSubtitlesToSMISubtitles((jsonString1,jsonString2),talkIntroDuration)
smiFile = open ( './VIDEO/'+filename + '.smi' , 'w' )
smiFile.write ( smiContent.encode ( encoding,'xmlcharrefreplace') )
smiFile.close ()
#download txt file
if jsonString1==None: jsonString1 = getTEDSubtitlesByTalkID ( talkId , tedLangID)
if jsonString2==None: jsonString2 = getTEDSubtitlesByTalkID ( talkId , 'eng' )
txtContent=convertTEDSubtitlesToTXTSubtitles((jsonString1,jsonString2))
if not txtContent==None:
txtFile = open ( './VIDEO/'+filename + '.txt' , 'w' )
txtFile.write ( txtContent.encode ( encoding,'xmlcharrefreplace'))
txtFile.close ()
break
except Exception,msg:
log_print(logFile,str(msg))
log_print(logFile,'waiting 10 seconds..')
isStopped=True
tryCount=tryCount-1
time.sleep(10)
def log_print(logFile,msg):
print msg
f=open ( './VIDEO/'+'log.txt' , 'a' )
f.write(msg + os.linesep)
f.close()
tedList=[]
if not initProgram():
exit()
if len(sys.argv)==2:
tedList=[(' ',sys.argv[1])]
download(tedList,videoQuality)
else:
initComponent()
download(tedList,videoQuality)