aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/Youtube.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/Youtube.cpp')
-rw-r--r--src/plugins/Youtube.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/plugins/Youtube.cpp b/src/plugins/Youtube.cpp
index d9d9239..924bf14 100644
--- a/src/plugins/Youtube.cpp
+++ b/src/plugins/Youtube.cpp
@@ -1783,6 +1783,43 @@ R"END(
return "";
}
+ static int youtube_url_timestamp_to_seconds(const std::string &timestamp) {
+ int hours = 0;
+ int minutes = 0;
+ int seconds = 0;
+ if(sscanf(timestamp.c_str(), "%dh%dm%d", &hours, &minutes, &seconds) == 3)
+ return (hours * 60 * 60) + (minutes * 60) + seconds;
+ if(sscanf(timestamp.c_str(), "%dm%d", &minutes, &seconds) == 2)
+ return (minutes * 60) + seconds;
+ if(sscanf(timestamp.c_str(), "%d", &seconds) == 1)
+ return seconds;
+ return 0;
+ }
+
+ static void youtube_url_remove_timestamp(std::string &url, std::string &timestamp) {
+ size_t timestamp_start = url.find("&t=");
+ if(timestamp_start == std::string::npos)
+ return;
+
+ size_t timestamp_end = url.find("&", timestamp_start + 3);
+ if(timestamp_end == std::string::npos)
+ timestamp_end = url.size();
+
+ int timestamp_seconds = youtube_url_timestamp_to_seconds(url.substr(timestamp_start + 3, timestamp_end - (timestamp_start + 3)));
+ timestamp = std::to_string(timestamp_seconds);
+ url.erase(timestamp_start, timestamp_end - timestamp_start);
+ return;
+ }
+
+ YoutubeVideoPage::YoutubeVideoPage(Program *program, std::string url) : VideoPage(program, "") {
+ set_url(std::move(url));
+ }
+
+ void YoutubeVideoPage::set_url(std::string new_url) {
+ youtube_url_remove_timestamp(new_url, timestamp);
+ VideoPage::set_url(std::move(new_url));
+ }
+
BodyItems YoutubeVideoPage::get_related_media(const std::string &url) {
BodyItems result_items;