mpratt / Embera

A Oembed consumer library, that gives you information about urls. It helps you replace urls to youtube or vimeo for example, with their html embed code. It has advanced features like offline support, responsive embeds and caching support.
MIT License
333 stars 59 forks source link

New Dailymotion url support #18

Closed DoyleCC closed 9 years ago

DoyleCC commented 9 years ago

Hi, it seems only the old Dailymotion url types (dailymotion.com/username/video/id) are embedded. The new url's (dailymotion.com/video/id_title) aren't recognized.

I changed the validateUrl regex to ~dailymotion\.com/(?:[^/]*)/?video/(?:[^/]+)/?~i That got it working for both url types. Maybe you could have a look at this issue before the next release.

Thanks!

mpratt commented 9 years ago

Hi DoyleCC,

Thanks for reporting but I cant replicate the issue. It seems to be working just fine for me:

$embera = new Embera\Embera();
print_r($embera->getUrlInfo('http://www.dailymotion.com/video/x2fm26p_magic-flip-book_tech http://www.dailymotion.com/video/xzva95_jacob-jones-and-the-bigfoot-mystery-launch-trailer_videogames'));

Array
(
    [http://www.dailymotion.com/video/x2fm26p_magic-flip-book_tech] => Array
        (
            [embera_using_fake] => 0
            [type] => video
            [version] => 1.0
            [provider_name] => Dailymotion
            [provider_url] => http://www.dailymotion.com
            [title] => Magic Flip Book
            [author_name] => Grand Illusions
            [author_url] => http://www.dailymotion.com/grand-illusions
            [width] => 480
            [height] => 269
            [html] => <iframe src="http://www.dailymotion.com/embed/video/x2fm26p" width="480" height="269" frameborder="0" allowfullscreen></iframe>
            [thumbnail_url] => http://s1.dmcdn.net/Is5bU/x240-n0j.jpg
            [thumbnail_width] => 427
            [thumbnail_height] => 240
        )

    [http://www.dailymotion.com/video/xzva95_jacob-jones-and-the-bigfoot-mystery-launch-trailer_videogames] => Array
        (
            [embera_using_fake] => 0
            [type] => video
            [version] => 1.0
            [provider_name] => Dailymotion
            [provider_url] => http://www.dailymotion.com
            [title] => Jacob Jones and the Bigfoot Mystery - Launch trailer
            [author_name] => TheVaultvideojuegos
            [author_url] => http://www.dailymotion.com/TheVaultvideojuegos
            [width] => 480
            [height] => 269
            [html] => <iframe src="http://www.dailymotion.com/embed/video/xzva95" width="480" height="269" frameborder="0" allowfullscreen></iframe>
            [thumbnail_url] => http://s1.dmcdn.net/BeIXa/x240-GcR.jpg
            [thumbnail_width] => 427
            [thumbnail_height] => 240
        )

)

or

$embera = new Embera\Embera();
echo $embera->autoEmbed('http://www.dailymotion.com/video/x2fm26p_magic-flip-book_tech http://www.dailymotion.com/video/xzva95_jacob-jones-and-the-bigfoot-mystery-launch-trailer_videogames');

<iframe src="http://www.dailymotion.com/embed/video/x2fm26p" width="480" height="269" frameborder="0" allowfullscreen></iframe> <iframe src="http://www.dailymotion.com/embed/video/xzva95" width="480" height="269" frameborder="0" allowfullscreen></iframe>

Can you give me an example of a url that's not working for you?

DoyleCC commented 9 years ago

Sorry, it was my mistake. My site has also still Dailymotion videos embedded from years ago, so I have links with the old and the new url's. When I updated to 1.8.5 I had forgotten that I changed the regex in earlier versions to embed the old url's too.

Sorry again for bothering you.

mpratt commented 9 years ago

No problem DoyleCC!

If I may, let me suggest another approach to your problem. Instead of overwriting the core class, just write a new Oembed provider.

You want to convert the older urls dailymotion.com/username/video/id to something like dailymotion.com/video/id_title

// Create a new class that extends the DailyMotion Provider
class CustomDailyMotion extends \Embera\Providers\DailyMotion
{
    /** inline {@inheritdoc} */
    protected function normalizeUrl()
    {
        parent::normalizeUrl();

        // Support for older dailymotion links
        if (preg_match('~dailymotion\.com/(?:[^/]+)/video/([^/]+)/?~i', $this->url, $matches)) {
            $this->url = new \Embera\Url('http://www.dailymotion.com/video/' . $matches['1']);
        }
    }
}

$embera = new Embera\Embera();

// Register the new class to 
$embera->addProvider('dailymotion.com', 'CustomDailyMotion');
$embera->addProvider('*.dailymotion.com', 'CustomDailyMotion');
print_r($embera->getUrlInfo(array(
    'http://www.dailymotion.com/video/x2fm26p_magic-flip-book_tech', 
     // Normal url
    'http://www.dailymotion.com/username/video/x2fm26p', 
     // will be converted to http://www.dailymotion.com/video/x2fm26p
    'http://www.dailymotion.com/other_user_name_old_links/video/x2fm26p_magic-flip-book_tech', 
     // will be converted to http://www.dailymotion.com/video/x2fm26p_magic-flip-book_tech
)));

By converting the links, you get a compatible url with the new format. Embera takes care of the rest. You don't need to modify the core class, so you don't have to think about doing changes right after updating.

Note that I'm registering the CustomClass to dailymotion.com and to *.dailymotion.com. I did that because I visited the website again and found out that dailymotion has support for http://games.dailymotion.com and to live streaming.

I changed the DailyMotion class in order to support those changes and I'll be pushing an update this weekend.

Im closing this issue for now!