lapalabs/youtube-helper
Composer 安装命令:
composer require lapalabs/youtube-helper
包简介
A tiny package to convenience work with YouTube media resources. Allow to extract ID from resource URL and build valid resource URLs.
README 文档
README
A tiny package to convenience work with YouTube media resources. Allow to extract ID from resource URL and build valid resource URLs.
Installation
Install package to your project with Composer:
$ composer require lapalabs/youtube-helper dev-master
Usage
Creation
You can easily create valid YouTube resource object:
use LapaLabs\YoutubeExtractor\Resource\YoutubeResource; // Build resource object from valid YouTube resource ID $resource = new YoutubeResource('5qanlirrRWs'); // or with static method $resource = YoutubeResource::create('5qanlirrRWs'); // or create from valid YouTube resource URL $resource = YoutubeResource::createFromUrl('https://www.youtube.com/watch?v=5qanlirrRWs');
There are a few valid YouTube resource URLs, supported by this library,
that should be used in YoutubeResource::createFromUrl() method:
https://youtube.com/watch?v=5qanlirrRWshttps://m.youtube.com/watch?v=5qanlirrRWshttps://www.youtube.com/watch?v=5qanlirrRWshttps://www.youtube.com/embed/5qanlirrRWshttps://youtu.be/5qanlirrRWs
Advanced usage
After resource was successfully created you get access to a bunch of useful methods:
$resource->getId(); // 5qanlirrRWs $resource->buildEmbedUrl(); // https://www.youtube.com/embed/5qanlirrRWs // other useful methods to build various valid URLs $resource->buildUrl(); // shortcut alias for buildDefaultUrl $resource->buildDefaultUrl(); // https://www.youtube.com/watch?v=5qanlirrRWs $resource->buildAliasUrl(); // https://youtube.com/watch?v=5qanlirrRWs $resource->buildMobileUrl(); // https://m.youtube.com/watch?v=5qanlirrRWs $resource->buildShortUrl(); // https://youtu.be/5qanlirrRWs
You can get array of valid YouTube resource URLs which could used in createFromUrl method:
YoutubeResource::getValidHosts(); // array of valid YouTube resource URLs
To check whether YouTube resource ID or host is valid use follow methods:
YoutubeResource::isValidId('5qanlirrRWs'); // return true if ID is valid YoutubeResource::isValidHost('youtu.be'); // return true if host is valid
You can easily get HTML code to embed YouTube resource on your page:
$resource->buildEmbedCode(); // with default attributes returns: <iframe width="560" height="315" src="https://www.youtube.com/embed/5qanlirrRWs" frameborder="0" allowfullscreen></iframe> // to pass any other parameters or override defaults with your own use: $resource->buildEmbedCode([ 'width' => 800, // override default 560 'height' => 600, // override default 315 'class' => 'video', // add new attribute ]);
The passed attributes to
buildEmbedCode()methods applies for current embed HTML code only. To change default attributes globally for specific resource you should pass an array of attributes tosetAttributes()method. To get current default HTML attributes of specific resource usegetAttributes()method.
There are a few attributes by default:
[
'width' => 560,
'height' => 315,
'src' => '', // hold position for specific order
'frameborder' => 0,
'allowfullscreen' => null,
];
NOTE: The
srcattribute is only required for building embed HTML code and will be injected automatically by callingbuildEmbedUrl()method behind the scenes. So every givensrcvalue tobuildEmbedCode()orsetAttributes()will be ignoring and replacing with correct URL for current resource. You could give it like in example above to point its position in HTML code.
Links
Feel free to create an Issue or Pull Request if you find a bug or just want to propose improvement suggestion.
lapalabs/youtube-helper 适用场景与选型建议
lapalabs/youtube-helper 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 89 次下载、GitHub Stars 达 0, 最近一次更新时间为 2015 年 07 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「youtube」 「lapalabs」 「url builder」 「embed resource」 「id extractor」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 lapalabs/youtube-helper 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 lapalabs/youtube-helper 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 lapalabs/youtube-helper 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Easy to use SDK with grabber for multiple platforms at once like YouTube, Dailymotion, Facebook and more.
Easy URL rewrites in your Laravel application
♺ Laravel Nova Hashids card. Convert your ids.
A Laravel helper to detect if the current route/path is active.
Provides a service and twig extension for getting short urls like http://your.host/~short
SURL - Laravel Short Url
统计信息
- 总下载量: 89
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 17
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-07-07