Spotify.php
| 1 | <?php |
| 2 | /** |
| 3 | * Spotify.php |
| 4 | * |
| 5 | * @package Embera |
| 6 | * @author Michael Pratt <yo@michael-pratt.com> |
| 7 | * @link http://www.michael-pratt.com/ |
| 8 | * |
| 9 | * For the full copyright and license information, please view the LICENSE |
| 10 | * file that was distributed with this source code. |
| 11 | */ |
| 12 | |
| 13 | namespace Embera\Provider; |
| 14 | |
| 15 | use Embera\Url; |
| 16 | |
| 17 | /** |
| 18 | * Spotify Provider |
| 19 | * En Spotify, puedes encontrar toda la música que necesitas. |
| 20 | * |
| 21 | * @link https://spotify.com |
| 22 | * @see https://developer.spotify.com/documentation/embeds/reference/oembed |
| 23 | * |
| 24 | */ |
| 25 | class Spotify extends ProviderAdapter implements ProviderInterface |
| 26 | { |
| 27 | /** inline {@inheritdoc} */ |
| 28 | protected $endpoint = 'https://open.spotify.com/oembed?format=json'; |
| 29 | |
| 30 | /** inline {@inheritdoc} */ |
| 31 | protected static $hosts = [ |
| 32 | 'open.spotify.com', |
| 33 | 'spotify.link' |
| 34 | ]; |
| 35 | |
| 36 | /** inline {@inheritdoc} */ |
| 37 | protected $httpsSupport = true; |
| 38 | |
| 39 | /** inline {@inheritdoc} */ |
| 40 | public function validateUrl(Url $url) |
| 41 | { |
| 42 | return (bool) ( |
| 43 | preg_match('~spotify\.com/(?:intl-[a-z]{2}/|)(?:track|album|playlist|show|episode|artist)/(?:[^/]+)(?:/[^/]*)?$~i', (string) $url) || |
| 44 | preg_match('~spotify\.com/user/(?:[^/]+)/playlist/(?:[^/]+)/?$~i', (string) $url) || |
| 45 | preg_match('~spotify\.link/(?:[^/]+)~i', (string) $url) |
| 46 | ); |
| 47 | } |
| 48 | |
| 49 | /** inline {@inheritdoc} */ |
| 50 | public function normalizeUrl(Url $url) |
| 51 | { |
| 52 | $url->convertToHttps(); |
| 53 | $url->removeQueryString(); |
| 54 | $url->removeLastSlash(); |
| 55 | |
| 56 | return $url; |
| 57 | } |
| 58 | |
| 59 | } |
| 60 |