From 0d4b8100cb67eb4d4e3396be20743bd0d4e2a59a Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 11 Jun 2021 19:48:40 +0200 Subject: Add option to play a youtube video directly from an url --- README.md | 3 ++- include/QuickMedia.hpp | 1 + src/QuickMedia.cpp | 32 +++++++++++++++++++++++--------- src/plugins/youtube/Signature.cpp | 2 +- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index a8f68c6..f4e1b0b 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Config data, including manga progress is stored under `$HOME/.config/quickmedia` Cache is stored under `$HOME/.cache/quickmedia`. ## Usage ``` -usage: quickmedia [--use-system-mpv-config] [--dir ] [-e ] +usage: quickmedia [--use-system-mpv-config] [--dir ] [-e ] [youtube-url] OPTIONS: plugin The plugin to use. Should be either launcher, 4chan, manga, manganelo, manganelos, mangatown, mangakatana, mangadex, readm, onimanga, youtube, soundcloud, nyaa.si, matrix, saucenao, file-manager or stdin --no-video Only play audio when playing a video. Disabled by default @@ -17,6 +17,7 @@ OPTIONS: EXAMPLES: quickmedia launcher quickmedia --upscale-images-always manganelo + quickmedia https://www.youtube.com/watch?v=jHg91NVHh3s echo -e "hello\nworld" | quickmedia stdin tabbed -c -k quickmedia launcher -e ``` diff --git a/include/QuickMedia.hpp b/include/QuickMedia.hpp index 903e815..9e24f3c 100644 --- a/include/QuickMedia.hpp +++ b/include/QuickMedia.hpp @@ -204,5 +204,6 @@ namespace QuickMedia { Atom wm_delete_window_atom; XEvent xev; std::filesystem::path file_manager_start_dir; + std::string youtube_url; }; } \ No newline at end of file diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 046a9a2..d1848ca 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -344,7 +344,7 @@ namespace QuickMedia { } static void usage() { - fprintf(stderr, "usage: quickmedia [--no-video] [--use-system-mpv-config] [--dir ] [-e ]\n"); + fprintf(stderr, "usage: quickmedia [--no-video] [--use-system-mpv-config] [--dir ] [-e ] [youtube-url]\n"); fprintf(stderr, "OPTIONS:\n"); fprintf(stderr, " plugin The plugin to use. Should be either launcher, 4chan, manga, manganelo, manganelos, mangatown, mangakatana, mangadex, readm, onimanga, youtube, soundcloud, nyaa.si, matrix, saucenao, file-manager, stdin, pornhub, spankbang, xvideos or xhamster\n"); fprintf(stderr, " --no-video Only play audio when playing a video. Disabled by default\n"); @@ -356,6 +356,7 @@ namespace QuickMedia { fprintf(stderr, "EXAMPLES:\n"); fprintf(stderr, " quickmedia launcher\n"); fprintf(stderr, " quickmedia --upscale-images-always manganelo\n"); + fprintf(stderr, " quickmedia https://www.youtube.com/watch?v=jHg91NVHh3s\n"); fprintf(stderr, " echo -e \"hello\\nworld\" | quickmedia stdin\n"); fprintf(stderr, " tabbed -c -k quickmedia launcher -e\n"); } @@ -390,6 +391,12 @@ namespace QuickMedia { for(int i = 1; i < argc; ++i) { if(!plugin_name) { + std::string youtube_video_id_dummy; + if(youtube_url_extract_id(argv[i], youtube_video_id_dummy)) { + youtube_url = argv[i]; + plugin_name = "youtube"; + } + for(const auto &valid_plugin : valid_plugins) { if(strcmp(argv[i], valid_plugin.first) == 0) { plugin_name = argv[i]; @@ -1171,16 +1178,23 @@ namespace QuickMedia { PipePage::load_body_items_from_stdin(pipe_body->items); tabs.push_back(Tab{std::move(pipe_body), std::make_unique(this), create_search_bar("Search...", SEARCH_DELAY_FILTER)}); } else if(strcmp(plugin_name, "youtube") == 0) { - start_tab_index = 1; - tabs.push_back(Tab{create_body(false, true), std::make_unique(this), create_search_bar("Search...", SEARCH_DELAY_FILTER)}); - tabs.push_back(Tab{create_body(false, true), std::make_unique(this), create_search_bar("Search...", 350)}); + if(youtube_url.empty()) { + start_tab_index = 1; + tabs.push_back(Tab{create_body(false, true), std::make_unique(this), create_search_bar("Search...", SEARCH_DELAY_FILTER)}); + tabs.push_back(Tab{create_body(false, true), std::make_unique(this), create_search_bar("Search...", 350)}); - auto recommended_page = std::make_unique(this); - tabs.push_back(Tab{create_body(false, true), std::move(recommended_page), create_search_bar("Search...", SEARCH_DELAY_FILTER)}); + auto recommended_page = std::make_unique(this); + tabs.push_back(Tab{create_body(false, true), std::move(recommended_page), create_search_bar("Search...", SEARCH_DELAY_FILTER)}); - auto history_body = create_body(false, true); - auto history_page = std::make_unique(this, tabs.front().page.get(), HistoryType::YOUTUBE); - tabs.push_back(Tab{std::move(history_body), std::move(history_page), create_search_bar("Search...", SEARCH_DELAY_FILTER)}); + auto history_body = create_body(false, true); + auto history_page = std::make_unique(this, tabs.front().page.get(), HistoryType::YOUTUBE); + tabs.push_back(Tab{std::move(history_body), std::move(history_page), create_search_bar("Search...", SEARCH_DELAY_FILTER)}); + } else { + current_page = PageType::VIDEO_CONTENT; + auto youtube_video_page = std::make_unique(this, youtube_url); + BodyItems body_items; + video_content_page(nullptr, youtube_video_page.get(), "", false, body_items, 0); + } } else if(strcmp(plugin_name, "pornhub") == 0) { auto search_page = std::make_unique(this, "https://www.pornhub.com/", sf::Vector2i(320/1.5f, 180/1.5f)); add_pornhub_handlers(search_page.get()); diff --git a/src/plugins/youtube/Signature.cpp b/src/plugins/youtube/Signature.cpp index 2460f8a..8c87817 100644 --- a/src/plugins/youtube/Signature.cpp +++ b/src/plugins/youtube/Signature.cpp @@ -235,7 +235,7 @@ namespace QuickMedia { int YoutubeSignatureDecryptor::update_decrypt_function() { std::string response; - DownloadResult download_result = download_to_string("https://www.youtube.com/watch?v=CvFH_6DNRCY&gl=US&hl=en", response, {}, true); + DownloadResult download_result = download_to_string("https://www.youtube.com/watch?v=jNQXAC9IVRw&gl=US&hl=en", response, {}, true); if(download_result != DownloadResult::OK) { fprintf(stderr, "YoutubeSignatureDecryptor::update_decrypt_function failed. Failed to get youtube page\n"); return U_DEC_FUN_NET_ERR; -- cgit v1.2.3