diff options
Diffstat (limited to 'src/QuickMedia.cpp')
-rw-r--r-- | src/QuickMedia.cpp | 50 |
1 files changed, 45 insertions, 5 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index b47ab13..c57540c 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -1089,18 +1089,58 @@ namespace QuickMedia { .related_media_thumbnail_handler({{"//div[data-role='video-relations']//img", "src", "xhcdn"}}); } - void Program::check_youtube_dl_installed(const std::string &plugin_name) { - if(yt_dl_name) - return; + bool Program::youtube_dl_extract_url(const std::string &url, std::string &video_url, std::string &audio_url) { + const char *youtube_dl_name = get_youtube_dl_program_name(); + if(!youtube_dl_name) + return false; + + std::string ytdl_format; + if(no_video) + ytdl_format = "(bestaudio/best)"; + else + ytdl_format = "(bestvideo[vcodec!*=av01][height<=?" + std::to_string(video_max_height) + "]+bestaudio/best)"; + + ytdl_format += "[protocol^=http]/" + ytdl_format + "[protocol^=m3u8]"; + + std::string result; + const char *args[] = { youtube_dl_name, "--no-warnings", "-f", ytdl_format.c_str(), "-g", "--", url.c_str(), nullptr }; + if(exec_program(args, accumulate_string, &result) != 0) + return false; + + string_split(result, '\n', [&](const char *str, size_t size) { + if(video_url.empty()) + video_url.assign(str, size); + else if(audio_url.empty()) + audio_url.assign(str, size); + return true; + }, false); + + return true; + } + + const char* Program::get_youtube_dl_program_name() { + if(yt_dl_name_checked) + return yt_dl_name; 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); + yt_dl_name = nullptr; } + + yt_dl_name_checked = true; + return yt_dl_name; + } + + void Program::check_youtube_dl_installed(const std::string &plugin_name) { + get_youtube_dl_program_name(); + if(yt_dl_name) + return; + + show_notification("QuickMedia", "yt-dlp or youtube-dl needs to be installed to play " + plugin_name + " videos", Urgency::CRITICAL); + exit(10); } void Program::load_plugin_by_name(std::vector<Tab> &tabs, int &start_tab_index, FileManagerMimeType fm_mime_type, FileSelectionHandler file_selection_handler, std::string instance) { |