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 --- src/QuickMedia.cpp | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'src/QuickMedia.cpp') 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()); -- cgit v1.2.3