aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-01-25 16:52:35 +0100
committerdec05eba <dec05eba@protonmail.com>2021-01-25 16:52:35 +0100
commit0d7ce5264e8c87c522a93172c944541bb205b9d5 (patch)
tree3fe19f12d96c1bf830f777e101e37edfedd0b80d /src
parent82d4273e445b85e15fe12caaa52c301fa77aaa6c (diff)
Limit ytdl video resolution to the largest monitors height
Diffstat (limited to 'src')
-rw-r--r--src/QuickMedia.cpp27
-rw-r--r--src/VideoPlayer.cpp9
2 files changed, 32 insertions, 4 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 41c2c6e..719345d 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -80,6 +80,21 @@ static int get_monitor_max_hz(Display *display) {
return 60;
}
+static int get_largest_monitor_height(Display *display) {
+ XRRScreenResources *screen_res = XRRGetScreenResources(display, DefaultRootWindow(display));
+ if(screen_res) {
+ int max_height = 0;
+ for(int i = 0; i < screen_res->nmode; ++i) {
+ max_height = std::max(max_height, (int)screen_res->modes[i].height);
+ }
+ XRRFreeScreenResources(screen_res);
+ if(max_height == 0)
+ max_height = 1080;
+ return std::max(max_height, 480);
+ }
+ return 1080;
+}
+
static void get_screen_resolution(Display *display, int *width, int *height) {
*width = DefaultScreenOfDisplay(display)->width;
*height = DefaultScreenOfDisplay(display)->height;
@@ -1721,7 +1736,7 @@ namespace QuickMedia {
video_url_converted = video_url;
}
- video_player = std::make_unique<VideoPlayer>(use_tor, no_video, use_system_mpv_config, resume_video, is_matrix, video_event_callback, on_window_create, resources_root);
+ video_player = std::make_unique<VideoPlayer>(use_tor, no_video, use_system_mpv_config, resume_video, is_matrix, video_event_callback, on_window_create, resources_root, get_largest_monitor_height(disp));
VideoPlayer::Error err = video_player->load_video(video_url_converted.c_str(), window.getSystemHandle(), plugin_name);
if(err != VideoPlayer::Error::OK) {
std::string err_msg = "Failed to play url: ";
@@ -3254,7 +3269,7 @@ namespace QuickMedia {
} else {
Message *orig_message = static_cast<Message*>(body_item->userdata);
body_item->set_description(message_get_body_remove_formatting(message.get()));
- if(message_contains_user_mention(message->body, my_display_name) || message_contains_user_mention(message->body, me->user_id) || (orig_message && orig_message->user == me))
+ if(message_contains_user_mention(message->body, my_display_name) || message_contains_user_mention(message->body, me->user_id) || (orig_message && orig_message->user == me && message->user != me))
body_item->set_description_color(sf::Color(255, 100, 100));
else
body_item->set_description_color(sf::Color::White);
@@ -3289,7 +3304,7 @@ namespace QuickMedia {
} else {
Message *orig_message = static_cast<Message*>(body_item->userdata);
body_item->set_description(message_get_body_remove_formatting(message.get()));
- if(message_contains_user_mention(message->body, my_display_name) || message_contains_user_mention(message->body, me->user_id) || (orig_message && orig_message->user == me))
+ if(message_contains_user_mention(message->body, my_display_name) || message_contains_user_mention(message->body, me->user_id) || (orig_message && orig_message->user == me && message->user != me))
body_item->set_description_color(sf::Color(255, 100, 100));
else
body_item->set_description_color(sf::Color::White);
@@ -3694,6 +3709,8 @@ namespace QuickMedia {
body_item->embedded_item->reactions.clear();
if(related_body_item->userdata && static_cast<Message*>(related_body_item->userdata)->user == me)
body_item->set_description_color(sf::Color(255, 100, 100));
+ else
+ body_item->set_description_color(sf::Color::White);
body_item->embedded_item_status = FetchStatus::FINISHED_LOADING;
return;
}
@@ -3720,6 +3737,8 @@ namespace QuickMedia {
body_item->reactions.clear();
if(message_contains_user_mention(related_body_item->get_description(), current_room->get_user_display_name(me)) || message_contains_user_mention(related_body_item->get_description(), me->user_id))
body_item->set_description_color(sf::Color(255, 100, 100));
+ else
+ body_item->set_description_color(sf::Color::White);
event_data->status = FetchStatus::FINISHED_LOADING;
event_data->message = static_cast<Message*>(related_body_item->userdata);
body_item->userdata = event_data;
@@ -3774,6 +3793,8 @@ namespace QuickMedia {
body_item->embedded_item->reactions.clear();
if((related_body_item->userdata && static_cast<Message*>(related_body_item->userdata)->user == me) || message_contains_user_mention(message->body, current_room->get_user_display_name(me)) || message_contains_user_mention(message->body, me->user_id))
body_item->set_description_color(sf::Color(255, 100, 100));
+ else
+ body_item->set_description_color(sf::Color::White);
body_item->embedded_item_status = FetchStatus::FINISHED_LOADING;
return;
}
diff --git a/src/VideoPlayer.cpp b/src/VideoPlayer.cpp
index bc37710..4653c5b 100644
--- a/src/VideoPlayer.cpp
+++ b/src/VideoPlayer.cpp
@@ -18,7 +18,7 @@ const int MAX_RETRIES_CONNECT = 1000;
const int READ_TIMEOUT_MS = 200;
namespace QuickMedia {
- VideoPlayer::VideoPlayer(bool use_tor, bool no_video, bool use_system_mpv_config, bool resume_playback, bool keep_open, EventCallbackFunc _event_callback, VideoPlayerWindowCreateCallback _window_create_callback, const std::string &resource_root) :
+ VideoPlayer::VideoPlayer(bool use_tor, bool no_video, bool use_system_mpv_config, bool resume_playback, bool keep_open, EventCallbackFunc _event_callback, VideoPlayerWindowCreateCallback _window_create_callback, const std::string &resource_root, int monitor_height) :
exit_status(0),
use_tor(use_tor),
no_video(no_video),
@@ -30,6 +30,7 @@ namespace QuickMedia {
connected_to_ipc(false),
connect_tries(0),
find_window_tries(0),
+ monitor_height(monitor_height),
event_callback(_event_callback),
window_create_callback(_window_create_callback),
window_handle(0),
@@ -44,6 +45,7 @@ namespace QuickMedia {
display = XOpenDisplay(NULL);
if (!display)
throw std::runtime_error("Failed to open display to X11 server");
+ fprintf(stderr, "Video max height: %d\n", monitor_height);
}
VideoPlayer::~VideoPlayer() {
@@ -89,6 +91,8 @@ namespace QuickMedia {
create_directory_recursive(mpv_watch_later_dir);
std::string watch_later_dir = "--watch-later-directory=" + mpv_watch_later_dir.data;
+ std::string ytdl_format = "--ytdl-format=bestvideo[height<=?" + std::to_string(monitor_height) + "]+bestaudio/best";
+
// TODO: Resume playback if the last video played matches the first video played next time QuickMedia is launched
args.insert(args.end(), {
"mpv",
@@ -101,6 +105,9 @@ namespace QuickMedia {
watch_later_dir.c_str(),
"--cache-on-disk=yes",
"--ytdl-raw-options=sub-lang=\"en,eng,enUS,en-US\",write-sub=",
+ ytdl_format.c_str(),
+ // TODO: Disable hr seek on low power devices?
+ "--hr-seek=yes",
input_conf.c_str(),
wid_arg.c_str()
});