def subt_conv(smiPath=None): if smiPath is None: videoDir = os.path.dirname(xbmc.Player().getPlayingFile()) smiPath = os.path.join(videoDir, xbmc.Player().getSubtitles()) if not xbmcvfs.exists(smiPath): xbmc.log("Can not find subtitles at " + smiFullPath, xbmc.LOGWARNING) return if not smiPath.lower().endswith(".smi"): xbmc.log("Subtitles file, %s, is not SMI format" % smiFullPath, xbmc.LOGWARNING) return #read smi file xbmc.log("Convert " + smiPath + " to ASS format", xbmc.LOGDEBUG) smi_file = xbmcvfs.File(smiPath, "r") smi_sgml = smi_file.read() smi_file.close() assDict = smi2ass(smi_sgml) for lang in assDict: ext = lang + '.ass' if lang == '': ext = 'ass' assPath = smiPath[:smiPath.rfind('.')] + '.' + ext tempDir = xbmc.translatePath("special://temp/") #tempFile = os.path.basename( assPath ) tempFile = "smi2ass." + ext tempPath = os.path.join(tempDir, tempFile) if not xbmcvfs.exists(assPath) or __addon__.getSetting( "overwrite_ass") == 'true': assfile = open(tempPath, "w") assfile.write(assDict[lang]) assfile.close() if not xbmcvfs.copy(tempPath, assPath): xbmc.log("Fail to write subtitles to " + assPath, xbmc.LOGWARNING) xbmcgui.Dialog().ok(__scriptname__, _(110), _(107), assPath) assPath = tempPath # enable the downloaded subtitle xbmc.log("ASS file is saved as " + assPath, xbmc.LOGINFO) xbmc.Player().setSubtitles(assPath) else: xbmc.log("Skip overwriting the existing ASS file, " + assPath, xbmc.LOGINFO)
def Download(sub_id, link, filename, sub_fmt): if xbmcvfs.exists(__temp__): shutil.rmtree(__temp__) xbmcvfs.mkdirs(__temp__) #url = GetSubtitleUrl( link ) url = link xbmc.log("download subtitle from %s" % url, level=xbmc.LOGINFO) subtitle_list = [] # only one file to download try: smi_sgml = urllib.urlopen(url).read() except: xbmc.log("fail to download subtitle from %s" % url, level=xbmc.LOGWARNING) return [] # convert to ASS format if sub_fmt == 'ass': assDict = smi2ass(smi_sgml) if len( assDict ) > 1 and 'Korean' in assDict: # select Korean in multi-language lang = 'Korean' else: lang = assDict.keys()[0] sub_txt = assDict[lang] else: sub_txt = smi_sgml # store in temp subtitle = os.path.join(__temp__, "%s.%s" % (sub_id, sub_fmt)) with open(subtitle, "w") as subFile: subFile.write(sub_txt) subFile.close() subtitle_list.append(subtitle) xbmc.log("stored at " + subtitle.encode('cp949', 'ignore'), xbmc.LOGINFO) if xbmcvfs.exists(subtitle_list[0]): return subtitle_list
def subt_conv(smiPath=None): if smiPath is None: videoDir = os.path.dirname(xbmc.Player().getPlayingFile()) smiPath = os.path.join(videoDir, xbmc.Player().getSubtitles()) if not xbmcvfs.exists(smiPath): xbmc.log("Can not find subtitles at "+smiFullPath, xbmc.LOGWARNING) return if not smiPath.lower().endswith(".smi"): xbmc.log("Subtitles file, %s, is not SMI format" %smiFullPath, xbmc.LOGWARNING) return #read smi file xbmc.log("Convert "+smiPath+" to ASS format", xbmc.LOGDEBUG) smi_file = xbmcvfs.File(smiPath,"r") smi_sgml = smi_file.read() smi_file.close() assDict = smi2ass(smi_sgml) for lang in assDict: ext = lang+'.ass' if lang == '': ext = 'ass' assPath = smiPath[:smiPath.rfind('.')]+'.'+ext tempDir = xbmc.translatePath( "special://temp/" ) #tempFile = os.path.basename( assPath ) tempFile = "smi2ass."+ext tempPath = os.path.join( tempDir, tempFile ) if not xbmcvfs.exists(assPath) or __addon__.getSetting( "overwrite_ass" )=='true': assfile = open(tempPath, "w") assfile.write(assDict[lang]) assfile.close() if not xbmcvfs.copy(tempPath, assPath): xbmc.log("Fail to write subtitles to "+assPath, xbmc.LOGWARNING) xbmcgui.Dialog().ok(__scriptname__, _(110), _(107), assPath) assPath = tempPath # enable the downloaded subtitle xbmc.log("ASS file is saved as "+assPath, xbmc.LOGINFO) xbmc.Player().setSubtitles(assPath) else: xbmc.log("Skip overwriting the existing ASS file, "+assPath, xbmc.LOGINFO)
def Download (sub_id, link, filename, sub_fmt): if xbmcvfs.exists(__temp__): shutil.rmtree(__temp__) xbmcvfs.mkdirs(__temp__) url = GetSubtitleUrl( link ) xbmc.log("download subtitle from %s" %url, level=xbmc.LOGINFO) subtitle_list = [] # only one file to download try: smi_sgml = urllib.urlopen(url).read() except: xbmc.log("fail to download subtitle from %s" %url, level=xbmc.LOGWARNING) return [] # convert to ASS format if sub_fmt == 'ass': assDict = smi2ass( smi_sgml ) if len(assDict) > 1 and 'Korean' in assDict: # select Korean in multi-language lang = 'Korean' else: lang = assDict.keys()[0] sub_txt = assDict[lang] else: sub_txt = smi_sgml # store in temp subtitle = os.path.join(__temp__, "%s.%s" %(sub_id, sub_fmt)) with open(subtitle, "w") as subFile: subFile.write( sub_txt ) subFile.close() subtitle_list.append(subtitle) xbmc.log("stored at "+subtitle.encode('cp949', 'ignore'), xbmc.LOGINFO) if xbmcvfs.exists(subtitle_list[0]): return subtitle_list