aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-07-28 02:39:28 +0200
committerdec05eba <dec05eba@protonmail.com>2020-07-28 02:39:28 +0200
commitc1297a820c65dfd0865f75401bbaecbe2f64ac3c (patch)
treef21ce8ee0de65dd3fa285e22e4e64c79a147274c /src
parent66e8390dce2d96c2def73f0781c0072a26acd8e4 (diff)
Add more invidious fallbacks
Diffstat (limited to 'src')
-rw-r--r--src/QuickMedia.cpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 7bb537b..74e5194 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -868,6 +868,12 @@ namespace QuickMedia {
search_bar->onTextUpdateCallback = nullptr;
search_bar->onTextSubmitCallback = nullptr;
+ int fallback_count = 0;
+ const int max_fallbacks = 3;
+ /* itags from: https://gist.github.com/sidneys/7095afe4da4ae58694d128b1034e01e2 */
+ /* 1080p, 720p, 360p */
+ const char *fallback_itags[max_fallbacks] = { "37", "22", "18" };
+
Page previous_page = pop_page_stack();
std::unique_ptr<VideoPlayer> video_player;
@@ -922,7 +928,7 @@ namespace QuickMedia {
};
bool has_video_started = true;
- auto video_event_callback = [this, &video_player, &load_video_error_check, previous_page, &has_video_started](const char *event_name) mutable {
+ auto video_event_callback = [this, &video_player, &load_video_error_check, previous_page, &has_video_started, &fallback_count](const char *event_name) mutable {
bool end_of_file = false;
if(strcmp(event_name, "pause") == 0) {
double time_remaining = 9999.0;
@@ -932,6 +938,7 @@ namespace QuickMedia {
video_player->set_paused(false);
} else if(strcmp(event_name, "start-file") == 0) {
has_video_started = true;
+ fallback_count = 0;
}
if(end_of_file && has_video_started) {
@@ -1001,10 +1008,11 @@ namespace QuickMedia {
VideoPlayer::Error update_err = video_player->update();
if(update_err == VideoPlayer::Error::FAIL_TO_CONNECT_TIMEOUT) {
- show_notification("Video player", "Failed to connect to mpv ipc after 5 seconds", Urgency::CRITICAL);
+ show_notification("Video player", "Failed to connect to mpv ipc after 10 seconds", Urgency::CRITICAL);
current_page = previous_page;
break;
- } else if(update_err == VideoPlayer::Error::EXITED) {
+ } else if(update_err == VideoPlayer::Error::EXITED && fallback_count < max_fallbacks) {
+ ++fallback_count;
std::string youtube_video_id;
if(youtube_url_extract_id(content_url, youtube_video_id)) {
fprintf(stderr, "Failed to play youtube video (maybe because of age verification?), trying with invidio.us...\n");
@@ -1016,7 +1024,7 @@ namespace QuickMedia {
video_player.reset();
video_player = std::make_unique<VideoPlayer>(current_plugin->use_tor, use_system_mpv_config, video_event_callback, on_window_create);
- std::string new_video_url = "https://www.invidio.us/latest_version?id=" + youtube_video_id + "&itag=22";
+ std::string new_video_url = "https://www.invidio.us/latest_version?id=" + youtube_video_id + "&itag=" + fallback_itags[fallback_count - 1];
VideoPlayer::Error err = video_player->load_video(new_video_url.c_str(), window.getSystemHandle(), current_plugin->name);
if(err != VideoPlayer::Error::OK) {
std::string err_msg = "Failed to play url: ";