Skip to content

Commit 9528d3d

Browse files
committed
Parse shortened YouTube URLs
1 parent 4c1e1bb commit 9528d3d

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## 2.0.3 - 2024-04-01
8+
### Added
9+
- Expand getYouTubeIdFromUrl to allow shortened YouTube URLs
10+
711
## 2.0.0 - 2022-09-07
812
### Added
913
- Updated for Craft 4

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Generate an embed URL from a YouTube or Vimeo URL.
44

55
## Requirements
66

7-
This plugin requires Craft CMS 4.0.0-beta or later.
7+
This plugin requires Craft CMS 4.0.0 or later.
88

99
## Installation
1010

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "viget/craft-video-embed",
33
"description": "Generate an embed URL from a YouTube or Vimeo URL",
44
"type": "craft-plugin",
5-
"version": "2.0.2",
5+
"version": "2.0.3",
66
"keywords": [
77
"craft",
88
"cms",
@@ -22,7 +22,7 @@
2222
}
2323
],
2424
"require": {
25-
"craftcms/cms": "^4.0.0-alpha"
25+
"craftcms/cms": "^4.0.0"
2626
},
2727
"autoload": {
2828
"psr-4": {

src/helpers/ParsingHelper.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,21 @@ public static function getYouTubeIdFromUrl(string $url): ?string
6060

6161
if ($query) {
6262
parse_str($query, $qs);
63-
return $qs['v'] ?? $qs['vi'] ?? null;
63+
if ($qs['v'] || $qs['vi']) {
64+
return $qs['v'] ?? $qs['vi'];
65+
}
6466
}
65-
66-
// Deals with https://youtu.be/X9tg3J5OiYU URLs
67+
68+
/**
69+
* Patterns:
70+
* - https://www.youtube.com/watch?v=--HXLM8GuxA
71+
* - https://youtu.be/--HXLM8GuxA?si=pNahKJLszKr8J00u
72+
*/
6773
if ($path) {
6874
$explodedPath = explode('/', trim($path, '/'));
6975
return $explodedPath[0] ?? null;
7076
}
71-
77+
7278
return null;
7379
}
7480

0 commit comments

Comments
 (0)