From e3a151d5d2a71126c275567862a0cd2d471b42bc Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 4 Sep 2022 22:35:17 +0200 Subject: Dramacool: watch progress --- src/plugins/DramaCool.cpp | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'src/plugins/DramaCool.cpp') diff --git a/src/plugins/DramaCool.cpp b/src/plugins/DramaCool.cpp index 9b419f9..4bb1054 100644 --- a/src/plugins/DramaCool.cpp +++ b/src/plugins/DramaCool.cpp @@ -2,6 +2,7 @@ #include "../../include/Theme.hpp" #include "../../include/StringUtils.hpp" #include "../../include/M3U8.hpp" +#include "../../plugins/utils/WatchProgress.hpp" #include #include @@ -118,7 +119,7 @@ namespace QuickMedia { auto body = create_body(); body->set_items(std::move(result_items)); - result_tabs.push_back(Tab{ std::move(body), std::make_unique(program), create_search_bar("Search...", SEARCH_DELAY_FILTER) }); + result_tabs.push_back(Tab{ std::move(body), std::make_unique(program, args.title), create_search_bar("Search...", SEARCH_DELAY_FILTER) }); return PluginResult::OK; } @@ -395,13 +396,13 @@ namespace QuickMedia { } */ - result_tabs.push_back(Tab{ nullptr, std::make_unique(program, std::move(video_url), args.title, std::move(referer)), nullptr }); + result_tabs.push_back(Tab{ nullptr, std::make_unique(program, std::move(video_url), series_name, args.title, std::move(referer)), nullptr }); return PluginResult::OK; } PluginResult DramaCoolVideoPage::load(const SubmitArgs&, VideoInfo &video_info, std::string &err_str) { - video_info.title = title; + video_info.title = episode_name; video_info.channel_url.clear(); video_info.duration = 0.0; video_info.chapters.clear(); @@ -409,4 +410,29 @@ namespace QuickMedia { err_str.clear(); return PluginResult::OK; } + + std::string DramaCoolVideoPage::get_url_timestamp() { + // TODO: Remove very old videos, to not make this file too large which slows this down on slow harddrives + std::unordered_map watch_progress = get_watch_progress_for_plugin("dramacool"); + auto it = watch_progress.find(get_video_id()); + if(it == watch_progress.end()) + return ""; + + // If we are very close to the end then start from the beginning. + // This is the same behavior as mpv. + // This is better because we dont want the video player to stop immediately after we start playing and we dont get any chance to seek. + if(it->second.time_pos_sec + 10.0 >= it->second.duration_sec) + return ""; + else + return std::to_string(it->second.time_pos_sec); + } + + void DramaCoolVideoPage::set_watch_progress(int64_t time_pos_sec, int64_t duration_sec) { + std::string video_id = get_video_id(); + set_watch_progress_for_plugin("dramacool", video_id, time_pos_sec, duration_sec, video_id); + } + + std::string DramaCoolVideoPage::get_video_id() const { + return series_name + "/" + episode_name; + } } \ No newline at end of file -- cgit v1.2.3