定制 lapalabs/youtube-helper 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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.

SensioLabsInsight Build Status Scrutinizer Code Quality Code Coverage

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=5qanlirrRWs
  • https://m.youtube.com/watch?v=5qanlirrRWs
  • https://www.youtube.com/watch?v=5qanlirrRWs
  • https://www.youtube.com/embed/5qanlirrRWs
  • https://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 to setAttributes() method. To get current default HTML attributes of specific resource use getAttributes() method.

There are a few attributes by default:

[
    'width'           => 560,
    'height'          => 315,
    'src'             => '', // hold position for specific order
    'frameborder'     => 0,
    'allowfullscreen' => null,
];

NOTE: The src attribute is only required for building embed HTML code and will be injected automatically by calling buildEmbedUrl() method behind the scenes. So every given src value to buildEmbedCode() or setAttributes() 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.

Move UP

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 我们能提供哪些服务?
定制开发 / 二次开发

基于 lapalabs/youtube-helper 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 89
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 17
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-07-07