From e1fa9cfeb87115f027672aa0e65ca7c748b33a09 Mon Sep 17 00:00:00 2001 From: Matt Sias Date: Sun, 17 Mar 2024 14:24:48 -0500 Subject: [PATCH] Recognize live and shorts YouTube URLs (#230) --- lib/video_info/providers/youtube.rb | 2 +- spec/lib/video_info/providers/youtube_spec.rb | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/video_info/providers/youtube.rb b/lib/video_info/providers/youtube.rb index 14b7b5e2..d37fc404 100644 --- a/lib/video_info/providers/youtube.rb +++ b/lib/video_info/providers/youtube.rb @@ -54,7 +54,7 @@ def thumbnail_maxres private def _url_regex - %r{(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/| + %r{(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?|live|shorts)/| .*[?&]v=)|youtu\.be/)([^"&?/ ]{11})}x end diff --git a/spec/lib/video_info/providers/youtube_spec.rb b/spec/lib/video_info/providers/youtube_spec.rb index 4394d3bc..7122c8c4 100644 --- a/spec/lib/video_info/providers/youtube_spec.rb +++ b/spec/lib/video_info/providers/youtube_spec.rb @@ -17,6 +17,21 @@ it { is_expected.to be_truthy } end + context "with embed url" do + let(:url) { "https://www.youtube.com/embed/JM9NgvjjVng" } + it { is_expected.to be_truthy } + end + + context "with live url" do + let(:url) { "https://www.youtube.com/live/SMhkA07Fbfs" } + it { is_expected.to be_truthy } + end + + context "with shorts url" do + let(:url) { "https://youtube.com/shorts/MOcigdHkzhE" } + it { is_expected.to be_truthy } + end + context "with other url" do let(:url) { "http://google.com/video1" } it { is_expected.to be_falsey }