/
var
/
www
/
vhosts
/
ihelp.ro
/
httpdocs
/
vendor
/
mirko-pagliai
/
me-tools
/
src
/
Utility
/
/var/www/vhosts/ihelp.ro/httpdocs/vendor/mirko-pagliai/me-tools/src/Utility
mkdir
upload
Name
Size
Mode
Actions
BBCode.php
4428
0644
edit
dl
rm
Youtube.php
1730
0644
edit
dl
rm
Edit:
/var/www/vhosts/ihelp.ro/httpdocs/vendor/mirko-pagliai/me-tools/src/Utility/Youtube.php
(1730B)
<?php declare(strict_types=1); /** * This file is part of me-tools. * * Licensed under The MIT License * For full copyright and license information, please see the LICENSE.txt * Redistributions of files must retain the above copyright notice. * * @copyright Copyright (c) Mirko Pagliai * @link https://github.com/mirko-pagliai/me-tools * @license https://opensource.org/licenses/mit-license.php MIT License */ namespace MeTools\Utility; /** * A utility to get information about YouTube videos */ class Youtube { /** * Parses a YouTube url and returns the YouTube ID * @param string $url Video url * @return string|null Youtube ID or `null` on failure */ public static function getId(string $url): ?string { if (str_contains($url, 'youtube.com')) { $url = parse_url($url) ?: []; if (!isset($url['query'])) { return null; } parse_str($url['query'], $url); return isset($url['v']) && is_string($url['v']) ? $url['v'] : null; } if (preg_match('/youtu\.be\/([^?]+)/', $url, $matches)) { return $matches[1]; } return null; } /** * Gets the preview for a video * @param string $id YouTube ID or url * @return string */ public static function getPreview(string $id): string { return sprintf('https://img.youtube.com/vi/%s/0.jpg', is_url($id) ? self::getId($id) : $id); } /** * Gets the url for a video * @param string $id YouTube ID * @return string */ public static function getUrl(string $id): string { return sprintf('https://youtu.be/%s', $id); } }
Save
cmd:
run