diff options
Diffstat (limited to 'src/QuickMedia.cpp')
-rw-r--r-- | src/QuickMedia.cpp | 124 |
1 files changed, 30 insertions, 94 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index f91ef7e..b1bbcde 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -1080,10 +1080,17 @@ namespace QuickMedia { .related_media_thumbnail_handler({{"//div[data-role='video-relations']//img", "src", "xhcdn"}}); } - static void check_youtube_dl_installed(const std::string &plugin_name) { - if(!is_program_executable_by_name("youtube-dl")) { - show_notification("QuickMedia", "youtube-dl needs to be installed to play " + plugin_name + " videos", Urgency::CRITICAL); - abort(); + void Program::check_youtube_dl_installed(const std::string &plugin_name) { + if(yt_dl_name) + return; + + if(is_program_executable_by_name("yt-dlp")) { + yt_dl_name = "yt-dlp"; + } else if(is_program_executable_by_name("youtube-dl")) { + yt_dl_name = "youtube-dl"; + } else { + show_notification("QuickMedia", "yt-dlp or youtube-dl needs to be installed to play " + plugin_name + " videos", Urgency::CRITICAL); + exit(10); } } @@ -1322,6 +1329,8 @@ namespace QuickMedia { pipe_body->set_items(std::move(body_items)); tabs.push_back(Tab{std::move(pipe_body), std::make_unique<PipePage>(this), create_search_bar("Search...", SEARCH_DELAY_FILTER)}); } else if(strcmp(plugin_name, "youtube") == 0) { + check_youtube_dl_installed(plugin_name); + use_youtube_dl = true; if(launch_url_type == LaunchUrlType::YOUTUBE_CHANNEL) { YoutubeChannelPage::create_each_type(this, std::move(launch_url), "", "Channel", tabs); } else if(launch_url_type == LaunchUrlType::YOUTUBE_VIDEO) { @@ -3031,6 +3040,8 @@ namespace QuickMedia { return url.find("pornhub.com") != std::string::npos || url.find("xhamster.com") != std::string::npos || url.find("spankbang.com") != std::string::npos + || url.find("youtube.com") != std::string::npos + || url.find("youtu.be") != std::string::npos // TODO: Remove when youtube-dl is no longer required to download soundcloud music || is_soundcloud(url); } @@ -3215,9 +3226,11 @@ namespace QuickMedia { mgl::Clock update_window_focus_time; // HACK! std::string youtube_video_id_dummy; - const bool is_youtube = youtube_url_extract_id(video_page->get_url(), youtube_video_id_dummy); + //const bool is_youtube = youtube_url_extract_id(video_page->get_url(), youtube_video_id_dummy); const bool is_matrix = strcmp(plugin_name, "matrix") == 0; const bool is_youtube_plugin = strcmp(plugin_name, "youtube") == 0; + const bool is_youtube = false; + const bool is_youtube_rel = youtube_url_extract_id(video_page->get_url(), youtube_video_id_dummy); bool added_recommendations = false; mgl::Clock time_watched_timer; @@ -3739,7 +3752,7 @@ namespace QuickMedia { current_page = previous_page; go_to_previous_page = true; break; - } else if(update_err == VideoPlayer::Error::EXITED && video_player->exit_status == 0 && (!is_matrix || is_youtube)) { + } else if(update_err == VideoPlayer::Error::EXITED && video_player->exit_status == 0 && (!is_matrix || is_youtube_rel)) { std::string new_video_url; if(!video_page->should_autoplay()) { @@ -7960,7 +7973,8 @@ namespace QuickMedia { const bool download_use_youtube_dl = url_should_download_with_youtube_dl(url); std::string filename; std::string video_id; - const bool url_is_youtube = youtube_url_extract_id(url, video_id); + //const bool url_is_youtube = youtube_url_extract_id(url, video_id); + const bool url_is_youtube = false; std::unique_ptr<YoutubeVideoPage> youtube_video_page; std::string video_url; @@ -7970,14 +7984,18 @@ namespace QuickMedia { TaskResult task_result = TaskResult::TRUE; if(download_use_youtube_dl) { - if(!is_program_executable_by_name("youtube-dl")) { - show_notification("QuickMedia", "youtube-dl needs to be installed to download the video/music", Urgency::CRITICAL); - abort(); + if(is_program_executable_by_name("yt-dlp")) { + yt_dl_name = "yt-dlp"; + } else if(is_program_executable_by_name("youtube-dl")) { + yt_dl_name = "youtube-dl"; + } else { + show_notification("QuickMedia", "yt-dlp or youtube-dl needs to be installed to download the video/music", Urgency::CRITICAL); + exit(10); } task_result = run_task_with_loading_screen([this, url, &filename]{ std::string json_str; - std::vector<const char*> args = { "youtube-dl", "--skip-download", "--print-json", "--no-warnings" }; + std::vector<const char*> args = { yt_dl_name, "--skip-download", "--print-json", "--no-warnings" }; if(no_video) { args.push_back("-f"); args.push_back("bestaudio/best"); @@ -8012,78 +8030,6 @@ namespace QuickMedia { return !filename.empty(); }); - } else if(url_is_youtube) { - youtube_video_page = std::make_unique<YoutubeVideoPage>(this, url); - bool cancelled = false; - bool load_successful = false; - const int video_max_height = video_get_max_height(); - - std::string err_str; - for(int i = 0; i < 3; ++i) { - task_result = run_task_with_loading_screen([&]{ - VideoInfo video_info; - SubmitArgs submit_args; - if(youtube_video_page->load(submit_args, video_info, err_str) != PluginResult::OK) - return false; - - filename = video_info.title; - std::string ext; - bool has_embedded_audio = true; - video_url = no_video ? "" : youtube_video_page->get_video_url(video_max_height, has_embedded_audio, ext); - audio_url.clear(); - - if(!has_embedded_audio || no_video) - audio_url = youtube_video_page->get_audio_url(ext); - - if(video_url.empty() && audio_url.empty()) - return false; - - if(!youtube_url_is_live_stream(video_url) && !youtube_url_is_live_stream(audio_url)) { - video_content_length = 0; - audio_content_length = 0; - std::string new_video_url = video_url; - std::string new_audio_url = audio_url; - auto current_thread_id = std::this_thread::get_id(); - if(!youtube_custom_redirect(new_video_url, new_audio_url, video_content_length, audio_content_length, [current_thread_id]{ return !program_is_dead_in_thread(current_thread_id); })) { - if(program_is_dead_in_current_thread()) - cancelled = true; - return false; - } - - video_url = std::move(new_video_url); - audio_url = std::move(new_audio_url); - } - - if(!video_url.empty() && !audio_url.empty()) - filename += ".mkv"; - else - filename += ext; - - return true; - }); - - if(task_result == TaskResult::CANCEL || cancelled) { - exit_code = 1; - return; - } else if(task_result == TaskResult::FALSE) { - continue; - } - - load_successful = true; - break; - } - - if(!load_successful) { - show_notification("QuickMedia", "Download failed" + (err_str.empty() ? "" : ", error: " + err_str), Urgency::CRITICAL); - exit_code = 1; - return; - } - - if(youtube_url_is_live_stream(video_url) || youtube_url_is_live_stream(audio_url)) { - show_notification("QuickMedia", "Downloading youtube live streams is currently not supported", Urgency::CRITICAL); - exit_code = 1; - return; - } } else { if(download_filename.empty()) { task_result = run_task_with_loading_screen([url, &filename]{ @@ -8173,17 +8119,7 @@ namespace QuickMedia { std::unique_ptr<Downloader> downloader; if(download_use_youtube_dl) { - downloader = std::make_unique<YoutubeDlDownloader>(url, output_filepath, no_video); - } else if(url_is_youtube) { - MediaMetadata video_metadata; - video_metadata.url = std::move(video_url); - video_metadata.content_length = video_content_length; - - MediaMetadata audio_metadata; - audio_metadata.url = std::move(audio_url); - audio_metadata.content_length = audio_content_length; - - downloader = std::make_unique<YoutubeDownloader>(video_metadata, audio_metadata, output_filepath); + downloader = std::make_unique<YoutubeDlDownloader>(yt_dl_name, url, output_filepath, no_video); } else { downloader = std::make_unique<CurlDownloader>(url, output_filepath); } |