From de4825e548b990493b372237cbef9a790bf114c4 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 15 Aug 2021 11:41:06 +0200 Subject: Play popular invidious instance urls directly in qm Replaces popular invidious instance urls with youtube.com --- src/plugins/Youtube.cpp | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'src/plugins') 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 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"; -- cgit v1.2.3