def webvtt2Srt(url):
    if xbmcvfs.exists(subFile):
        xbmcvfs.delete(subFile)

    webvtt = utils.getUrl(url)
    s = webvtt.split('\n\n')
    i = 1
    srt = ''
    while i < len(s):
        j = 0
        for line in s[i].split('\n'):
            if j == 0:
                srt += line + '\n'
            elif j == 1:
                t = line.split(' ')
                srt += t[0][:-1].replace('.', ',') + ' --> ' + \
                    t[2][:-1].replace('.', ',') + '\n'
            else:
                for bracket in bracketLookup:
                    line = line.replace(bracket, bracketLookup[bracket])
                srt += line + '\n'
            j += 1
        srt += '\n'
        i += 1

    f = xbmcvfs.File(subFile, 'w')
    f.write(srt)
    f.close()
    return subFile
예제 #2
0
def _newSubtitle(url):
	_createProfilePath()
	if xbmcvfs.exists(subFile):
		xbmcvfs.delete(subFile)
	#content = utils.getUrl(url)
	try:
		content = utils.getUrl(url)
	except:
		content = ""
	content = content.replace('\0','').replace('<tt:','<').replace('</tt:','</')
	if content:
		#utils.log(str(content))
		d = _stylesSetup(re.compile('<styling>(.+?)</styling>', re.DOTALL).findall(content)[0])
		div = re.compile('<div.+?>(.+?)</div>', re.DOTALL).findall(content)[0]
		p = re.compile('<(.+?)</p>', re.DOTALL).findall(div)
		i = 1
		buffer = ''
		for part in p:
			if '<span' in part:
				part = part.replace('begin="1','begin="0').replace('end="1','end="0').replace('\n','').replace('<br/>','\n')
				begin = re.compile('begin="(.+?)"').findall(part)[0]
				begin = begin.replace(".",",")[:-1]
				end = re.compile('end="(.+?)"').findall(part)[0]
				end = end.replace(".",",")[:-1]
				s = part.split('>')[0]
				part = part.replace(s+'>','')
				part = part.replace('<br />','\n')
				if 'style=' in s:
					style = re.compile('style="(.+?)"').findall(s)[0]
					if d[style]:
						part = '<font color="'+d[style]+'">'+part+'</font>'
				match = re.compile('<(.+?)>').findall(part)
				for entry in match:
					if entry.startswith('span'):
						if 'style' in entry:
							style = re.compile('style="(.+?)"').findall(entry)[0]
							part = part.replace('<'+entry+'>','<font color="'+d[style]+'">')
						else:
							part = part.replace('<'+entry+'>','')
					elif entry.startswith('/span'):
						part = part.replace('</span>','</font>')
					else:
						part = part.replace('<'+entry+'>','')
				

				buffer += str(i) + '\n'
				buffer += begin+" --> "+end+"\n"
				buffer += part + '\n\n'
				i+=1
		buffer = buffer.replace('            ','').replace('           ','').replace('  ',' ').replace(' \n','\n')
		utils.f_write(subFile,buffer)
		utils.log(subFile)
		return subFile