在对象数组中的对象数组中提取url

时间:2018-04-09 08:51:02

标签: php arrays json object youtube-data-api

这是一个YouTube视频采集器php应用程序 我想从对象数组

中的对象数组中仅提取具有大小和视频格式链接的下载链接

这是我的http://videos.hdbuddy.com/test.php代码

<?php
include 'src/YouTubeDownloader.php';
$yt = new YouTubeDownloader();

$links = $yt->getDownloadLinks("https://www.youtube.com/watch?v=QxsmWxxouIM");

var_dump($links);
?>

结果

array(5) { 
  [22]=> array(2) { 
    ["url"]=> string(656) "https://r4---sn-ab5szn76.googlevideo.com/videoplayback?lmt=1507179503294268&ipbits=0&itag=22&fvip=3&mime=video%2Fmp4&key=yt6&expire=1523284910&mm=31%2C26&mn=sn-ab5szn76%2Csn-vgqsener&c=WEB&ms=au%2Conr&mt=1523263121&mv=m&ip=66.45.230.2&ei=TSfLWpLWOYLi8gS1kaTQCw&beids=%5B9466594%5D&sparams=dur%2Cei%2Cgcr%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Clmt%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cpl%2Cratebypass%2Crequiressl%2Csource%2Cexpire&id=o-AKa0YLmNTIX4dFUNMwWQoCTIANkmABH8S0RMBx5ctQwz&requiressl=yes&initcwndbps=993750&pl=21&dur=265.357&source=youtube&ratebypass=yes&gcr=us&signature=71705585E2AD7E6A0E1BFD62AD83252ACF7D29A0.50FD9186F9657251D824C2D7B81D542BFAEB7CD7"
    ["format"]=> string(13) "MP4 720p (HD)"
  }
  [43]=> array(2) {
    ["url"]=> string(690) "https://r4---sn-ab5szn76.googlevideo.com/videoplayback?lmt=1501662219959316&ipbits=0&itag=43&fvip=3&mime=video%2Fwebm&key=yt6&expire=1523284910&mm=31%2C26&mn=sn-ab5szn76%2Csn-vgqsener&c=WEB&ms=au%2Conr&mt=1523263121&mv=m&ip=66.45.230.2&ei=TSfLWpLWOYLi8gS1kaTQCw&beids=%5B9466594%5D&sparams=clen%2Cdur%2Cei%2Cgcr%2Cgir%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Clmt%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cpl%2Cratebypass%2Crequiressl%2Csource%2Cexpire&id=o-AKa0YLmNTIX4dFUNMwWQoCTIANkmABH8S0RMBx5ctQwz&clen=23912664&requiressl=yes&gir=yes&initcwndbps=993750&pl=21&dur=0.000&source=youtube&ratebypass=yes&gcr=us&signature=1F17AD81E24338CAD45AE0A0AA0D7491F3CC8F00.C405F6188B348A7C4A347CE40BCB11B1EE2963CF"
    ["format"]=> string(9) "WebM 360p"
  }
  [18]=> array(2) {
    ["url"]=> string(691) "https://r4---sn-ab5szn76.googlevideo.com/videoplayback?lmt=1501659763427190&ipbits=0&itag=18&fvip=3&mime=video%2Fmp4&key=yt6&expire=1523284910&mm=31%2C26&mn=sn-ab5szn76%2Csn-vgqsener&c=WEB&ms=au%2Conr&mt=1523263121&mv=m&ip=66.45.230.2&ei=TSfLWpLWOYLi8gS1kaTQCw&beids=%5B9466594%5D&sparams=clen%2Cdur%2Cei%2Cgcr%2Cgir%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Clmt%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cpl%2Cratebypass%2Crequiressl%2Csource%2Cexpire&id=o-AKa0YLmNTIX4dFUNMwWQoCTIANkmABH8S0RMBx5ctQwz&clen=18087055&requiressl=yes&gir=yes&initcwndbps=993750&pl=21&dur=265.357&source=youtube&ratebypass=yes&gcr=us&signature=D1AC382CB1A739B1B8D991772C587EFC32377793.0D741B6549A8E2C8A52A567C5EF63A4844929999"
    ["format"]=> string(8) "MP4 360p"
  }
  [36]=> array(2) {
    ["url"]=> string(663) "https://r4---sn-ab5szn76.googlevideo.com/videoplayback?lmt=1501659917733148&ipbits=0&itag=36&fvip=3&mime=video%2F3gpp&key=yt6&expire=1523284910&mm=31%2C26&mn=sn-ab5szn76%2Csn-vgqsener&c=WEB&ms=au%2Conr&mt=1523263121&mv=m&ip=66.45.230.2&ei=TSfLWpLWOYLi8gS1kaTQCw&beids=%5B9466594%5D&sparams=clen%2Cdur%2Cei%2Cgcr%2Cgir%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Clmt%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cpl%2Crequiressl%2Csource%2Cexpire&id=o-AKa0YLmNTIX4dFUNMwWQoCTIANkmABH8S0RMBx5ctQwz&clen=7376503&requiressl=yes&gir=yes&initcwndbps=993750&pl=21&dur=265.404&source=youtube&gcr=us&signature=6360F52E3A3ABB93F476ABDA63228A5D88191C7F.89EA5099EB1EF368436EB2FE4DC2C45899FD7CFC" 
    ["format"]=> string(7) "Unknown"
  }
  [17]=> array(2) {
    ["url"]=> string(663) "https://r4---sn-ab5szn76.googlevideo.com/videoplayback?lmt=1501659765741655&ipbits=0&itag=17&fvip=3&mime=video%2F3gpp&key=yt6&expire=1523284910&mm=31%2C26&mn=sn-ab5szn76%2Csn-vgqsener&c=WEB&ms=au%2Conr&mt=1523263121&mv=m&ip=66.45.230.2&ei=TSfLWpLWOYLi8gS1kaTQCw&beids=%5B9466594%5D&sparams=clen%2Cdur%2Cei%2Cgcr%2Cgir%2Cid%2Cinitcwndbps%2Cip%2Cipbits%2Citag%2Clmt%2Cmime%2Cmm%2Cmn%2Cms%2Cmv%2Cpl%2Crequiressl%2Csource%2Cexpire&id=o-AKa0YLmNTIX4dFUNMwWQoCTIANkmABH8S0RMBx5ctQwz&clen=2648195&requiressl=yes&gir=yes&initcwndbps=993750&pl=21&dur=265.404&source=youtube&gcr=us&signature=C71A2E632D88447878B5D0F32866FC20F853A1A8.18E68277C47EA61DF64695AC92033059DBB25DEF" 
    ["format"]=> string(8) "3GP 144p"
  }
}

任何帮助非常感谢您提前感谢

1 个答案:

答案 0 :(得分:0)

好吧,我不知道你会怎么做,但这是如何。

<?php
include 'src/YouTubeDownloader.php';
$yt = new YouTubeDownloader();

$links = $yt->getDownloadLinks("https://www.youtube.com/watch?v=QxsmWxxouIM");

foreach($links as $k => $v) {
   $url = $v['url'];
   $format = $v['format'];
}

您将使用$url$format做些什么取决于您。