vinelab / youtube
此软件包最新版本(v9.6)没有可用的许可信息。
v9.6
2015-03-02 12:31 UTC
Requires
- php: >=5.3.0
- illuminate/support: 5.*
- vinelab/http: 1.2.*
Requires (Dev)
- mockery/mockery: 0.*
- phpunit/phpunit: 4.2.*
- squizlabs/php_codesniffer: 1.*
- vinelab/php-cs-fixer: dev-master
README
此库用于使用URL从youtube获取视频和频道。
安装
- 使用Composer包含:
"vinelab/youtube" : "*"
- 添加服务提供者
'Vinelab\Youtube\YoutubeServiceProvider'
- 添加外观
'Youtube' => 'Vinelab\Youtube\Facades\Youtube'
- 发布配置文件
php artisan config:publish Vinelab/youtube
- 将您的密钥添加到配置文件
使用
使用 Youtube
外观访问软件包的功能。
Youtube::video($url)
要获取视频,请使用
Youtube::video($url)
,这将返回类型为Najem\Videos\Video
的对象。
您可以通过传递包含
Url's
的array
来一次获取多个videos
,到Youtube::videos($urls)
或甚至Youtube::video($urls)
。
响应
object(Vinelab\Youtube\Video)[180] public 'kind' => string 'youtube#video' (length=13) public 'id' => string '1j1MBSwg44A' (length=11) public 'etag' => string '"ePFRUfYBkeQ2ncpP9OLHKB0fDw4/ZsQyzEl5gbrEkz55D3fNHwM1RUM"' (length=57) public 'sync_enabled' => boolean true public 'synced_at' => string '2014-05-08T15:55:06+00:00' (length=25) public 'snippet' => array (size=5) 'publishedAt' => string '2013-07-02T16:11:38.000Z' (length=24) 'channelId' => string 'UCUuseKzXVxgBCnSy8KU90jg' (length=24) 'title' => string 'Pink Floyd - Comfortably Numb (Cover by Hayajan)' (length=48) 'description' => string 'Hayajan | Ya Bay: Lyrics of Comfortably Numb wr'... (length=675) 'channelTitle' => string 'Alaa Wardi' (length=10) public 'thumbnails' => array (size=5) 'default' => string 'https://i1.ytimg.com/vi/1j1MBSwg44A/default.jpg' (length=47) 'medium' => string 'https://i1.ytimg.com/vi/1j1MBSwg44A/mqdefault.jpg' (length=49) 'high' => string 'https://i1.ytimg.com/vi/1j1MBSwg44A/hqdefault.jpg' (length=49) 'standard' => string 'https://i1.ytimg.com/vi/1j1MBSwg44A/sddefault.jpg' (length=49) 'maxres' => string 'https://i1.ytimg.com/vi/1j1MBSwg44A/maxresdefault.jpg' (length=53)
Youtube::channel($url)
要获取频道,请使用
Youtube::channel($url)
,这将返回类型为Najem\Videos\Channel
的对象。
响应
object(Najem\Videos\Channel)[209] protected 'data' => array (size=14) 'kind' => string 'youtube#channel' (length=15) 'etag' => string '"ePFRUfYBkeQ2ncpP9OLHKB0fDw4/53nIEDRhzjlzEN0ZZf1TQ5Oyr_0"' (length=57) 'sync_enabled' => boolean true 'id' => string 'UCBsKiXTgZrg0tqz4yz_R5Tw' (length=24) 'synced_at' => string '2014-05-08T15:56:10+00:00' (length=25) 'title' => string 'adib hanna' (length=10) 'description' => string '' (length=0) 'published_at' => string '2009-12-27T22:46:00.000Z' (length=24) 'default_thumb' => string 'https://yt3.ggpht.com/-xRortO695HE/AAAAAAAAAAI/AAAAAAAAAAA/b2VPZd_ZNsk/s88-c-k-no/photo.jpg' (length=91) 'medium_thumb' => string 'https://yt3.ggpht.com/-xRortO695HE/AAAAAAAAAAI/AAAAAAAAAAA/b2VPZd_ZNsk/s240-c-k-no/photo.jpg' (length=92) 'high_thumb' => string 'https://yt3.ggpht.com/-xRortO695HE/AAAAAAAAAAI/AAAAAAAAAAA/b2VPZd_ZNsk/s240-c-k-no/photo.jpg' (length=92) 'playlist_likes' => string 'LLBsKiXTgZrg0tqz4yz_R5Tw' (length=24) 'playlist_uploads' => string 'UUBsKiXTgZrg0tqz4yz_R5Tw' (length=24) 'google_plus_user_id' => string '113619238331121062947' (length=21) 'videos' => object(Najem\Videos\VideoCollection)[177] protected 'items' => array (size=2) 0 => object(Najem\Videos\Video)[207] public 'kind' => string 'youtube#video' (length=13) public 'id' => string 'cdy2iLDznbI' (length=11) public 'etag' => string '"LFawZk2qAkq9bosMnzaQJqPHO_0/lXpe47wULVDBmjpY0A3wMuM2PpQ"' (length=57) public 'sync_enabled' => boolean true public 'snippet' => array (size=5) ... public 'thumbnails' => array (size=3) ... 1 => object(Najem\Videos\Video)[208] public 'kind' => string 'youtube#video' (length=13) public 'id' => string '4l5M0vvOnjc' (length=11) public 'etag' => string '"LFawZk2qAkq9bosMnzaQJqPHO_0/af1eeVp2yks5Z1PgoBwAtyQK578"' (length=57) public 'sync_enabled' => boolean true public 'snippet' => array (size=5) ... public 'thumbnails' => array (size=3) ...
Youtube::playlist($url)
要获取播放列表,请使用
Youtube::playlist($url)
,这将返回类型为Najem\Videos\Playlist
的对象。
响应
object(Vinelab\Youtube\Playlist)[811] protected 'data' => array (size=12) 'kind' => string 'youtube#playlist' (length=16) 'etag' => string '"9Y5jTkxN1JET3y-M4wKMA5aK7Mk/Ed_sn_8oQKILYPBK-rRE431SEss"' (length=57) 'sync_enabled' => boolean true 'id' => string 'PLaMWTg0sIKTdOsNOI9h2AjKHUremHKGNZ' (length=34) 'synced_at' => string '2015-02-27T14:12:18+00:00' (length=25) 'title' => string 'Laravel 4.1 Tutorial | مدخل الى برمجة الوب بإستخدام لارافيل' (length=90) 'description' => string '' (length=0) 'published_at' => string '2014-06-02T00:47:12.000Z' (length=24) 'default_thumb' => string 'https://i.ytimg.com/vi/FasdiQBlWwM/default.jpg' (length=46) 'medium_thumb' => string 'https://i.ytimg.com/vi/FasdiQBlWwM/mqdefault.jpg' (length=48) 'high_thumb' => string 'https://i.ytimg.com/vi/FasdiQBlWwM/hqdefault.jpg' (length=48) 'videos' => object(Vinelab\Youtube\VideoCollection)[695] protected 'items' => array (size=9) 0 => object(Vinelab\Youtube\Video)[802] public 'kind' => string 'youtube#playlistItem' (length=20) public 'id' => string 'PLoqlw2-AY6NMK_3wSxsZieCVbVrh7I4ZUMlgYhD46jpk' (length=45) public 'etag' => string '"9Y5jTkxN1JET3y-M4wKMA5aK7Mk/1CE9qGYaTyrvAf_cVZDngkiJNrI"' (length=57) public 'sync_enabled' => boolean false public 'synced_at' => string '2015-02-27T14:12:18+00:00' (length=25) public 'snippet' => array (size=8) 'publishedAt' => string '2014-06-02T00:48:26.000Z' (length=24) 'channelId' => string 'UCpOLwC-MKK9STITTUAYlmVQ' (length=24) 'title' => string '1 - Laravel 4.1: Introduction | مقدمة الى لارافيل' (length=64) 'description' => string '- why Laravel - what is laravel 4 - walking through the top features - system and knowlege requirement' (length=102) 'channelTitle' => string 'Mahmoud Zalt' (length=12) 'playlistId' => string 'PLaMWTg0sIKTdOsNOI9h2AjKHUremHKGNZ' (length=34) 'position' => int 0 'resourceId' => object(stdClass)[729] public 'kind' => string 'youtube#video' (length=13) public 'videoId' => string 'FasdiQBlWwM' (length=11) public 'thumbnails' => array (size=5) 'default' => string 'https://i.ytimg.com/vi/FasdiQBlWwM/default.jpg' (length=46) 'medium' => string 'https://i.ytimg.com/vi/FasdiQBlWwM/mqdefault.jpg' (length=48) 'high' => string 'https://i.ytimg.com/vi/FasdiQBlWwM/hqdefault.jpg' (length=48) 'standard' => string 'https://i.ytimg.com/vi/FasdiQBlWwM/sddefault.jpg' (length=48) 'maxres' => string 'https://i.ytimg.com/vi/FasdiQBlWwM/maxresdefault.jpg' (length=52) public 'url' => string 'https://www.youtube.com/watch?v=PLoqlw2-AY6NMK_3wSxsZieCVbVrh7I4ZUMlgYhD46jpk' (length=77) 1 => object(Vinelab\Youtube\Video)[803] public 'kind' => string 'youtube#playlistItem' (length=20) public 'id' => string 'PLoqlw2-AY6NMK_3wSxsZieCWxHwDW_yyZU5fw7We9j94' (length=45) ... 2 => ...
Youtube::sync($resource)
要同步任何检索到的资源,请使用
Youtube::sync($resource)
。
- 您可以同步
Video|Channel|Playlist
,并将返回更改后的对象Video|Channel|Playlist
。 - 如果保存的数据被手动更改,则无法同步数据,这意味着
sync_enabled
的值被设置为false
。 - 如果将视频和频道传递给同步方法,或传递空(已删除)的频道或视频,将抛出
IncompatibleParametersObjectTypesException
。
URL验证
- 要验证给定的URL,您可以使用
Vinelab\Youtube\Validators\VideoValidator
类。 - 使用
validate
方法并将URL传递给它。
示例
$this->validator->validate(compact('url', 'url1', 'url2', 'url3'));
如果验证失败,将抛出 InvalidVideoException
。