aboutsummaryrefslogtreecommitdiff
path: root/lib/Videolist/Platform
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Videolist/Platform')
-rw-r--r--lib/Videolist/Platform/Youtube.php30
1 files changed, 21 insertions, 9 deletions
diff --git a/lib/Videolist/Platform/Youtube.php b/lib/Videolist/Platform/Youtube.php
index 41c7d1252..648ac282c 100644
--- a/lib/Videolist/Platform/Youtube.php
+++ b/lib/Videolist/Platform/Youtube.php
@@ -10,16 +10,28 @@ class Videolist_Platform_Youtube implements Videolist_PlatformInterface
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;
+ $id = '';
+ if (! empty($parsed['host'])) {
+ if ($parsed['host'] === 'youtu.be') {
+ // short URLs
+ $id = substr($parsed['path'], 1);
+ } elseif ($parsed['host'] === 'www.youtube.com'
+ && $parsed['path'] === '/watch'
+ && ! empty($parsed['query'])) {
+ // long URLs
+ parse_str($parsed['query'], $query);
+ if (! empty($query['v'])) {
+ $id = $query['v'];
+ }
+ }
}
-
- return array(
- 'videotype' => 'youtube',
- 'video_id' => $query['v'],
- );
+ if ($id) {
+ return array(
+ 'videotype' => 'youtube',
+ 'video_id' => $id,
+ );
+ }
+ return false;
}
public function getData($parsed)