6 class MicroDvd extends CaptionFormat
\r
8 private $textStyles = array();
\r
11 * Imports a caption string into a CaptionCollection
\r
13 * @param String $theCCString the caption file as string
\r
14 * @return CaptionCollection $myCcCollection A CaptionCollection Object
\r
16 public function importCC($theCCString) {
\r
17 //global $ins, $caps, $outs, $num_clips,$proj_caption;
\r
21 //$contents = file_get_contents($theCCFile);
\r
22 $contents = $theCCString;
\r
24 // clean malformed patterns creted when saving files on win notepad
\r
25 $toSearch = array(chr(13).chr(10));
\r
26 $toReplace = array(chr(10));
\r
27 $contents = str_replace($toSearch,$toReplace,$contents);
\r
29 // Defining QText known pattenrs;
\r
30 $pattern_QT_time_format = "\[([0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{3})\]";
\r
31 $pattern_QT_time_format_magpie = "\[([0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{2})\]";
\r
33 $num_clips = preg_match_all("/$pattern_QT_time_format/", $contents, $clips);
\r
35 // if caption file is not QT and comes from MapPie time format
\r
36 if ($num_clips == 0)
\r
38 $num_clips = preg_match_all("/$pattern_QT_time_format_magpie/", $contents, $clips);
\r
41 //$num_clips = $num_clips/2; // this is not needed
\r
43 // create a collection object
\r
44 include_once('CaptionCollection.php');
\r
45 $myQTextCollection = new CaptionCollection();
\r
48 // build data arrays looing through $clips QT format: 1) Split using QT time format, Find all times
\r
49 for ($i=0; $i<$num_clips; $i=$i+2) {
\r
51 // 2) Find all content in between QT time START and END using /s flag to capture also break lines
\r
52 $match_this = '/\['.$clips[1][$i].'\]\n(.*)\n\['.$clips[1][$i+1].'\]\n/s';
\r
53 preg_match($match_this, $contents, $clip_bit);
\r
55 // add captions to the collection
\r
56 $myQTextCollection->addCaptions($clips[1][$i],$clip_bit[1],$clips[1][$i+1]);
\r
59 $ins[] = $clips[1][$i];
\r
60 $caps[] = $clip_bit[1];
\r
61 $outs[] = $clips[1][$i+1];
\r
66 return $myQTextCollection;
\r
71 * Exports a CaptionCollection object into a string
\r
73 * @param CaptionCollection $theCollection A CaptionCollection Object
\r
74 * @return String $captionString The caption as a String
\r
76 public function exportCC($theCollection)
\r
81 $myCollection = $theCollection->getCollection();
\r
83 foreach ($myCollection as $captionObj)
\r
86 $miliSecIN = TimeUtil::timeQtToSami($captionObj->getInTime());
\r
87 $miliSecOUT = TimeUtil::timeQtToSami($captionObj->getOutTime());
\r
88 $fixCap = TxtFileTools::ccNewLineToBr($captionObj->getCaption(),' ');
\r
90 $ccExport .= "{".$miliSecIN."}{".$miliSecOUT."}".$fixCap."\n";
\r
99 * Verify if the caption file is a QText caption file
\r
101 public function checkFormat($theCCString)
\r
104 $patternCheck = "/({(QTtext)})/"; // RegExp to look for QText
\r
105 preg_match_all($patternCheck,$theCCString,$patternFound);
\r
107 if(count($patternFound)>0)
\r
114 } // end checkFormat()
\r
117 * Here functions to re-define
\r
119 public function getName()
\r
124 public function getAbout()
\r
126 return 'Caption Format used by the popular video player MicroDVD';
\r
129 public function getVersion()
\r
134 public function getFileExtension()
\r
139 public function getIdPattern()
\r
141 $idPattern = '/unknown/';
\r
146 public function allowsTextStyles()
\r
151 public function template()
\r
154 {4952}{6082}caption 1
\r
155 {6084}{8977}caption 2
\r
156 {8979}{11928}caption 3
\r
157 {11930}{13795}caption 4
\r
158 {13797}{16569}caption 5
\r
159 {16571}{17816}caption 6
\r
160 {19656}{21412}caption 7
\r
161 {21414}{23133}caption 8
\r
162 {23135}{26100}caption 9
\r
163 {26102}{28141}caption 10
\r
164 {28143}{29867}caption 11
\r
167 return $ccTemplate;
\r
170 } // end MicroDvd class
\r