aboutsummaryrefslogtreecommitdiff
path: root/lib/videolist.php
blob: bb114b29882e8dcdd39909eede6f63a7e1abe036 (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<?php

function videolist_parseurl_youtube($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'],
	);
}

function videolist_parseurl_vimeo($url) {
	$parsed = parse_url($url);
	$path = explode('/', $parsed['path']);
	
	if ($parsed['host'] != 'vimeo.com' || !(int) $path[1]) {
		return false;
	}

	return array(
		'videotype' => 'vimeo',
		'video_id' => $path[1],
	);
}

function videolist_parseurl_metacafe($url) {
	$parsed = parse_url($url);
	$path = explode('/', $parsed['path']);

	if ($parsed['host'] != 'www.metacafe.com' || $path[1] != 'watch' || !(int) $path[2]) {
		return false;
	}
	
	return array(
		'videotype' => 'metacafe',
		'video_id' => $path[2],
	);
}

function videolist_parseurl_bliptv($url) {
	$parsed = parse_url($url);
	$path = explode('/', $parsed['path']);

	if ($parsed['host'] != 'blip.tv' || count($path) < 3) {
		return false;
	}
	
	return array(
		'videotype' => 'bliptv',
		'video_id' => $parsed['path'],
	);
}

function videolist_parseurl_gisstv($url) {
	$parsed = parse_url($url);
	$path = explode('/', $parsed['path']);

	if ($parsed['host'] != 'giss.tv' || $path[1] != 'dmmdb') {
		return false;
	}
	
	if($path[2] == 'contents' && isset($path[3])) {
		$video_id = $path[3];
	} elseif($path[3] == 'contents' && isset($path[4])) {
		$video_id = $path[4];
	} else {
		return false;
	}
	
	return array(
		'videotype' => 'gisstv',
		'video_id' => $video_id,
	);
}

function videolist_parseurl($url){
	if ($parsed = videolist_parseurl_youtube($url)) return $parsed;
	elseif ($parsed = videolist_parseurl_vimeo($url)) return $parsed;
	elseif ($parsed = videolist_parseurl_metacafe($url)) return $parsed;
	elseif ($parsed = videolist_parseurl_bliptv($url)) return $parsed;
	elseif ($parsed = videolist_parseurl_gisstv($url)) return $parsed;
	else return array();
}

function videolist_get_data($video_parsed_url) {
	$videotype = $video_parsed_url['videotype'];
	$video_id = $video_parsed_url['video_id'];
	switch($videotype){
		case 'youtube': return videolist_get_data_youtube($video_id);
		case 'vimeo': return videolist_get_data_vimeo($video_id);
		case 'metacafe': return videolist_get_data_metacafe($video_id);
		case 'bliptv': return videolist_get_data_bliptv($video_id);
		case 'gisstv': return videolist_get_data_gisstv($video_id);
		default: return array();
	}
}


function videolist_get_data_youtube($video_id){
	$buffer = file_get_contents('http://gdata.youtube.com/feeds/api/videos/'.$video_id);
	$xml = new SimpleXMLElement($buffer);
	
	return array(
		'title' => sanitize_string($xml->title),
		'description' => sanitize_string($xml->content),
		'thumbnail' => "http://img.youtube.com/vi/$video_id/default.jpg",
		'video_id' => $video_id,
		'videotype' => 'youtube',
	);
}

function videolist_get_data_vimeo($video_id){
	$buffer = file_get_contents("http://vimeo.com/api/v2/video/$video_id.xml");
	$xml = new SimpleXMLElement($buffer);
	
	$videos = $xml->children();
	$video = $videos[0];
	
	return array(
		'title' => sanitize_string($video->title),
		'description' => sanitize_string($video->description),
		'thumbnail' => sanitize_string($video->thumbnail_medium),
		'video_id' => $video_id,
		'videotype' => 'vimeo',
	);
}

function videolist_get_data_metacafe($video_id){ //FIXME
	$buffer = file_get_contents("http://www.metacafe.com/api/item/$video_id");
	$xml = new SimpleXMLElement($buffer);
	
	return array(
		'title' => current($xml->xpath('/rss/channel/item/title')),
		'description' => current($xml->xpath('/rss/channel/item/description')),
		'thumbnail' => current($xml->xpath('/rss/channel/item/media:thumbnail/@url')),
		'embedurl' => current($xml->xpath('/rss/channel/item/media:content/@url')),
		'video_id' => $video_id,
		'videotype' => 'metacafe',
	);
}

function videolist_get_data_bliptv($video_id){
	$buffer = file_get_contents('http://blip.tv'.$video_id.'?skin=rss');
	$xml = new SimpleXMLElement($buffer);
	
	return array(
		'title' => current($xml->xpath('/rss/channel/item/title')),
		'description' => current($xml->xpath('/rss/channel/item/description')),
		'thumbnail' => current($xml->xpath('/rss/channel/item/media:thumbnail/@url')),
		'embedurl' => current($xml->xpath('/rss/channel/item/blip:embedUrl')),
		'video_id' => $video_id,
		'videotype' => 'bliptv',
	);
}

function videolist_get_data_gisstv($video_id){
	$buffer = file_get_contents('http://giss.tv/dmmdb//rss.php');
	$xml = new SimpleXMLElement($buffer);
	
	$data = array();
	foreach($xml->xpath('/rss/channel/item') as $item){
		if(sanitize_string($item->link) == 'http://giss.tv/dmmdb//contents/'.$video_id) {
			$data['title'] = sanitize_string($item->title);
			$data['description'] = sanitize_string($item->description);
			$data['thumbnail'] = sanitize_string($item->thumbnail);
			break;
		}
	}
	return array_merge($data, array(
		'video_id' => $video_id,
		'videotype' => 'gisstv',
	));
}