Support /live and /shorts for Youtube metadata lookups.
This commit is contained in:
parent
d1bab14435
commit
f2c25e2c6f
2 changed files with 31 additions and 18 deletions
24
composer.lock
generated
24
composer.lock
generated
|
@ -12,7 +12,7 @@
|
|||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://patchii.net/flash/index.git",
|
||||
"reference": "e31781c69f0b13fe251771c8e7e529222630a44f"
|
||||
"reference": "18397477d6734b4336c8b273f069cd8584173435"
|
||||
},
|
||||
"require": {
|
||||
"ext-mbstring": "*",
|
||||
|
@ -50,7 +50,7 @@
|
|||
],
|
||||
"description": "Composer package for the common library for my projects.",
|
||||
"homepage": "https://railgun.sh/index",
|
||||
"time": "2023-11-20T19:01:19+00:00"
|
||||
"time": "2024-01-04T02:07:43+00:00"
|
||||
},
|
||||
{
|
||||
"name": "flashwave/syokuhou",
|
||||
|
@ -58,7 +58,7 @@
|
|||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://patchii.net/flash/syokuhou.git",
|
||||
"reference": "fdf3c38cc216bf7024af331cbe1758532355c22f"
|
||||
"reference": "c1fe9371ada20fcea51c225cc53b9ceae4642bc4"
|
||||
},
|
||||
"require": {
|
||||
"flashwave/index": "dev-master",
|
||||
|
@ -89,7 +89,7 @@
|
|||
],
|
||||
"description": "Configuration library for PHP.",
|
||||
"homepage": "https://railgun.sh/syokuhou",
|
||||
"time": "2023-11-20T19:10:04+00:00"
|
||||
"time": "2024-01-04T02:12:49+00:00"
|
||||
},
|
||||
{
|
||||
"name": "guzzlehttp/psr7",
|
||||
|
@ -525,16 +525,16 @@
|
|||
},
|
||||
{
|
||||
"name": "sentry/sentry",
|
||||
"version": "4.1.0",
|
||||
"version": "4.3.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/getsentry/sentry-php.git",
|
||||
"reference": "89666f297891ff937fceb2f3d1fb967a6848cf37"
|
||||
"reference": "cd89f230bda0833cb9992ebe9a1b7d24d6ee245b"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/getsentry/sentry-php/zipball/89666f297891ff937fceb2f3d1fb967a6848cf37",
|
||||
"reference": "89666f297891ff937fceb2f3d1fb967a6848cf37",
|
||||
"url": "https://api.github.com/repos/getsentry/sentry-php/zipball/cd89f230bda0833cb9992ebe9a1b7d24d6ee245b",
|
||||
"reference": "cd89f230bda0833cb9992ebe9a1b7d24d6ee245b",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -558,7 +558,7 @@
|
|||
"phpbench/phpbench": "^1.0",
|
||||
"phpstan/phpstan": "^1.3",
|
||||
"phpunit/phpunit": "^8.5.14|^9.4",
|
||||
"symfony/phpunit-bridge": "^5.2|^6.0",
|
||||
"symfony/phpunit-bridge": "^5.2|^6.0|^7.0",
|
||||
"vimeo/psalm": "^4.17"
|
||||
},
|
||||
"suggest": {
|
||||
|
@ -598,7 +598,7 @@
|
|||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/getsentry/sentry-php/issues",
|
||||
"source": "https://github.com/getsentry/sentry-php/tree/4.1.0"
|
||||
"source": "https://github.com/getsentry/sentry-php/tree/4.3.1"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
|
@ -610,7 +610,7 @@
|
|||
"type": "custom"
|
||||
}
|
||||
],
|
||||
"time": "2023-12-04T12:41:21+00:00"
|
||||
"time": "2023-12-22T18:46:49+00:00"
|
||||
},
|
||||
{
|
||||
"name": "symfony/deprecation-contracts",
|
||||
|
@ -758,5 +758,5 @@
|
|||
"prefer-lowest": false,
|
||||
"platform": [],
|
||||
"platform-dev": [],
|
||||
"plugin-api-version": "2.3.0"
|
||||
"plugin-api-version": "2.6.0"
|
||||
}
|
||||
|
|
|
@ -11,6 +11,12 @@ final class YouTubeLookup implements \Uiharu\ILookup {
|
|||
'youtu.be', 'www.youtu.be', // www. doesn't work for this, but may as well cover it
|
||||
];
|
||||
|
||||
private const WATCH_PREFIXES = [
|
||||
'/watch/',
|
||||
'/live/',
|
||||
'/shorts/',
|
||||
];
|
||||
|
||||
private const VALID_TLDS = [
|
||||
'ae', 'at', 'az', 'ba', 'be', 'bg', 'bh', 'bo', 'by',
|
||||
'ca', 'cat', 'ch', 'cl', 'co', 'co.ae', 'co.at', 'co.cr', 'co.hu',
|
||||
|
@ -67,8 +73,14 @@ final class YouTubeLookup implements \Uiharu\ILookup {
|
|||
}
|
||||
|
||||
$urlPath = $url->getPath();
|
||||
return $urlPath === '/watch'
|
||||
|| str_starts_with($urlPath, '/watch/');
|
||||
if($urlPath === '/watch')
|
||||
return true;
|
||||
|
||||
foreach(self::WATCH_PREFIXES as $prefix)
|
||||
if(str_starts_with($urlPath, $prefix))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function lookupVideo(string $videoId): ?object {
|
||||
|
@ -99,11 +111,12 @@ final class YouTubeLookup implements \Uiharu\ILookup {
|
|||
|
||||
if(self::isShortDomain($url->getHost())) {
|
||||
$videoId = substr($urlPath, 1);
|
||||
} elseif(array_key_exists('v', $urlQuery)) {
|
||||
$videoId = $urlQuery['v'];
|
||||
} else {
|
||||
if(str_starts_with($urlPath, '/watch/'))
|
||||
$videoId = explode('/', trim($urlPath, '/'))[1] ?? '';
|
||||
else
|
||||
$videoId = $urlQuery['v'] ?? '';
|
||||
$urlPathParts = explode('/', trim($urlPath, '/'));
|
||||
if(count($urlPathParts) > 1)
|
||||
$videoId = $urlPathParts[1];
|
||||
}
|
||||
|
||||
if(empty($videoId))
|
||||
|
|
Loading…
Reference in a new issue