aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-07-10 02:06:44 +0200
committerdec05eba <dec05eba@protonmail.com>2020-07-10 02:06:44 +0200
commita5be59329daa54c8afeab01a8ee530fca07baaf7 (patch)
tree36e52f510704d440b34c9dda6df99de0013b8ed6 /src
parent2f91655cbf65e83e6ed812c35ea492f2133fd6b9 (diff)
Fallback to invidio.us if youtube-dl fails (happens with videos that require age verification)
Diffstat (limited to 'src')
-rw-r--r--src/Program.c3
-rw-r--r--src/QuickMedia.cpp45
2 files changed, 45 insertions, 3 deletions
diff --git a/src/Program.c b/src/Program.c
index 2509f6f..2c6759e 100644
--- a/src/Program.c
+++ b/src/Program.c
@@ -43,7 +43,8 @@ int exec_program(const char **args, ProgramOutputCallback output_callback, void
close(fd[WRITE_END]);
execvp(args[0], args);
- return 0;
+ perror("execvp");
+ exit(127);
} else { /* parent */
close(fd[WRITE_END]);
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 60fc523..e30d453 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -651,6 +651,35 @@ namespace QuickMedia {
#endif
}
+ static 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=");
+ if(index != std::string::npos) {
+ index += 20;
+ size_t end_index = youtube_url.find("&", index);
+ if(end_index == std::string::npos)
+ end_index = youtube_url.size();
+ youtube_video_id = youtube_url.substr(index, end_index - index);
+ return true;
+ }
+
+ index = youtube_url.find("youtu.be/");
+ if(index != std::string::npos) {
+ index += 9;
+ size_t end_index = youtube_url.find("?", index);
+ if(end_index == std::string::npos)
+ end_index = youtube_url.size();
+ youtube_video_id = youtube_url.substr(index, end_index - index);
+ return true;
+ }
+
+ return false;
+ }
+
+ static bool youtube_dl_can_download_video(const std::string &video_url) {
+ const char *args[] = { "youtube-dl", "--skip-download", "--", video_url.c_str(), nullptr };
+ return exec_program(args, nullptr, nullptr) == 0;
+ }
+
void Program::video_content_page() {
search_bar->onTextUpdateCallback = nullptr;
search_bar->onTextSubmitCallback = nullptr;
@@ -671,10 +700,22 @@ namespace QuickMedia {
auto load_video_error_check = [this, &video_player, previous_page]() mutable {
watched_videos.insert(content_url);
- VideoPlayer::Error err = video_player->load_video(content_url.c_str(), window.getSystemHandle());
+ std::string video_url = content_url;
+
+ std::string youtube_video_id;
+ if(youtube_url_extract_id(video_url, youtube_video_id)) {
+ // This can fail for example if the video requires age vertification...
+ // TODO: Remove this when youtube-dl is modified to work with videos that require age verification.
+ if(!youtube_dl_can_download_video(video_url)) {
+ // Im sorry invidio.us server... this will be removed later and it only happens when youtube-dl fails!
+ video_url = "https://www.invidio.us/latest_version?id=" + youtube_video_id + "&itag=22";
+ }
+ }
+
+ VideoPlayer::Error err = video_player->load_video(video_url.c_str(), window.getSystemHandle());
if(err != VideoPlayer::Error::OK) {
std::string err_msg = "Failed to play url: ";
- err_msg += content_url;
+ err_msg += video_url;
show_notification("Video player", err_msg.c_str(), Urgency::CRITICAL);
current_page = previous_page;
}