diff options
author | dec05eba <dec05eba@protonmail.com> | 2019-08-07 06:46:03 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2019-08-07 06:46:07 +0200 |
commit | 852c6bc48b7044c54923b722ab5d9363a27ceb6c (patch) | |
tree | 5ced7f86526e44a605342957ae5626b443d387d9 | |
parent | 55cb9a1ffb4226e5771c45d294ae297fe0a1b94e (diff) |
Youtube: do not play videos that have been played before
-rw-r--r-- | include/QuickMedia.hpp | 2 | ||||
-rw-r--r-- | src/QuickMedia.cpp | 19 | ||||
-rw-r--r-- | src/VideoPlayer.cpp | 4 |
3 files changed, 21 insertions, 4 deletions
diff --git a/include/QuickMedia.hpp b/include/QuickMedia.hpp index 54799b8..2ab4733 100644 --- a/include/QuickMedia.hpp +++ b/include/QuickMedia.hpp @@ -8,6 +8,7 @@ #include <SFML/Graphics/Font.hpp> #include <SFML/Graphics/RenderWindow.hpp> #include <json/value.h> +#include <unordered_set> namespace QuickMedia { class Body; @@ -42,5 +43,6 @@ namespace QuickMedia { int image_index; Path content_storage_file; Json::Value content_storage_json; + std::unordered_set<std::string> watched_videos; }; }
\ No newline at end of file diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 7f7bb1c..1a88776 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -191,6 +191,8 @@ namespace QuickMedia { FileType file_type = get_file_type(content_storage_file); if(file_type == FileType::REGULAR) get_manga_storage_json(content_storage_file, content_storage_json); + } else if(next_page == Page::VIDEO_CONTENT) { + watched_videos.clear(); } current_page = next_page; } @@ -286,6 +288,7 @@ namespace QuickMedia { search_bar->onTextUpdateCallback = nullptr; search_bar->onTextSubmitCallback = nullptr; + watched_videos.insert(video_url); std::unique_ptr<VideoPlayer> video_player = nullptr; try { printf("Play video: %s\n", video_url.c_str()); @@ -300,9 +303,21 @@ namespace QuickMedia { if(video_player) { video_player->onPlaybackEndedCallback = [this, &related_media, &video_player, &reload]() { - if(related_media.empty()) + std::string new_video_url; + // Find video that hasn't been played before in this video session + for(auto it = related_media.begin(), end = related_media.end(); it != end; ++it) { + if(watched_videos.find((*it)->url) == watched_videos.end()) { + new_video_url = (*it)->url; + related_media.erase(it); + break; + } + } + + // If there are no videos to play, then dont play any... + if(new_video_url.empty()) return; - video_url = related_media.front()->url; + + video_url = std::move(new_video_url); related_media = current_plugin->get_related_media(video_url); // TODO: This doesn't seem to work correctly right now, it causes video to become black when changing video (context reset bug). //video_player->load_file(video_url); diff --git a/src/VideoPlayer.cpp b/src/VideoPlayer.cpp index dbfcaac..1a2cc9a 100644 --- a/src/VideoPlayer.cpp +++ b/src/VideoPlayer.cpp @@ -86,8 +86,8 @@ namespace QuickMedia { //check_error(mpv_set_option_string(mpv, "vo", "gpu")); //check_error(mpv_set_option_string(mpv, "hwdec", "auto")); - check_error(mpv_set_option_string(mpv, "terminal", "yes")); - check_error(mpv_set_option_string(mpv, "msg-level", "all=v")); + //check_error(mpv_set_option_string(mpv, "terminal", "yes")); + //check_error(mpv_set_option_string(mpv, "msg-level", "all=v")); if(loop) check_error(mpv_set_option_string(mpv, "loop", "inf")); |