Home API Get youtube file resource in php

Get youtube file resource in php

220
0

YouTube is an American online video sharing and social media platform owned by Google. It was launched on February 14, 2005, by Steve Chen, Chad Hurley, and Jawed Karim. It is the second most visited website, right after Google itself. YouTube has more than one billion monthly users[7] who collectively watch more than one billion hours of videos each day.[8] As of May 2019, videos were being uploaded at a rate of more than 500 hours of content per minute

1. Create a new class function
function get_resource($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.youtube.com/watch?v=$id");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,true);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
return $result = curl_exec($ch);
}

2. Make a grabber file
$result = get_resource('FMqYhnN0Qjk'); //example video id https://www.youtube.com/watch?v=FMqYhnN0Qjk
if(!$result){
$response = array('status'=>'error','message'=>'Cant connected to youtube');
echo json_encode($response);
}else{
$m1 = explode('var ytInitialPlayerResponse = ',$result);
$m2 = explode(';<',$m1[1]); $s1 = explode('',$s1[1]);
if(!$s2[0]){
$response = array('status'=>'error','message'=>'Invalid response details');
echo json_encode($response);
}else{
$q1 = explode('',$q1[1]);
$output = $m2[0];
$baca = json_decode($output,true);
$durasi = $baca['videoDetails']['lengthSeconds'];
$file_data = array();
$file_data['status'] = "success";
$file_data['message'] = "Data Found";
$file_data['song_title'] = "$s2[0]";
$file_data['song_channel'] = "$q2[0]";
$file_data['song_duration'] = "$durasi";
$file_data['song_thumb'] = "$thumbnail";
$file_data["files"] = array();
$o = 1;
$satu = $baca['streamingData']['adaptiveFormats'];
foreach($satu as $data){
$m3 = explode(';',$data['mimeType']);
$file_data2['mimeType'] = $m3[0];
$file_data2['quality'] = $data['quality'];
if($data['url']){
$file_data2['outputType'] = '1';
$file_data2['url'] = $data['url'];
$file_data2['cek_akses'] = request("$data[urls]");
}else
if($data['signatureCipher']) {
$file_data2['outputType'] = '2';
$file_data2['url'] = 'Blocked_by_Signaturechipper';
}else{
$file_data2['url'] = 'unknown';
$file_data2['cek_akses'] = 'unkown';
}
array_push($file_data["files"], $file_data2);
$o++;
}
echo json_encode($file_data);
}
}

If you got Blocked_by_Signaturechipper response means your request is blocked by youtube and the file url is compressed by youtube, you have to create a new class function to decode SignatureChipper by youtube.

Credit Card Details API in PHP

A credit card is a payment card issued to users (cardholders) to enable the cardholder to pay a merchant for Read more

How to do an ip address lookup via extreme-ip-lookup.com in php

Very simple. Get all geolocation information about an IP address in JSON, JSONP and CSV format through our API. Free Read more

Previous articleIndonesian state company job applicant data has been hacked
Next articleEmail Login checker API in php

LEAVE A REPLY

Please enter your comment!
Please enter your name here