PHPBuilder - Substation Alpha (*.SSA) - SubtitleFix



RSS Twitter
Snippets Other

Substation Alpha (*.SSA) - SubtitleFix

by: Markku Uttula
|
April 4, 2002

Version: 1.0

Type: Full Script

Category: Other

License: GNU General Public License

Description: I got tired of malformed SSA-subtitles that are available for DivX-movies on the net, and decided to do this script that fixes the timestamps of the subtitles so that no subtitle overlaps with another (this is extreamly irritating). Hope this is of use to somebody...



<HTML>
  <HEAD>
    <TITLE>Substation Alpha (*.SSA) - SubtitleFix v1.0</TITLE>
  </HEAD>
  <BODY>
<?
    if ($fix_this != '') {
      $fixed = '';
      $fix_this = preg_replace("/\r/","",$fix_this);
      $fix_this = preg_replace("/\n+/","\n",$fix_this);
      $subtitle = explode("\n",stripslashes($fix_this));
      for ($i = 0; $i < count($subtitle); $i++) {
        $string = $subtitle[$i];
        if (!preg_match("/^Dialogue/",$string)) {
          $fixed .= $string."\n";
        } else {
          $str_parts = explode(",",$string);
          $start = $str_parts[1];
          $end = $str_parts[2];
          if ($start > $end) {
            $str_parts[2] = $start;
            $str_parts[1] = $end;
            $start = $str_parts[1];
            $end = $str_parts[2];
          }
          if ($old > $start) {
            $str_parts[1] = $old;
          }
          $old = $end;
          $string = implode(",",$str_parts);
          $fixed .= $string."\n";
        }
      }
      print('<PRE>'."\n".$fixed."\n".'</PRE>');
    } else {
?>
    <CENTER>
      <FORM ACTION="subtitlefix.php" METHOD="POST">
        <TEXTAREA NAME="fix_this" COLS="100" ROWS="40" WRAP="VIRTUAL"></TEXTAREA>
        <BR>
        <INPUT TYPE="SUBMIT" VALUE="FIX IT!">
      </FORM>
    </CENTER>
<?
    }
?>
  </BODY>
</HTML>

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
Markku Uttula

Comment:



Comment:

(Maximum characters: 1200). You have characters left.