diff options
author | dec05eba <dec05eba@protonmail.com> | 2022-11-20 21:48:59 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2022-11-20 21:48:59 +0100 |
commit | cdfda3436aa96134797f6f1c45d76227770f1f4b (patch) | |
tree | a23f18349204f578fc9464104a846ad75235f530 /src | |
parent | de45f6d8d7d777244006a7998ec971157e51296e (diff) |
Youtube: support @Channel and /user/UserName formats to launch youtube plugin for youtube channels
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/Info.cpp | 5 | ||||
-rw-r--r-- | src/plugins/Youtube.cpp | 44 |
2 files changed, 48 insertions, 1 deletions
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; } |