Standart mı değil mi bilmem, karşılaştığım bir subtitle için yazdığım kodu.

Kullanım:
python .py dosyadi.xml

import math
import sys
import re
import codecs
from xml.dom import minidom
xmldoc = minidom.parse(sys.argv[1])

x,z  = 0,0
yazi = ""

df = codecs.open(sys.argv[1] + ".srt","wt","utf-8")

def saat(msaniye):
    hour = math.floor(msaniye/3600000)
    minute = math.floor((msaniye%3600000)/60000)
    second = math.floor((msaniye%60000)/1000)
    milisecond = math.floor((msaniye%1000))
    return "%02d:%02d:%02d,%03d" % (hour,minute,second,milisecond)

def saatbul(sira):
    r = 0
    for satir in xmldoc.getElementsByTagName(‘SYNC‘):
        q = satir.getAttribute(‘start‘)
        if (r == sira) :
            return satir.getAttribute(‘start‘)
        r += 1
    return int(q) + 2000

for tag in xmldoc.getElementsByTagName(‘SYNC‘):
    print >>df,  x
    print >>df, saat(int(tag.getAttribute(‘start‘))) ,  "–>"  , saat(int(saatbul(x + 1)))
    x += 1
    z = tag.getAttribute(‘start‘)
    m = re.search(‘\<P.+\>(?P<metin>.+)\<\/P\>‘,tag.toxml())
    yazi = m.group(‘metin‘)
    yazi = yazi.replace(‘#‘,’\n‘)
    print >>df, yazi
    print >>df, " "

Link: flvxml2srt

Bookmark and Share
Tags: , , , , , ,

Tags: , , , , , ,

This entry was posted on Monday, November 2nd, 2009 at 17:04 and is filed under Uncategorized. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Cevap veya Yorum Yaz

İsminiz
e-Mail (Burada yayınlanmayacak endişelenmeyin)
Web Siteniz
Yorumunuz

Switch to our mobile site