aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TODO3
-rw-r--r--include/Downloader.hpp2
-rw-r--r--include/QuickMedia.hpp2
-rw-r--r--plugins/Youtube.hpp2
-rw-r--r--src/Downloader.cpp4
-rw-r--r--src/QuickMedia.cpp14
-rw-r--r--src/plugins/Youtube.cpp27
7 files changed, 43 insertions, 11 deletions
diff --git a/TODO b/TODO
index 9ad1d52..3431697 100644
--- a/TODO
+++ b/TODO
@@ -196,4 +196,5 @@ Add throttling to youtube live stream (MediaProxy).
Use event timestamp to sort display name/room name (etc) events to apply them in order when fetching previous messages or additional messages.
Restart and resume youtube media download in downloader when media is throttled.
Try to reconnect media proxy on disconnect. The internet may be unstable (for example on mobile internet).
-Youtube is still getting throttled, but to 500kb/sec from 5mb/sec. How to detect this???. \ No newline at end of file
+Youtube is still getting throttled, but to 500kb/sec from 5mb/sec. How to detect this???.
+Opening a media url should display it directly in quickmedia. \ No newline at end of file
diff --git a/include/Downloader.hpp b/include/Downloader.hpp
index f09f9bf..cc15e5d 100644
--- a/include/Downloader.hpp
+++ b/include/Downloader.hpp
@@ -1,8 +1,8 @@
#pragma once
+#include "../plugins/youtube/YoutubeMediaProxy.hpp"
#include "Path.hpp"
#include "AsyncTask.hpp"
-#include "../plugins/youtube/YoutubeMediaProxy.hpp"
#include <string>
namespace QuickMedia {
diff --git a/include/QuickMedia.hpp b/include/QuickMedia.hpp
index 71e4797..cb3f5ef 100644
--- a/include/QuickMedia.hpp
+++ b/include/QuickMedia.hpp
@@ -124,7 +124,7 @@ namespace QuickMedia {
void chat_login_page();
bool chat_page(MatrixChatPage *matrix_chat_page, RoomData *current_room);
void after_matrix_login_page();
- void download_page(const std::string &url);
+ void download_page(std::string url);
// Returns the full path where the file should be saved, or an empty string if the operation was cancelled
std::string file_save_page(const std::string &filename);
diff --git a/plugins/Youtube.hpp b/plugins/Youtube.hpp
index c7aff93..c3945de 100644
--- a/plugins/Youtube.hpp
+++ b/plugins/Youtube.hpp
@@ -23,6 +23,8 @@ namespace QuickMedia {
YoutubeFormat base;
};
+ // Returns |url| if the url is already a youtube url
+ std::string invidious_url_to_youtube_url(const std::string &url);
bool youtube_url_extract_id(const std::string &youtube_url, std::string &youtube_video_id);
// |video_url| or |audio_url| will be empty if there is an error and false will be returned.
// If false is returned from |active_handler|, then this function is cancelled.
diff --git a/src/Downloader.cpp b/src/Downloader.cpp
index 450bff3..fc16e07 100644
--- a/src/Downloader.cpp
+++ b/src/Downloader.cpp
@@ -27,7 +27,7 @@ namespace QuickMedia {
const char *args[] = { "curl",
"-H", "Accept-Language: en-US,en;q=0.5", "-H", "Connection: keep-alive", "--compressed",
"-H", "user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36",
- "-g", "-s", "-L", "-f", "-o", output_filepath_tmp.data.c_str(),
+ "--no-buffer", "-g", "-s", "-L", "-f", "-o", output_filepath_tmp.data.c_str(),
"-D", "/dev/stdout",
"--", url.c_str(), nullptr };
@@ -37,7 +37,7 @@ namespace QuickMedia {
const char *args[] = { "curl",
"-H", "Accept-Language: en-US,en;q=0.5", "-H", "Connection: keep-alive", "--compressed",
"-H", "user-agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36",
- "-g", "-s", "-L", "-f", "-o", output_filepath_tmp.data.c_str(),
+ "--no-buffer", "-g", "-s", "-L", "-f", "-o", output_filepath_tmp.data.c_str(),
"--", url.c_str(), nullptr };
if(exec_program_pipe(args, &read_program) != 0)
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 6a37b1d..d006f3d 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -397,8 +397,9 @@ 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];
+ std::string youtube_url_converted = invidious_url_to_youtube_url(argv[i]);
+ if(youtube_url_extract_id(youtube_url_converted, youtube_video_id_dummy)) {
+ youtube_url = std::move(youtube_url_converted);
plugin_name = "youtube";
}
@@ -5514,16 +5515,18 @@ namespace QuickMedia {
bool avatar_applied = false;
- auto launch_url = [this, matrix_chat_page, &tabs, MESSAGES_TAB_INDEX, &redraw, &avatar_applied](const std::string &url) mutable {
+ auto launch_url = [this, matrix_chat_page, &tabs, MESSAGES_TAB_INDEX, &redraw, &avatar_applied](std::string url) mutable {
if(url.empty())
return;
+ url = invidious_url_to_youtube_url(url);
+
std::string video_id;
if(youtube_url_extract_id(url, video_id)) {
watched_videos.clear();
page_stack.push(PageType::CHAT);
current_page = PageType::VIDEO_CONTENT;
- auto youtube_video_page = std::make_unique<YoutubeVideoPage>(this, url);
+ auto youtube_video_page = std::make_unique<YoutubeVideoPage>(this, std::move(url));
// TODO: Use real title
video_content_page(matrix_chat_page, youtube_video_page.get(), "", false, tabs[MESSAGES_TAB_INDEX].body.get(), tabs[MESSAGES_TAB_INDEX].body->get_selected_item());
redraw = true;
@@ -6688,9 +6691,10 @@ namespace QuickMedia {
return 0;
}
- void Program::download_page(const std::string &url) {
+ void Program::download_page(std::string url) {
window.setTitle("QuickMedia - Select where you want to save " + std::string(url));
+ url = invidious_url_to_youtube_url(url);
const bool download_use_youtube_dl = url_should_download_with_youtube_dl(url);
std::string filename;
std::string video_id;
diff --git a/src/plugins/Youtube.cpp b/src/plugins/Youtube.cpp
index ce1c153..be405b1 100644
--- a/src/plugins/Youtube.cpp
+++ b/src/plugins/Youtube.cpp
@@ -19,6 +19,30 @@ extern "C" {
namespace QuickMedia {
static const char *youtube_client_version = "x-youtube-client-version: 2.20210622.10.00";
+ static const std::array<std::string, 10> invidious_urls = {
+ "yewtu.be",
+ "invidious.snopyta.org",
+ "invidious.kavin.rocks",
+ "vid.puffyan.us",
+ "invidious.exonip.de",
+ "ytprivate.com",
+ "invidious.silkky.cloud",
+ "invidious-us.kavin.rocks",
+ "inv.riverside.rocks",
+ "y.com.cm"
+ };
+
+ std::string invidious_url_to_youtube_url(const std::string &url) {
+ std::string result = url;
+ for(const std::string &invidious_url : invidious_urls) {
+ const size_t index = url.find(invidious_url);
+ if(index != std::string::npos) {
+ result.replace(index, invidious_url.size(), "youtube.com");
+ break;
+ }
+ }
+ return result;
+ }
bool youtube_url_extract_id(const std::string &youtube_url, std::string &youtube_video_id) {
size_t index = youtube_url.find("youtube.com/watch?v=");
@@ -2033,6 +2057,7 @@ namespace QuickMedia {
}
void YoutubeVideoPage::set_url(std::string new_url) {
+ new_url = invidious_url_to_youtube_url(new_url);
youtube_url_remove_timestamp(new_url, timestamp);
VideoPage::set_url(std::move(new_url));
}
@@ -2226,7 +2251,7 @@ namespace QuickMedia {
if(chosen_audio_format->base.mime_type.find("mp4") != std::string::npos)
ext = ".m4a";
else if(chosen_audio_format->base.mime_type.find("webm") != std::string::npos)
- ext = ".webm";
+ ext = ".opus"; // TODO: Detect if vorbis (.ogg) or opus (.opus)
else if(chosen_audio_format->base.mime_type.find("opus") != std::string::npos)
ext = ".opus";