Advertisement
toritoesinocente

parte .srt

Nov 28th, 2022 (edited)
1,123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.83 KB | None | 0 0
  1. <?php
  2.    //parte los subtitulos de Youtube en 2 :)
  3.    //@toro 2022-11-28 https://tar.mx/
  4.    //
  5.    $filex = "/Users/gnu/Downloads/captions.srt";
  6.    if(isset($argv[1]) && is_file($argv[1])) $filex = $argv[1];
  7.    $file = file_get_contents($filex);
  8.    $data= explode("\n\n",$file);
  9.    $ndata = [];
  10.    foreach($data as $k=>$v) {
  11.       if(empty($v)) continue;
  12.       $v = explode("\n",$v);
  13.       $nl = $v[2];
  14.       //$nl = mb_strlen($nl,'UTF-8');
  15.       @$nl = explode("\n",wordwrap($nl,  ceil(mb_strlen($nl,'UTF-8')/2)+3));
  16.       unset($v[2]);
  17.       $v = array_merge($v,$nl);
  18.       $ndata[($k+1)] = implode("\n",$v);
  19.    }
  20.    $file = str_replace(".srt","-2.srt",$filex);
  21.    echo $file."\n";
  22.    $data = null;
  23.    foreach($ndata AS $k=>$v) {
  24.       $data .= $v."\n\n";
  25.    }
  26.    file_put_contents($file,trim($data));
  27.    // print_r($ndata);
Tags: php subtitle
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement