Como puedo sacar la informacion de la línea play_addr
y la calidad "ratio":"720p"
ya que soy algo novato usando funciones en PHP solo quiero un ejemplo para aprender
es un archivo JSON
donde esta la informacion
var data = {
"risk_infos": {
"warn":false,"content":"","risk_sink":false,"type":0}
,"label_top": {
"url_list":["http:\/\/p16-tiktokcdn-com.akamaized.net\/obj\/tiktok-obj\/1598708589477025.PNG","https:\/\/p16-tiktokcdn-com.akamaized.net\/obj\/tiktok-obj\/1598708589477025.PNG","http:\/\/p16-tiktokcdn-com.akamaized.net\/obj\/tiktok-obj\/1598708589477025.PNG","https:\/\/p16-tiktokcdn-com.akamaized.net\/obj\/tiktok-obj\/1598708589477025.PNG","http:\/\/p16-tiktokcdn-com.akamaized.net\/obj\/tiktok-obj\/1598708589477025.PNG","https:\/\/p16-tiktokcdn-com.akamaized.net\/obj\/tiktok-obj\/1598708589477025.PNG"],"uri":"tiktok-obj\/1598708589477025.PNG"}
,"author_user_id":188158835147382784,"item_comment_settings":0,"rate":10,"create_time":1522878942,"video": {
"ratio":"720p","origin_cover": {
"url_list":["\/\/mpak-suse1.akamaized.net\/reg02\/2018\/04\/05\/05\/a8f4505c-a16f-44a1-8d3f-27a24be38091_KHUspvwjWI.jpg"],"uri":"http:\/\/mpak-suse1.akamaized.net\/reg02\/2018\/04\/05\/05\/a8f4505c-a16f-44a1-8d3f-27a24be38091_KHUspvwjWI.jpg","preview_url":"\/\/mpak-suse1.akamaized.net\/img\/http:\/\/mpak-suse1.akamaized.net\/reg02\/2018\/04\/05\/05\/a8f4505c-a16f-44a1-8d3f-27a24be38091_KHUspvwjWI.jpg~tplv-tiktok-play.jpg"}
,"play_addr": {
"url_list":["\/\/mpak-suse1.akamaized.net\/reg02\/2018\/04\/05\/05\/6540715167737451535_XOmKXwzFpY.mp4"],"uri":"6540715167737451535"}
,"cover": {
"url_list":["\/\/mpak-suse1.akamaized.net\/reg02\/2018\/04\/05\/05\/a8f4505c-a16f-44a1-8d3f-27a24be38091_KHUspvwjWI.jpg"],"uri":"http:\/\/mpak-suse1.akamaized.net\/reg02\/2018\/04\/05\/05\/a8f4505c-a16f-44a1-8d3f-27a24be38091_KHUspvwjWI.jpg","preview_url":"\/\/mpak-suse1.akamaized.net\/img\/http:\/\/mpak-suse1.akamaized.net\/reg02\/2018\/04\/05\/05\/a8f4505c-a16f-44a1-8d3f-27a24be38091_KHUspvwjWI.jpg~tplv-tiktok-play.jpg"}
,"height":960,"width":540,"download_addr": {
"url_list":["\/\/mpak-suse1.akamaized.net\/reg02\/2018\/04\/05\/05\/6540715167737451535_XOmKXwzFpY.mp4"],"uri":"6540715167737451535"}
,"has_watermark":true,"play_addr_h264": {
"url_list":["http:\/\/v16.muscdn.com\/9d1dbe754d53a1a4b527694470c971d3\/5c610565\/video\/tos\/maliva\/tos-maliva-v-0068\/c4aeed8f3bbd4226b859974afa8b9ee2\/?rc=OGkzOTNpOzU5ZDRlNTlmNkApQHRwbndsQG85Rjg8MzczNDQ4OjozNTwzQCl1KUBnM3cpQGZlemV6b2Z2cGY2NUAvMV4xMzUvXjUxMi8tL2JhczVvI1xsaHFvIzQyMy8xLS4tLS8uLi4tLi9pOmItbyM6YC1vI2IrYiteZnI6IzAuXg%3D%3D","https:\/\/api2.musical.ly\/aweme\/v1\/play\/?video_id=d3ec26022b514a86a2288f6046a04f25\u0026line=0\u0026ratio=720p\u0026media_type=4\u0026vr_type=0\u0026test_cdn=None\u0026improve_bitrate=0"],"url_key":"d3ec26022b514a86a2288f6046a04f25_h264_720p","uri":"d3ec26022b514a86a2288f6046a04f25"}
,"duration":14000,"is_h265":0,"play_addr_lowbr": {
"url_list":["\/\/mpak-suse1.akamaized.net\/reg02\/2018\/04\/05\/05\/6540715167737451535_XOmKXwzFpY.mp4"],"uri":"6540715167737451535"}
,"dynamic_cover": {
"url_list":["http:\/\/mpak-suse1.akamaized.net\/reg02\/2018\/04\/05\/05\/35ae581c-cfb6-490c-b123-f1a611203dd4_jjsLnThzKc.webp"],"uri":"http:\/\/mpak-suse1.akamaized.net\/reg02\/2018\/04\/05\/05\/35ae581c-cfb6-490c-b123-f1a611203dd4_jjsLnThzKc.webp"}
}
}
Este es el codígo que estoy usando:
function url_get_contents($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10240');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$PHP_cUrl = url_get_contents('https://m.tiktok.com/v/6540715167737451535.html');
$Document = new DOMDocument();
$Document->loadHTML($PHP_cUrl);
$ScriptNodes = $Document->getElementsByTagName('script');
foreach($ScriptNodes as $Script){
if( strpos($Script->nodeValue, 'play_addr') && strpos($Script->nodeValue, 'ratio') ){
$cadena = $Script->nodeValue;
$cadena = substr($cadena, strpos($cadena, "=") + 1 );
$json = json_decode($cadena);
echo $json->video->play_addr->url_list[0];
echo $json->video->ratio;
}
}
var data
en tu PHP?. ¿Esa sintaxis es PHP? ¿Eso es un JSON? ¿Tienes eso así tal cual en tu código?json_decode()
lo tomas?