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
339 stars 59 forks source link

The New YouTube Desktop Design is not Supported. #52

Closed dipo1 closed 5 years ago

dipo1 commented 7 years ago

YouTube Just rolled out a new desktop design which is not supported by the Embera Library.

I am currently using the below code the get the Title, Description and Embed Code pending the time the issue is resolved

<?php
    $link = isset($_GET['link']) ? $_GET['link'] : 'https://www.youtube.com/watch?v=myEv3Qr3Efo';
    $link_details = parse_url($link);
    $scheme = isset($link_details['scheme']) ? $link_details['scheme'].'://' : '';
    $host = isset($link_details['host']) ? $link_details['host'] : '';
    $query = isset($link_details['query']) ? $link_details['query'] : '';
    $id = '';
    if(preg_match('/youtube\.com$/i', $host)) {
        parse_str($query, $params);
        $id = isset($params['v']) ? $params['v'] : $id;
    } elseif(preg_match('/youtu\.be$/i', $host)) {
        $link = preg_replace('/www\.youtu\.be$/i', 'youtu.be', $link);
        $host = 'www.youtube.com';
        $id = trim($path, '/');
    }
    $url = $scheme.$host.'/embed/'.$id;
    $code = '<iframe frameborder="0" src="'.$url.'" allowfullscreen=""></iframe>';
    $title = '';
    $description = '';
    if(ini_get('allow_url_fopen')) {
        $source = file_get_contents($link);
        $source = mb_convert_encoding($source, 'utf-8', mb_detect_encoding($source));
        $source = mb_convert_encoding($source, 'html-entities', 'utf-8');
        $doc = new DOMDocument();
        @$doc->loadHTML($source);
        $nodes = $doc->getElementsByTagName('title');
        $title = $nodes->item(0)->nodeValue;
        $metas = $doc->getElementsByTagName('meta');
        $x = 0;
        for ($i = 0; $i < $metas->length; $i++) {
            $meta = $metas->item($i);
            if($meta->getAttribute('name') == 'description') {
                $description = $meta->getAttribute('content');
                break;
            }
        }
    }
    header('Content-Type: text/plain');
    print("CODE:\n");
    print($code."\n");
    print("\nTITLE:\n");
    print($title."\n");
    print("\nDESCRIPTION:\n");
    print($description);
    exit;

Regards.

maietta commented 6 years ago

The best way to contribute changes is to fork the code, make the changes, then do a pull request. This can all be done easily from within Github's web interface.