# -*- coding: euckr -*- import urllib import json import wget import os import zipfile import re def unzip_file_into_dir(file, dir): try: os.mkdir(dir, 0777) except: pass zfobj = zipfile.ZipFile(file) filename = zfobj.namelist()[0] zfobj.extractall("./downloads") return filename for name in zfobj.namelist(): outfile = open( os.path.join(dir, name), 'wb') outfile.write(zfobj.read(name)) outfile.close() filename = name return filename def getIntroDuration(data): duration = data.split('introDuration:')[1].split(',')[0] return int(duration) def getLink(data): url = data.split('href="')[1].split('"')[0] return url def getTitle(data): title = data.split('Video to desktop (Zipped MP4)')[0][-100:].split('
  • ' for item in captionDataList: content = item["content"] startTime = item["startTime"] subscript += '

    \n' + content + "\n" subscript += """""" subfile = open( os.path.join(dir, filename[:-3]+"smi"), 'w') try: subfile.write(subscript) except: try: subfile.write(subscript.encode("utf8")) except: subfile.write(subscript.encode("euckr")) subfile.close() def downloads(movFileList): for mov in movFileList: print "다운로드시작 : [" , mov[0] , "]" #download mov file filename = wget.wget("http://www.ted.com"+mov[2]) print "다운로드완료 : [" , filename + ".zip]" #movie file rename try: os.rename(filename, filename+".zip") except: pass print "압축 푸는중 : [" , filename + ".zip]" #unzip realfile = unzip_file_into_dir(filename+".zip","downloads") print "압축 풀기 완료 : [" , filename + ".zip]" try: os.remove(filename+".zip") except: pass print "자막만들기 : [" , mov[0], "]" try: makeSubScript("downloads", mov[1], mov[0],realfile, mov[3]) except: print " 자막 없음 " lang = "kor" if __name__=="__main__": lang = raw_input("목록 보실 언어를 선택해 주세요 (ex: kor, jpn, eng, etc... : ") downloads(getMovieList(lang))