Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ############ youtube funcs ###########
- // 'flags' contains many-info about video
- public function youtube_data($ytVideoId, $api_redirect_url=null) {
- $targetUrl = 'https://youtube.com/get_video_info?video_id='.$ytVideoId;
- // when Youtube Blocks this Server's IP, use 3rd party:
- // $ResponserUrl = 'http://my_another_clean_host_site.com/youtube_info.php?yt_id='; and this code: pastebin_com/dxigxnNH
- // if external server is used
- if (!empty($api_redirect_url))
- $targetUrl = $api_redirect_url . urlencode($targetUrl);
- $data = $this->file_get_contents($targetUrl);
- parse_str($data , $full_info);
- return $full_info;
- }
- public function youtube_mediafiles($data) {
- $n1 = json_decode( $data['player_response'], true);
- $streamingData = $n1['streamingData'];
- $formats = $streamingData['formats']; // contains Video with audio, i.e. example : pastebin_com/R0n1jC9W
- $adaptiveFormats = $streamingData['adaptiveFormats']; // contains separated streams (videos / audios): pastebin_com/qui0w8BB
- $audiosArray = [];
- // we need only audios (as videos dont have an audio)
- foreach ($adaptiveFormats as $each) {
- if ( stripos($each['mimeType'], 'audio/') !== false ) {
- $audiosArray[] = $each;
- }
- }
- $res = ['status'=>'success', 'data'=>['videos'=> $formats, 'audios'=>$audiosArray] ];
- return $res;
- }
- public function youtube_video_details($data) {
- $arr = json_decode( $data['player_response'], true);
- return $arr['videoDetails'];
- }
- public function youtube_best_audio($audios_or_videos) {
- $max_array = [];
- foreach($audios_or_videos as $each_A_V){
- if (empty($max_array) || $each_A_V['contentLength'] > $max_array['contentLength'] )
- $max_array = $each_A_V;
- }
- return $max_array;
- }
- public function youtube_low_video($mediaFiles) {
- $fileUrl ='';
- foreach($mediaFiles['data']['videos'] as $each)
- {
- if ($each['audioQuality']=='AUDIO_QUALITY_LOW')
- {
- $fileUrl = $each['url'];
- }
- }
- return $fileUrl;
- }
- public function youtube_file_url($array){
- if (array_key_exists('url', $array) ){
- return $array['url'];
- }
- elseif (array_key_exists('signatureCipher', $array) ){
- $sig = $array['signatureCipher'];
- parse_str( str_replace('\\u0026','&', $sig), $array);
- return $array['url'];
- }
- else{
- return "INVALID_DATA. CANT GET URL from: ". print_r($array,true);
- }
- }
- public function youtube_curl($url)
- {
- $ch=curl_init();
- 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");
- curl_setopt($ch,CURLOPT_URL,$url);
- curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
- curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,0);
- curl_setopt($ch,CURLOPT_HEADER,0);
- curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
- curl_setopt($ch,CURLOPT_TIMEOUT,100000);
- $curl_output=curl_exec($ch);
- $curlstatus=curl_getinfo($ch);
- curl_close($ch);
- return $curl_output;
- }
- //
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement