ytcaption.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. function curlGet($url) {
  3. if(in_array('curl', get_loaded_extensions())){
  4. $appSettings = parse_ini_file('../config/config.ini',true);
  5. $ch = curl_init($url);
  6. curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Linux x86_64; rv:62.0) Gecko/20100101 Firefox/62.0');
  7. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  8. curl_setopt($ch, CURLOPT_HEADER, 0);
  9. //curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
  10. if($appSettings["Proxy"]["type"]) {
  11. curl_setopt($ch, CURLOPT_PROXY, $appSettings["Proxy"]["type"]."://".$appSettings["Proxy"]["domain"].":".$appSettings["Proxy"]["port"]);
  12. curl_setopt($ch, CURLOPT_PROXYUSERPWD, $appSettings["Proxy"]["username"].":".$appSettings["Proxy"]["password"]);
  13. }
  14. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  15. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  16. $result = curl_exec($ch);
  17. curl_close($ch);
  18. return $result;
  19. }
  20. return FALSE;
  21. }
  22. function timevtt($gtime) {
  23. if(strlen(date("H",intval($gtime))-1) == 1) $hour = "0".intval(date("H",intval($gtime))-1);
  24. else $hour = intval(date("H",intval($gtime))-1);
  25. if(strlen(explode(".",$gtime)[1]) == 3) return $hour.":".date("i:s",intval($gtime)).".".explode(".",$gtime)[1];
  26. if(strlen(explode(".",$gtime)[1]) == 2) return $hour.":".date("i:s",intval($gtime)).".".explode(".",$gtime)[1]."0";
  27. if(strlen(explode(".",$gtime)[1]) == 1) return $hour.":".date("i:s",intval($gtime)).".".explode(".",$gtime)[1]."00";
  28. if(strlen(explode(".",$gtime)[1]) == 0) return $hour.":".date("i:s",intval($gtime)).".".explode(".",$gtime)[1]."000";
  29. }
  30. $caption = new SimpleXMLElement(curlGet($_GET["url"]));
  31. echo "WEBVTT\n";
  32. echo "Kind: captions\n";
  33. echo "Language: ".$_GET["lang"]."\n\n";
  34. for($i=0;$i<count($caption->text);$i++) {
  35. if($i == count($caption->text)-1) {
  36. if(strlen(explode(".",$caption->text[$i]["start"])[1]+explode(".",$caption->text[$i]["dur"])[1]) == 3) $endtime = array(explode(".",$caption->text[$i]["start"])[0]+explode(".",$caption->text[$i]["dur"])[0],explode(".",$caption->text[$i]["start"])[1]+explode(".",$caption->text[$i]["dur"])[1]);
  37. else $endtime = array(explode(".",$caption->text[$i]["start"])[0]+explode(".",$caption->text[$i]["dur"])[0]+1,explode(".",$caption->text[$i]["start"])[1]+explode(".",$caption->text[$i]["dur"])[1]);
  38. echo timevtt($caption->text[$i]["start"])." --> ".timevtt(implode(".",$endtime))."\n";
  39. }
  40. else echo timevtt($caption->text[$i]["start"])." --> ".timevtt($caption->text[$i+1]["start"])."\n";
  41. echo preg_replace('/<font color="#[a-fA-F0-9]{6}">/',"",str_replace("</font>","",$caption->text[$i]))."\n\n";
  42. }
  43. ?>