Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //parte los subtitulos de Youtube en 2 :)
- //@toro 2022-11-28 https://tar.mx/
- //
- $filex = "/Users/gnu/Downloads/captions.srt";
- if(isset($argv[1]) && is_file($argv[1])) $filex = $argv[1];
- $file = file_get_contents($filex);
- $data= explode("\n\n",$file);
- $ndata = [];
- foreach($data as $k=>$v) {
- if(empty($v)) continue;
- $v = explode("\n",$v);
- $nl = $v[2];
- //$nl = mb_strlen($nl,'UTF-8');
- @$nl = explode("\n",wordwrap($nl, ceil(mb_strlen($nl,'UTF-8')/2)+3));
- unset($v[2]);
- $v = array_merge($v,$nl);
- $ndata[($k+1)] = implode("\n",$v);
- }
- $file = str_replace(".srt","-2.srt",$filex);
- echo $file."\n";
- $data = null;
- foreach($ndata AS $k=>$v) {
- $data .= $v."\n\n";
- }
- file_put_contents($file,trim($data));
- // print_r($ndata);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement