Advertisement
retesere20

youtube-video-info-old

Feb 8th, 2023 (edited)
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. // ############ youtube funcs ###########
  2. // 'flags' contains many-info about video
  3. public function youtube_data($ytVideoId, $api_redirect_url=null) {
  4. $targetUrl = 'https://youtube.com/get_video_info?video_id='.$ytVideoId;
  5. // when Youtube Blocks this Server's IP, use 3rd party:
  6. // $ResponserUrl = 'http://my_another_clean_host_site.com/youtube_info.php?yt_id='; and this code: pastebin_com/dxigxnNH
  7. // if external server is used
  8. if (!empty($api_redirect_url))
  9. $targetUrl = $api_redirect_url . urlencode($targetUrl);
  10. $data = $this->file_get_contents($targetUrl);
  11. parse_str($data , $full_info);
  12. return $full_info;
  13. }
  14.  
  15. public function youtube_mediafiles($data) {
  16. $n1 = json_decode( $data['player_response'], true);
  17. $streamingData = $n1['streamingData'];
  18. $formats = $streamingData['formats']; // contains Video with audio, i.e. example : pastebin_com/R0n1jC9W
  19. $adaptiveFormats = $streamingData['adaptiveFormats']; // contains separated streams (videos / audios): pastebin_com/qui0w8BB
  20. $audiosArray = [];
  21. // we need only audios (as videos dont have an audio)
  22. foreach ($adaptiveFormats as $each) {
  23. if ( stripos($each['mimeType'], 'audio/') !== false ) {
  24. $audiosArray[] = $each;
  25. }
  26. }
  27. $res = ['status'=>'success', 'data'=>['videos'=> $formats, 'audios'=>$audiosArray] ];
  28. return $res;
  29. }
  30. public function youtube_video_details($data) {
  31. $arr = json_decode( $data['player_response'], true);
  32. return $arr['videoDetails'];
  33. }
  34. public function youtube_best_audio($audios_or_videos) {
  35. $max_array = [];
  36. foreach($audios_or_videos as $each_A_V){
  37. if (empty($max_array) || $each_A_V['contentLength'] > $max_array['contentLength'] )
  38. $max_array = $each_A_V;
  39. }
  40. return $max_array;
  41. }
  42. public function youtube_low_video($mediaFiles) {
  43. $fileUrl ='';
  44. foreach($mediaFiles['data']['videos'] as $each)
  45. {
  46. if ($each['audioQuality']=='AUDIO_QUALITY_LOW')
  47. {
  48. $fileUrl = $each['url'];
  49. }
  50. }
  51. return $fileUrl;
  52. }
  53. public function youtube_file_url($array){
  54. if (array_key_exists('url', $array) ){
  55. return $array['url'];
  56. }
  57. elseif (array_key_exists('signatureCipher', $array) ){
  58. $sig = $array['signatureCipher'];
  59. parse_str( str_replace('\\u0026','&', $sig), $array);
  60. return $array['url'];
  61. }
  62. else{
  63. return "INVALID_DATA. CANT GET URL from: ". print_r($array,true);
  64. }
  65. }
  66. public function youtube_curl($url)
  67. {
  68. $ch=curl_init();
  69. curl_setopt($ch,CURLOPT_USERAGENT, "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.35 (KHTML, like Gecko) Chrome/84.0.4147.00 Safari/537.35");
  70. curl_setopt($ch,CURLOPT_URL,$url);
  71. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  72. curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,0);
  73. curl_setopt($ch,CURLOPT_HEADER,0);
  74. curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
  75. curl_setopt($ch,CURLOPT_TIMEOUT,100000);
  76.  
  77. $curl_output=curl_exec($ch);
  78. $curlstatus=curl_getinfo($ch);
  79. curl_close($ch);
  80.  
  81. return $curl_output;
  82. }
  83. //
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement