Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

add SoundCloud #9

Merged
merged 1 commit into from

2 participants

@JLepeltier

No description provided.

Jerome Lepeltier Add SoundCloud player 0537594
@GromNaN GromNaN merged commit 3ea9c08 into GromNaN:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 22, 2012
  1. Add SoundCloud player

    Jerome Lepeltier authored
This page is out of date. Refresh to see the latest.
View
1  README.md
@@ -13,6 +13,7 @@ a supported URL and extract the video ID.
* [Dailymotion](http://www.dailymotion.com/)
* [Vimeo](http://www.vimeo.com/)
* [Spotify](http://www.spotify.com/)
+* [SoundCloud](http://soundcloud.com/)
* ... more to come
Installation
View
3  demo.php
@@ -29,5 +29,8 @@
<h1>Spotify</h1>
<?php echo $t->parse('https://embed.spotify.com/?uri=spotify:track:4bz7uB4edifWKJXSDxwHcs')->render() ?>
+ <h1>SoundCloud</h1>
+ <?php echo $t->parse('http://player.soundcloud.com/player.swf?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F17373708')->render() ?>
+
</body>
</html>
View
4 src/TubeLink/Service/Dailymotion.php 100755 → 100644
@@ -20,7 +20,9 @@ class Dailymotion implements ServiceInterface
public function parse($url)
{
$data = parse_url($url);
-
+ if (empty($data['host'])) {
+ return false;
+ }
if (false !== strpos($data['host'], 'dailymotion.com')
&& preg_match('#^(/embed)?/video/([0-9a-z]+)(_[-_\w]+)?$#', $data['path'], $matches)
) {
View
59 src/TubeLink/Service/SoundCloud.php
@@ -0,0 +1,59 @@
+<?php
+/*
+ * This file is part of the TubeLink package.
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ *
+ * @licence MIT
+ */
+
+namespace TubeLink\Service;
+
+use TubeLink\Tube;
+
+class SoundCloud implements ServiceInterface
+{
+ /**
+ * {@inheritDoc}
+ */
+ public function parse($url)
+ {
+ $data = parse_url($url);
+ if (empty($data['host'])) {
+ return false;
+ }
+ if (false !== strpos($data['host'], 'soundcloud.com') && isset($data['query'])) {
+ $queryFields = array();
+ parse_str($data['query'], $queryFields);
+ if (isset($queryFields['url']) && preg_match('#http://api.soundcloud.com/([^&]*)#', $queryFields['url'], $matches)) {
+ $id = $matches[1];
+ } else {
+ return false;
+ }
+ } else {
+ return false;
+ }
+
+ $tube = new Tube($this);
+ $tube->id = $id;
+
+ return $tube;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function generateEmbedUrl(Tube $video)
+ {
+ return 'http://player.soundcloud.com/player.swf?url=http%3A%2F%2Fapi.soundcloud.com%2F'.urlencode($video->id);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public function getName()
+ {
+ return 'soundcloud';
+ }
+}
View
4 src/TubeLink/Service/Spotify.php 100755 → 100644
@@ -20,7 +20,9 @@ class Spotify implements ServiceInterface
public function parse($url)
{
$data = parse_url($url);
-
+ if (empty($data['host'])) {
+ return false;
+ }
if (false !== strpos($data['host'], 'embed.spotify.com')
&& isset($data['query'])
&& preg_match('#^uri=spotify:([0-9a-zA-Z:]+)$#', $data['query'], $matches)) {
View
4 src/TubeLink/Service/Vimeo.php
@@ -20,7 +20,9 @@ class Vimeo implements ServiceInterface
public function parse($url)
{
$data = parse_url($url);
-
+ if (empty($data['host'])) {
+ return false;
+ }
if (false !== strpos($data['host'], 'vimeo.com')
&& preg_match('#^/(video/)?([0-9]+)?$#', $data['path'], $matches)
) {
View
13 src/TubeLink/Service/Youtube.php 100755 → 100644
@@ -20,15 +20,16 @@ class Youtube implements ServiceInterface
public function parse($url)
{
$data = parse_url($url);
+
+ if (empty($data['host'])) {
+ return false;
+ }
+
$query = array();
if (isset($data['query'])) {
parse_str($data['query'], $query);
}
- if (!isset($data['host'])) {
- return false;
- }
-
if (false !== strpos($data['host'], 'youtube.')
&& in_array($data['path'], array('/watch', '/all_comments'))
&& isset($query['v'])
@@ -47,6 +48,10 @@ public function parse($url)
&& preg_match('{^/v/([\w-]{11})}', $data['path'], $matches)
) {
$id = $matches[1];
+ } elseif (false != preg_match('/^www\.youtube(-nocookie)?\.com$/',$data['host'])
+ && preg_match('{^/p/([\w-]{16})}', $data['path'], $matches)
+ ) {
+ $id = $matches[1];
} else {
return false;
}
View
43 src/TubeLink/Tests/Service/SoundCloudTest.php
@@ -0,0 +1,43 @@
+<?php
+/*
+ * This file is part of the TubeLink package.
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ *
+ * @licence MIT
+ */
+
+namespace TubeLink\Tests\Service;
+
+use TubeLink\Service\SoundCloud;
+
+class SoundCloudTest extends ServiceTestCase
+{
+ public function dataForTestParse()
+ {
+ return array(
+ array('http://w.soundcloud.com/player/?url=http%3A%2F%2Fapi.soundcloud.com%2Fplaylists%2F1482008&show_artwork=true', 'playlists/1482008'),
+ array('https://player.soundcloud.com/player.swf?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F17373708', 'tracks/17373708'),
+ );
+ }
+
+ public function dataForTestParseFalse()
+ {
+ return array(
+ array('http://player.soundcloud.com/player.swf?url=http%3A%2F%2Fapi.soundcloud.com'),
+ );
+ }
+
+ public function dataForTestGenerateEmbedUrl()
+ {
+ return array(
+ array('tracks/17373708', 'http://player.soundcloud.com/player.swf?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F17373708'),
+ );
+ }
+
+ protected function getService()
+ {
+ return new SoundCloud();
+ }
+}
View
1  src/TubeLink/Tests/Service/YoutubeTest.php 100755 → 100644
@@ -30,6 +30,7 @@ public function dataForTestParse()
array('http://www.youtube-nocookie.com/embed/P-8llsSbVDc?rel=0', 'P-8llsSbVDc'),
array('http://www.youtube.com/v/uPgLxYUHRcg?fs=1&hl=fr_FR', 'uPgLxYUHRcg'),
array('http://www.youtube-nocookie.com/v/Kw_yO2utN0c?fs=1&hl=fr_FR', 'Kw_yO2utN0c'),
+ array('http://www.youtube.com/p/18DCC2CD9CCCCB91?hl=fr_FR&fs=1', '18DCC2CD9CCCCB91'),
);
}
View
0  src/TubeLink/Tube.php 100755 → 100644
File mode changed
View
1  src/TubeLink/TubeLink.php
@@ -63,6 +63,7 @@ static public function create()
$t->registerService(new Service\Dailymotion());
$t->registerService(new Service\Vimeo());
$t->registerService(new Service\Spotify());
+ $t->registerService(new Service\SoundCloud());
return $t;
}
Something went wrong with that request. Please try again.