From cdfda3436aa96134797f6f1c45d76227770f1f4b Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 20 Nov 2022 21:48:59 +0100 Subject: Youtube: support @Channel and /user/UserName formats to launch youtube plugin for youtube channels --- src/plugins/Info.cpp | 5 ++++- src/plugins/Youtube.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/src/plugins/Info.cpp b/src/plugins/Info.cpp index ed63aae..1ad7320 100644 --- a/src/plugins/Info.cpp +++ b/src/plugins/Info.cpp @@ -15,7 +15,10 @@ namespace QuickMedia { } static bool is_youtube_channel_url(const std::string &url) { - return url.find("youtube.com/c/") != std::string::npos || url.find("youtu.be/c/") != std::string::npos || url.find("youtube.com/channel/") != std::string::npos || url.find("youtu.be/channel/") != std::string::npos; + return url.find("youtube.com/c/") != std::string::npos || url.find("youtu.be/c/") != std::string::npos + || url.find("youtube.com/channel/") != std::string::npos || url.find("youtu.be/channel/") != std::string::npos + || url.find("youtube.com/@") != std::string::npos || url.find("youtu.be/@") != std::string::npos + || url.find("youtube.com/user") != std::string::npos || url.find("youtu.be/user") != std::string::npos; } static PluginResult open_with_browser(const std::string &url) { diff --git a/src/plugins/Youtube.cpp b/src/plugins/Youtube.cpp index c6e8533..9b64054 100644 --- a/src/plugins/Youtube.cpp +++ b/src/plugins/Youtube.cpp @@ -136,6 +136,50 @@ namespace QuickMedia { return true; } + index = youtube_url.find("youtube.com/@"); + if(index != std::string::npos) { + index += 12; // 13 - 1, to include @ + size_t end_index = youtube_url.find("/", index); + if(end_index == std::string::npos) + end_index = youtube_url.size(); + channel_id = youtube_url.substr(index, end_index - index); + channel_url = "https://www.youtube.com/" + channel_id; + return true; + } + + index = youtube_url.find("youtu.be/@"); + if(index != std::string::npos) { + index += 9; // 10 - 1, to include @ + size_t end_index = youtube_url.find("/", index); + if(end_index == std::string::npos) + end_index = youtube_url.size(); + channel_id = youtube_url.substr(index, end_index - index); + channel_url = "https://www.youtube.com/" + channel_id; + return true; + } + + index = youtube_url.find("youtube.com/user/"); + if(index != std::string::npos) { + index += 17; + size_t end_index = youtube_url.find("/", index); + if(end_index == std::string::npos) + end_index = youtube_url.size(); + channel_id = youtube_url.substr(index, end_index - index); + channel_url = "https://www.youtube.com/user/" + channel_id; + return true; + } + + index = youtube_url.find("youtu.be/user/"); + if(index != std::string::npos) { + index += 14; + size_t end_index = youtube_url.find("/", index); + if(end_index == std::string::npos) + end_index = youtube_url.size(); + channel_id = youtube_url.substr(index, end_index - index); + channel_url = "https://www.youtube.com/user/" + channel_id; + return true; + } + return false; } -- cgit v1.2.3