scarletsfiction / littleyoutube
Requires
- php: >=5.4
This package is auto-updated.
Last update: 2020-10-26 06:09:59 UTC
README
LittleYoutube
你是否曾梦想在自己的网站上展示自己的频道?
LittleYoutube可以帮助你
警告
YouTube不喜欢内容被抓取。请尊重他们的服务,不要将此库用作爬虫或他们网站的替代品。
此库是为了帮助社区开发的。
目录
入门
- 克隆/下载此存储库
- 将
LittleYoutube.php
包含到你的PHP脚本中
通过composer下载
将LittleYoutube添加到composer.json配置文件。
$ composer require scarletsfiction/littleyoutube
然后更新它
$ composer update
示例用法
<?php // require 'vendor/autoload.php'; require_once "LittleYoutube.php"; use ScarletsFiction\LittleYoutube; $video = LittleYoutube::video("https://www.youtube.com/watch?v=xQomv1gqmb4"); echo("Video ID:".$video->data['videoID']."\n"); print_r($video->getVideoImages());
文档
LittleYoutube选项
可用选项
{ // Must be set to save the decipher logic "temporaryDirectory"=>realpath("./temp"), // View the decipher logic as a text "signatureDebug"=>false || realpath("./signatureDebug.log"), // Get the detailed info "processDetail"=>true, // Optional if the video can't be downloaded on some country "useRedirector"=>false, // Will be slow because all url header will be checked "loadVideoSize"=>false, // Parse from VideoInfo or VideoPage "processVideoFrom"=>"VideoInfo" || "VideoPage" }
视频类
$video = LittleYoutube::video("videoURLHere", options);
//重新初始化视频类 $video->init("videoURLHere");
返回视频类
获取视频预览图
$video->getImage();
返回索引数组
[ "HighQualityURL", "MediumQualityURL", "DefaultQualityURL" ]
获取嵌入链接
$video->getEmbedLink();
// Usually we will wrap it with iframe echo('<iframe width="480" height="360" src="'.$video->getEmbedLink().'" frameborder="0" allowfullscreen></iframe>');
解析字幕
$video->parseSubtitle(args, asSRT);
- args: 字幕索引或xml字符串
- asSRT: 以srt格式返回
- 注意:如果你传递字幕索引,则必须启用/调用ProcessDetails
[ [0]=>[ [time] => 1.31, [duration] => 6.609, [text]=>"in a single lifetime we can take a days" ], ... ]
获取视频数据
$video->data;
- 您也可以调用$video->processDetails()来刷新数据
返回当前视频数据的关联数组
{ "videoID"=>"", //When ProcessDetail was enabled/called "playerID", "title", "duration", "viewCount", "like", "dislike", "author", "subtitle", "uploaded", "description", "metatag", "channelID", // Not available when ProcessDetails = false video=>{ "encoded"=>[ [0] => { "itag", "type"=>[ [0] => Media //video [1] => Format //mp4 [2] => Encoder //avc1.64001F, mp4a.40.2 ], "expire", //timestamp "quality", //hd720, medium, small "url", "size" //When loadVideoSize was enabled }, ... ], "adaptive"=>[ [0] => { "itag", "type"=>[ [0] => Media //video [1] => Format //mp4 [2] => Encoder //avc1.4d401f ], "expire", //timestamp "quality", //1080p, 720p, 192k, 144k "url", "size" //When loadVideoSize was enabled }, ... ], //If it's a live stream, then return m3u8 url only "stream" } }
频道类
$channel = LittleYoutube::channel("channelURLHere", options);
//重新初始化频道类 $channel->init("channelURLHere");
返回频道类
获取RSS URL
$channel->getChannelRSS();
返回字符串
https://www.youtube.com/feeds/videos.xml?channel_id=...
获取频道数据
$channel->data;
- 您还可以调用 $channel->processDetails() 来刷新数据
返回当前频道数据的关联数组
{ //Some data will available when ProcessDetail was enabled/called "channelID", "userID", "playlists"=>[ [0]=>{ "playlistID"=>"" "title"=>"", "length"=>0 }, ... ] "videos"=>[ [0]=>{ "videoID"=>"" "title"=>"", "viewCount"=>0 }, ... ] }
播放列表类
$playlist = LittleYoutube::playlist("playlistURLHere", options);
//重新初始化播放列表类 $playlist->init("playlistURLHere");
返回播放列表类
获取播放列表数据
$playlist->data;
- 您还可以调用 $playlist->processDetails() 来刷新数据
返回字符串
{ //Some data will available when ProcessDetail was enabled/called "playlistID", "channelID", "userID", "userData"=>{ "name", image }, "videos"=>[ [0]=>{ "title", "videoID" }, ... ] }
搜索类
$search = LittleYoutube::search("searchQueryHere", options);
//重新初始化搜索类 $search->init("searchQueryHere");
返回搜索类
获取搜索数据
$search->data;
- 您还可以调用 $search->processDetails() 来刷新数据
返回字符串
{ "query", // Not available when ProcessDetails = false "video"=>[ [0]=>{ "videoID", "title", "duration", "userID", "userName", "uploaded", "views" } ], //When available "next", "previous" }
下一个结果
$search->next();
这将把下一页的结果添加到当前数据中
动态更改设置
您也可以在初始化 LittleYoutube 类后更改设置
$classes->settings[options] = value;
贡献
如果您想帮助 LittleYoutube 库,请让它变得更好,并提交一个 pull request。
别忘了关注我 ^.^)/
许可证
LittleYoutube 在 MIT 许可证下。