jorarmarfin/laravel_youtube

从YouTube视频中获取信息

0.0.4 2020-02-08 05:28 UTC

This package is auto-updated.

Last update: 2024-09-08 15:51:31 UTC


README

最新稳定版本 总下载量 最新不稳定版本 许可 以简单方式在 Laravel 中显示YouTube视频的元数据

安装

可以通过在项目的composer.json中要求jorarmarfin/laravel_youtube包,通过composer安装LaravelYoutube服务提供者。

Laravel 5.5+ 将使用自动发现功能。

{
    "require": {
        "jorarmarfin/laravel_youtube": "0.0.2"
    }
}

如果您不使用自动发现,您需要在 config/app.php 中包含服务提供者/外观。

'providers' => [
    //...
    JorarMarfin\LaravelYoutube\LaravelYoutubeServiceProvider::class,
]

//...

'aliases' => [
    //...
    'LaravelYoutube' => JorarMarfin\LaravelYoutube\Facades\LaravelYoutubeFacade::class
]

这就完成了!您已准备好开始。

以下是一个小例子

use LaravelYoutube; // at the top of the file

$data = LaravelYoutube::getData('https://www.youtube.com/watch?v=cYgkfQUUwWQ');
$data is object
+"thumbnail_url": "https://i.ytimg.com/vi/cYgkfQUUwWQ/hqdefault.jpg"
  +"version": "1.0"
  +"type": "video"
  +"html": "<iframe width="480" height="270" src="https://www.youtube.com/embed/cYgkfQUUwWQ?feature=oembed" frameborder="0" allow="accelerometer; autoplay; encrypted-media; ▶"
  +"provider_url": "https://www.youtube.com/"
  +"thumbnail_width": 480
  +"width": 480
  +"thumbnail_height": 360
  +"author_url": "https://www.youtube.com/user/CocinoThai"
  +"height": 270
  +"author_name": "Kwan Homsai"
  +"title": "Receta de Pollo Teriyaki - Chicken Teriyaki Recipe l Kwan Homsai"
  +"provider_name": "YouTube"