Example #1
0
def _newSubtitle(url):
    #if os.path.exists(subFile):
    #	os.remove(subFile)
    if xbmcvfs.exists(subFile):
        xbmcvfs.delete(subFile)
    try:
        content = utils.getUrl(url)
    except:
        content = ""
    if content:
        dict = _stylesSetup(
            re.compile('<tt:styling>(.+?)</tt:styling>',
                       re.DOTALL).findall(content)[0])
        div = re.compile('<tt:div.+?>(.+?)</tt:div>',
                         re.DOTALL).findall(content)[0]
        p = re.compile('<tt:p(.+?)</tt:p>', re.DOTALL).findall(div)
        i = 1
        buffer = ''
        for part in p:
            if '<tt:span' in part:
                part = part.replace('begin="1', 'begin="0').replace(
                    'end="1', 'end="0').replace('\n',
                                                '').replace('<tt: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 + '>', '')
                if 'style=' in s:
                    style = re.compile('style="(.+?)"').findall(s)[0]
                    if dict[style]:
                        part = '<font color="' + dict[
                            style] + '">' + part + '</font>'
                match = re.compile('<(.+?)>').findall(part)
                for entry in match:
                    if entry.startswith('tt:span'):
                        if 'style' in entry:
                            style = re.compile('style="(.+?)"').findall(
                                entry)[0]
                            part = part.replace(
                                '<' + entry + '>',
                                '<font color="' + dict[style] + '">')
                        else:
                            part = part.replace('<' + entry + '>', '')
                    elif entry.startswith('tt:/span'):
                        part = part.replace('</tt:span>', '</font>')
                    else:
                        part = part.replace('<' + entry + '>', '')

                buffer += str(i) + '\n'
                buffer += begin + " --> " + end + "\n"
                buffer += part + '\n\n'
                i += 1

        f = xbmcvfs.File(subFile, 'w')
        f.write(buffer)
        f.close()
        xbmc.sleep(1000)
        xbmc.Player().setSubtitles(subFile)
Example #2
0
def _newSubtitle(url):
    # if os.path.exists(subFile):
    # 	os.remove(subFile)
    if xbmcvfs.exists(subFile):
        xbmcvfs.delete(subFile)
    try:
        content = utils.getUrl(url)
    except:
        content = ""
    if content:
        dict = _stylesSetup(re.compile("<tt:styling>(.+?)</tt:styling>", re.DOTALL).findall(content)[0])
        div = re.compile("<tt:div.+?>(.+?)</tt:div>", re.DOTALL).findall(content)[0]
        p = re.compile("<tt:p(.+?)</tt:p>", re.DOTALL).findall(div)
        i = 1
        buffer = ""
        for part in p:
            if "<tt:span" in part:
                part = (
                    part.replace('begin="1', 'begin="0')
                    .replace('end="1', 'end="0')
                    .replace("\n", "")
                    .replace("<tt: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 + ">", "")
                if "style=" in s:
                    style = re.compile('style="(.+?)"').findall(s)[0]
                    if dict[style]:
                        part = '<font color="' + dict[style] + '">' + part + "</font>"
                match = re.compile("<(.+?)>").findall(part)
                for entry in match:
                    if entry.startswith("tt:span"):
                        if "style" in entry:
                            style = re.compile('style="(.+?)"').findall(entry)[0]
                            part = part.replace("<" + entry + ">", '<font color="' + dict[style] + '">')
                        else:
                            part = part.replace("<" + entry + ">", "")
                    elif entry.startswith("tt:/span"):
                        part = part.replace("</tt:span>", "</font>")
                    else:
                        part = part.replace("<" + entry + ">", "")

                buffer += str(i) + "\n"
                buffer += begin + " --> " + end + "\n"
                buffer += part + "\n\n"
                i += 1

        f = xbmcvfs.File(subFile, "w")
        f.write(buffer)
        f.close()
        xbmc.sleep(1000)
        xbmc.Player().setSubtitles(subFile)
Example #3
0
def _newSubtitle(url):
  debug("_newSubtitle :" + url)
  #if os.path.exists(subFile):
  #  os.remove(subFile)
  if xbmcvfs.exists(subFile):
    xbmcvfs.delete(subFile)
  try:
    content = utils.getUrl(url)
  except:
    content = ""
  if content:
    debug("Subtitle gefunden")
    dict = _stylesSetup(re.compile('<tt:styling>(.+?)</tt:styling>', re.DOTALL).findall(content)[0])
    div = re.compile('<tt:div.+?>(.+?)</tt:div>', re.DOTALL).findall(content)[0]
    p = re.compile('<tt:p(.+?)</tt:p>', re.DOTALL).findall(div)
    i = 1
    buffer = ''
    for part in p:
      if '<tt:span' in part:
        part = part.replace('begin="1','begin="0').replace('end="1','end="0').replace('\n','').replace('<tt:br/>','\n').replace('<tt: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+'>','')
        if 'style=' in s:
          style = re.compile('style="(.+?)"').findall(s)[0]
          if dict[style]:
            part = '<font color="'+dict[style]+'">'+part+'</font>'
        match = re.compile('<(.+?)>').findall(part)
        for entry in match:
          if entry.startswith('tt:span'):
            if 'style' in entry:
              style = re.compile('style="(.+?)"').findall(entry)[0]
              part = part.replace('<'+entry+'>','<font color="'+dict[style]+'">')
            else:
              part = part.replace('<'+entry+'>','')
          elif entry.startswith('tt:/span'):
            part = part.replace('</tt:span>','</font>')
          else:
            part = part.replace('<'+entry+'>','')
        

        buffer += str(i) + '\n'
        buffer += begin+" --> "+end+"\n"
        buffer += part + '\n\n'
        i+=1
    
    f = xbmcvfs.File(subFile, 'w')
    f.write(buffer)
    f.close()
Example #4
0
def _oldSubtitle(url):
    if os.path.exists(subFile):
        os.remove(subFile)
    try:
        content = utils.getUrl(url)
    except:
        content = ""
    if content:
        dict = _stylesSetup(
            re.compile('<styling>(.+?)</styling>',
                       re.DOTALL).findall(content)[0])
        matchLine = re.compile(
            '<p id=".+?" begin="1(.+?)" end="1(.+?)".+?style="(.+?)">(.+?)</p>',
            re.DOTALL).findall(content)
        #fh = open(subFile, 'a')
        f = xbmcvfs.File(subFile, 'w')
        count = 1
        for begin, end, style, line in matchLine:
            begin = "0" + begin.replace(".", ",")[:-1]
            end = "0" + end.replace(".", ",")[:-1]
            text = ''
            line = line.replace('\n', '').strip()
            line = line.replace("<br />", "\n")

            if dict[style]:
                line = '<font color="' + dict[style] + '">' + line + '</font>'

            s = line.split('<')
            for entry in s:
                if entry.startswith('span'):
                    if 'tts:color' in entry.split('>')[0]:
                        color = re.compile('tts:color="(.+?)"',
                                           re.DOTALL).findall(
                                               entry.split('>')[0])[0]
                        line = line.replace('<' + entry.split('>')[0] + '>',
                                            '<font color="' + color + '">')
            line = line.replace('</span>', '</font>')

            while '  ' in line:
                line = line.replace('  ', ' ')
            line = line.replace(' \n', '\n').replace(' </font>\n', '</font>\n')
            #fh.write(str(count)+"\n"+begin+" --> "+end+"\n"+_cleanTitle(line)+"\n\n")
            f.write(
                str(count) + "\n" + begin + " --> " + end + "\n" +
                _cleanTitle(line) + "\n\n")

            count += 1
        f.close()
        xbmc.sleep(1000)
        xbmc.Player().setSubtitles(subFile)
Example #5
0
def _oldSubtitle(url):
    if os.path.exists(subFile):
        os.remove(subFile)
    try:
        content = utils.getUrl(url)
    except:
        content = ""
    if content:
        dict = _stylesSetup(re.compile("<styling>(.+?)</styling>", re.DOTALL).findall(content)[0])
        matchLine = re.compile('<p id=".+?" begin="1(.+?)" end="1(.+?)".+?style="(.+?)">(.+?)</p>', re.DOTALL).findall(
            content
        )
        # fh = open(subFile, 'a')
        f = xbmcvfs.File(subFile, "w")
        count = 1
        for begin, end, style, line in matchLine:
            begin = "0" + begin.replace(".", ",")[:-1]
            end = "0" + end.replace(".", ",")[:-1]
            text = ""
            line = line.replace("\n", "").strip()
            line = line.replace("<br />", "\n")

            if dict[style]:
                line = '<font color="' + dict[style] + '">' + line + "</font>"

            s = line.split("<")
            for entry in s:
                if entry.startswith("span"):
                    if "tts:color" in entry.split(">")[0]:
                        color = re.compile('tts:color="(.+?)"', re.DOTALL).findall(entry.split(">")[0])[0]
                        line = line.replace("<" + entry.split(">")[0] + ">", '<font color="' + color + '">')
            line = line.replace("</span>", "</font>")

            while "  " in line:
                line = line.replace("  ", " ")
            line = line.replace(" \n", "\n").replace(" </font>\n", "</font>\n")
            # fh.write(str(count)+"\n"+begin+" --> "+end+"\n"+_cleanTitle(line)+"\n\n")
            f.write(str(count) + "\n" + begin + " --> " + end + "\n" + _cleanTitle(line) + "\n\n")

            count += 1
        f.close()
        xbmc.sleep(1000)
        xbmc.Player().setSubtitles(subFile)
Example #6
0
def _oldSubtitle(url):
	if os.path.exists(subFile):
		os.remove(subFile)
	try:
		content = utils.getUrl(url)
	except:
		content = ""
	if content:
		dict = _stylesSetup(re.compile('<styling>(.+?)</styling>', re.DOTALL).findall(content)[0])
		matchLine = re.compile('<p id=".+?" begin="1(.+?)" end="1(.+?)".+?style="(.+?)">(.+?)</p>', re.DOTALL).findall(content)
		#fh = open(subFile, 'a')
		f = xbmcvfs.File(subFile, 'w')
		count = 1
		for begin, end, style, line in matchLine:
			begin = "0"+begin.replace(".",",")[:-1]
			end = "0"+end.replace(".",",")[:-1]
			text = ''
			line = line.replace('\n','').strip()
			line = line.replace("<br />","\n")
			
			if dict[style]:
				line = '<font color="'+dict[style]+'">'+line+'</font>'

			s = line.split('<')
			for entry in s:
				if entry.startswith('span'):
					if 'tts:color' in entry.split('>')[0]:
						color = re.compile('tts:color="(.+?)"', re.DOTALL).findall(entry.split('>')[0])[0]
						line = line.replace('<'+entry.split('>')[0]+'>','<font color="'+color+'">')
			line = line.replace('</span>','</font>')

			while '  ' in line:
				line = line.replace('  ',' ')
			line = line.replace(' \n','\n').replace(' </font>\n','</font>\n')
			#fh.write(str(count)+"\n"+begin+" --> "+end+"\n"+_cleanTitle(line)+"\n\n")
			f.write(str(count)+"\n"+begin+" --> "+end+"\n"+_cleanTitle(line)+"\n\n")
			
			count+=1
		f.close()