From 2c0347ff7a13896dcc64c1deb4447449790bad73 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Mon, 14 Jun 2021 08:54:55 +0200 Subject: Workaround shitty mpv pulseaudio issue where the video is frozen. Try reloading video on failure to load --- src/plugins/Youtube.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'src/plugins/Youtube.cpp') diff --git a/src/plugins/Youtube.cpp b/src/plugins/Youtube.cpp index 49d7b83..1f8c103 100644 --- a/src/plugins/Youtube.cpp +++ b/src/plugins/Youtube.cpp @@ -1864,29 +1864,31 @@ namespace QuickMedia { return ""; } + const YoutubeVideoFormat *chosen_video_format = nullptr; const YoutubeVideoFormat *best_mp4 = get_highest_resolution_mp4_non_av1(video_formats, max_height); const YoutubeVideoFormat *best_non_mp4 = get_highest_resolution_non_mp4(video_formats, max_height); // We prefer mp4 (h264) because it has the best hardware decoding support if(best_mp4 && (!best_non_mp4 || (best_mp4->height >= best_non_mp4->height && best_mp4->fps >= best_non_mp4->fps))) { - print_chosen_format(*best_mp4); - has_embedded_audio = best_mp4->has_embedded_audio; - return best_mp4->base.url; + chosen_video_format = best_mp4; } else if(best_non_mp4) { - print_chosen_format(*best_non_mp4); - has_embedded_audio = best_non_mp4->has_embedded_audio; - return best_non_mp4->base.url; + chosen_video_format = best_non_mp4; } + + if(!chosen_video_format) + chosen_video_format = &video_formats.back(); - print_chosen_format(video_formats.back()); - has_embedded_audio = video_formats.back().has_embedded_audio; - return video_formats.back().base.url; + print_chosen_format(*chosen_video_format); + has_embedded_audio = chosen_video_format->has_embedded_audio; + return chosen_video_format->base.url; } std::string YoutubeVideoPage::get_audio_url() { if(audio_formats.empty()) return ""; - return audio_formats.front().base.url; + const YoutubeAudioFormat *chosen_audio_format = &audio_formats.front(); + fprintf(stderr, "Choosing youtube audio format: bitrate: %d, mime type: %s\n", chosen_audio_format->base.bitrate, chosen_audio_format->base.mime_type.c_str()); + return chosen_audio_format->base.url; } PluginResult YoutubeVideoPage::load(std::string &title, std::string &channel_url) { -- cgit v1.2.3