Giter VIP home page Giter VIP logo

php-video-url-parser's Introduction

DEPRECATED !

If you have PHP 7.4 or newer then please use https://github.com/ricardofiorani/oembed instead.
This lib will receive only small bugfixes, not new features anymore.

PHP Video URL Parser

Build Status Minimum PHP Version License Total Downloads Coding Standards Scrutinizer Code Quality Code Coverage

PHP Video URL Parser is a parser that detects a given video url and returns an object containing information like the video's embed code, title, description, thumbnail and other information that the service's API may give.

Installation

Install the latest version with

$ composer require ricardofiorani/php-video-url-parser

Requirements

  • PHP 5.3
  • cURL (Or at least file_get_contents() enabled if you want to use it with Vimeo, otherwise it's not required)

Basic Usage

<?php
use RicardoFiorani\Matcher\VideoServiceMatcher;

require __DIR__ . '/vendor/autoload.php';

$vsm = new VideoServiceMatcher();

//Detects which service the url belongs to and returns the service's implementation
//of RicardoFiorani\Adapter\VideoAdapterInterface
$video = $vsm->parse('https://www.youtube.com/watch?v=PkOcm_XaWrw');

//Checks if service provides embeddable videos (most services does)
if ($video->isEmbeddable()) {
    //Will echo the embed html element with the size 200x200
    echo $video->getEmbedCode(200, 200);

    //Returns the embed html element with the size 1920x1080 and autoplay enabled
    echo $video->getEmbedCode(1920, 1080, true);
    
    //Returns the embed html element with the size 1920x1080, autoplay enabled and force the URL schema to be https.
    echo $video->getEmbedCode(1920, 1080, true, true);
}

//If you don't want to check if service provides embeddable videos you can try/catch
try {
    echo $video->getEmbedUrl();
} catch (\RicardoFiorani\Exception\NotEmbeddableException $e) {
    die(sprintf("The URL %s service does not provide embeddable videos.", $video->getRawUrl()));
}

//Gets URL of the smallest thumbnail size available
echo $video->getSmallThumbnail();

//Gets URL of the largest thumbnail size available
//Note some services (such as Youtube) does not provide the largest thumbnail for some low quality videos (like the one used in this example)
echo $video->getLargestThumbnail();

Registering your own service video (it's easy !)

If you want to register an implementation of some service your class just needs to implement the "RicardoFiorani\Adapter\VideoAdapterInterface" or extend the RicardoFiorani\Adapter\AbstractServiceAdapter

A Fully functional example can be found Here.

PS: If you've made your awesome implementation of some well known service, feel free to send a Pull Request. All contributions are welcome :)

Using your own framework's template engine

A Fully functional example can be found Here.

Currently Suported Services

  • Youtube
  • Vimeo
  • Dailymotion
  • Facebook Videos

Currently Supported PHP Versions

  • PHP 5.3
  • PHP 5.4
  • PHP 5.5
  • PHP 5.6
  • PHP 7.0
  • PHP 7.1
  • PHP 7.2

Please note that lib is not passing tests on HHVM, therefore, we can't guarantee it will work properly. Please use it on your own risk.

php-video-url-parser's People

Contributors

bitdeli-chef avatar ricardofiorani avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

php-video-url-parser's Issues

Start time in the URL is ignored

In youtube, we can specify the start time using the parameter ?t=3m2s (3 minute, 2 seconds). This is ignored when parsing. Is there a way to add support to the start time parameter?

Add PSR-7 support

I have an instance of Psr\Http\Message\UriInterface in my hand, it would be classy to make parser() accept this class as argument as-is. The following code doesn't work:

$vsm->parse(new Zend\Diactoros\Uri('https://www.youtube.com/watch?v=PkOcm_XaWrw'));

I'm able to make a PR if you give me a green light

Additional Vimeo URL format

Hey,

I found out, that Vimeo also supports URLs in this format:
https://vimeo.com/256764179/d2cf1613f7

I can't exactly tell what the last url-part stands for, but it's possible to embed this video without the last url-part:

<iframe src="https://player.vimeo.com/video/256764179?color=ffffff&title=0&byline=0" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
<script src="https://player.vimeo.com/api/player.js"></script>

If I parse the URL with your parser, the file_get_contents to the vimeo api fails.

Do you have any ideas on how to support this type of Vimeo URLs?

Implement PSR-18

Story

When we made the VimeoAdapter we used file_get_contents() which requires cURL directly.
Ideally we would depend on a package like Guzzle or something like, but since the PSR-18 is in transit to approval, would be the best for everyone to add PSR-18 support.

To-Do

Make the VimeoAdapter to work with the PSR-18 HTTP Client interface.

Title / Description?

I see in the readme that the parser can obtain titles and descriptions, however I don't see anything related to this in the code? How can this be achieved?

Add guzzle support

Within the DailymotionAdapter, we use a file_get_contents which is not ideal to use.
We need to add support to make the requests through guzzle instead.

Fix Scrutinizer coverage

Apparently the tests are not being executed on PHP 7+ which is causing Scrutinizer to think there is no test coverage.

Create integration tests

Story

We don't have any automated test that certifies that the integration is working.

To-Do

Create integration tests (can use guzzle to check if the thumbnails URLs gives a non 404 response).

Add cache support

Today, in VideoServiceMatcher::parse() we have a logic that saves in an array URLs that were already parsed, however it persists within the same request only.
We need to add cache support to save the already parsed.

It must be implemented following PSR-6.

Rebuild it all on top of oEmbed

Story

Now that there is oEmbed and packages like https://github.com/oscarotero/Embed, we could build this on top of it.

Todo

Rebuild it all to work with oEmbed.
For services like Youtube where we can "guess" some data, we can add some lazy-load strategy that only makes the request to the oEmbed endpoint if some data that we can't guess is requested.

Important functionalities to keep

The user must be able to specify the size of the embed that they want.
For this we can use some DomDocument parsing to "update" the attributes of the embed code provided by the service's oEmbed API endpoint.

getEmbedUrl should return secure url (optionnaly ?)

Hi !
As the web migrates more and more to the HTTPS everywhere, it should be interesting to offer the user the choice to get an https embed when calling getEmbedUrl()
Maybe by forcing it, or simply adding a $secure = false var in the function call.
The main problem here is when you want to display an http only embed on a https url, the video is just blocked by the browser. And that's a problem, isn'it ? ๐Ÿ˜†

edit: the same goes for the getLargestThumbnail(), I guess

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.