aboutsummaryrefslogtreecommitdiff
path: root/lib/Videolist/Platform/Youtube.php
blob: 41c7d1252a2bdc391b7b0382e9509a14648ca278 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php

class Videolist_Platform_Youtube implements Videolist_PlatformInterface
{
    public function getType()
    {
        return "youtube";
    }

    public function parseUrl($url)
    {
        $parsed = parse_url($url);
        parse_str($parsed['query'], $query);

        if ($parsed['host'] != 'www.youtube.com' || $parsed['path'] != '/watch' || !isset($query['v'])) {
            return false;
        }

        return array(
            'videotype' => 'youtube',
            'video_id' => $query['v'],
        );
    }

    public function getData($parsed)
    {
        $video_id = $parsed['video_id'];

        $buffer = file_get_contents('http://gdata.youtube.com/feeds/api/videos/'.$video_id);
        $xml = new SimpleXMLElement($buffer);

        return array(
            'title' => $xml->title,
            'description' => strip_tags($xml->content),
            'thumbnail' => "http://img.youtube.com/vi/$video_id/default.jpg",
        );
    }
}