承接 lapalabs/youtube-helper 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

lapalabs/youtube-helper

最新稳定版本:v0.1.0

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

统计信息

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

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固