• Youtube ID no dziesmas nosaukuma

    $homepage = file_get_contents('https://gdata.youtube.com/feeds/api/videos?q='.urlencode($dz_izpilditajs).'%20-%20'.urlencode($dz_nosaukums).'&orderby=relevance&start-index=1&max-results=1&v=2&alt=json');
    $ytraw=json_decode($homepage, true);
    $here = explode(":", $ytraw['feed']['entry'][0]['id']['$t']);
    $num = (count($here) - 1);
    $yt = $here[$num];

    Vairāk info šeit:
    https://developers.google.com/youtube/2.0/developers_guide_protocol_api_query_parameters?hl=cs


  • PHP Preg_match lai izvilktu pirmo youtube linku no teksta

    preg_match('#(?:http://)?(?:www\.)?(?:youtube\.com/(?:embed/|v/|watch\?v=)|youtu\.be/)([\w-]+)(?:\S+)?#', $string, $match);


  • Youtube thumbnail no video identifikatora

    $url="http://www.youtube.com/watch?v=mHifGmeToVU";
    parse_str(parse_url($url,PHP_URL_QUERY),$my_array);
    echo $my_array['v'];
    echo "<img alt="" src="http://img.youtube.com/vi/&quot;.$my_array[" />";

    VAI
    function youtube_id_from_url($url) {
    $pattern =
    '%^# Match any youtube URL
    (?:https?://)? # Optional scheme. Either http or https
    (?:www\.)? # Optional www subdomain
    (?: # Group host alternatives
    youtu\.be/ # Either youtu.be,
    | youtube\.com # or youtube.com
    (?: # Group path alternatives
    /embed/ # Either /embed/
    | /v/ # or /v/
    | /watch\?v= # or /watch\?v=
    ) # End path alternatives.
    ) # End host alternatives.
    ([\w-]{10,12}) # Allow 10-12 for 11 char youtube id.
    $%x'
    ;
    $result = preg_match($pattern, $url, $matches);
    if (false !== $result) {
    return $matches[1];
    }
    return false;
    }

    echo youtube_id_from_url(‘http://youtu.be/NLqAF9hrVbY’); # NLqAF9hrVbY

    http://img.youtube.com/vi//0.jpg
    http://img.youtube.com/vi//1.jpg
    http://img.youtube.com/vi//2.jpg
    http://img.youtube.com/vi//3.jpg

    http://img.youtube.com/vi//default.jpg

    http://img.youtube.com/vi//hqdefault.jpg

    http://img.youtube.com/vi//mqdefault.jpg

    http://img.youtube.com/vi//sddefault.jpg

    http://img.youtube.com/vi//maxresdefault.jpg