Sistem nasıl olacak acaba?
aşağıdaki örnek kodu kendi altyazılarına uyarlayabilirsiniz.
<?php
// script to convert srt caption files to new-format (02-05-08) tt XML caption files
$use_cdata_tags = true;
$debug_output = true;
// the directory to write the new files in
// it must exist, be writeable, and be outside of the directory that is being scanned
$new_directory = '../temp/';
////////////////////////////////// no user configuraton below this /////////////////////////////
// get name or scan directory if it's a directory
$filename = (isset($_GET["filename"])) ? strval($_GET["filename"]) : "./";
// read each file into an array
$it = new RecursiveDirectoryIterator("$filename");
foreach(new RecursiveIteratorIterator($it) as $file)
{
// debug('Filename', $file);
// debug('Ext', substr(strtolower($file), (strlen($file) - 4), 4));// exit;
// check for .srt extension
if(substr(strtolower($file), (strlen($file) - 4), 4) == '.srt')
{
$ttxml = "";
$next_line_is_text = false;
if($file_array = file($file))
{
// write tt , head, and div elements for the new file
$ttxml .= "<tt xml:lang='en' xmlns='http://www.w3.org/2006/10/ttaf1' xmlns:tts='http://www.w3.org/2006/10/ttaf1#style'>\n";
$ttxml .= " <head>\n";
$ttxml .= " </head>\n";
$ttxml .= " <body>\n";
$ttxml .= " <div xml:id=\"captions\">\n";
foreach($file_array as $line)
{
// debug('Line', $line);
// if the next line is text, write the paragraph
if($next_line_is_text)
{
// write new paragraph
// <p begin="00:08:01.50" end="00:08:07.50">Nothing is going on.</p>
if($use_cdata_tags)
{
$ttxml .= " <p begin=\"" . $begin . "\" end=\"" . $end . "\"><![CDATA[" . rtrim($line) . "]]></p>\n";
}
else
{
$ttxml .= " <p begin=\"" . $begin . "\" end=\"" . $end . "\">" . rtrim($line) . "</p>\n";
}
$next_line_is_text = false;
// debug('Text', $line);
// debug('ttxml', $ttxml); exit;
}
// get begin and end
// 00 : 00 : 32 , 000 --> 00 : 00 : 37 , 000
if(preg_match('/(\d\d):(\d\d):(\d\d),(\d\d\d) --> (\d\d):(\d\d):(\d\d),(\d\d\d)/', $line, $match))
{
$begin = $match[1] . ":" . $match[2] . ":" . $match[3] . "." . $match[4];
$end = $match[5] . ":" . $match[6] . ":" . $match[7] . "." . $match[8];
$next_line_is_text = true;
}
}
// write ending tags
$ttxml .= " </div>\n";
$ttxml .= " </body\n";
$ttxml .= "</tt>\n";
// write new file
$new_file = $new_directory . substr($file, 0, (strlen($file) - 4)) . '.xml';
$fh = fopen($new_file, 'w') or die('Can\'t open: ' . $new_file);
fwrite($fh, $ttxml) or die('Can\'t write to: ' . $new_file);
fclose($fh);
}
}
}
function debug($title, $value)
{
global $debug_output;
if ($debug_output)
{
print "<pre>";
if (is_array($value))
{
print $title . ":\n";
print_r($value);
}
else
{
print $title . ": " . $value;
}
print "</pre>\n";
}
}
?>
Çevrimden önceki altyazı
Alıntı
1
00:00:16,000 --> 00:00:19,000
<font size="12" face="Verdana">Your fingertips across my skin</font>
2
00:00:21,000 --> 00:00:24,000
<font size="12" face="Verdana">The palm trees swaying in the wind</font>
Çevrimden sonraki
Alıntı
<tt xml:lang='en' xmlns='http://www.w3.org/2006/10/ttaf1' xmlns:tts='http://www.w3.org/2006/10/ttaf1#style'>
<head>
</head>
<body>
<div xml:id="captions">
<p begin="00:00:16.000" end="00:00:19.000"><![CDATA[<font size="12" face="Verdana">Your fingertips across my skin</font>]]></p>
<p begin="00:00:21.000" end="00:00:24.000"><![CDATA[<font size="12" face="Verdana">The palm trees swaying in the wind</font>]]></p>
...
</div>
</body
</tt>