From 68be24ffc69bdd38735faaa87a32d885f47f0ec9 Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Fri, 4 Oct 2019 12:23:28 -0400 Subject: [PATCH] Refactor process_video_params --- src/invidious/videos.cr | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/src/invidious/videos.cr b/src/invidious/videos.cr index ea6788ee..354ab19e 100644 --- a/src/invidious/videos.cr +++ b/src/invidious/videos.cr @@ -1276,19 +1276,19 @@ end def process_video_params(query, preferences) annotations = query["iv_load_policy"]?.try &.to_i? - autoplay = query["autoplay"]?.try &.to_i? + autoplay = query["autoplay"]?.try { |q| (q == "true" || q == "1").to_unsafe } comments = query["comments"]?.try &.split(",").map { |a| a.downcase } - continue = query["continue"]?.try &.to_i? - continue_autoplay = query["continue_autoplay"]?.try &.to_i? - listen = query["listen"]? && (query["listen"] == "true" || query["listen"] == "1").to_unsafe - local = query["local"]? && (query["local"] == "true" || query["local"] == "1").to_unsafe + continue = query["continue"]?.try { |q| (q == "true" || q == "1").to_unsafe } + continue_autoplay = query["continue_autoplay"]?.try { |q| (q == "true" || q == "1").to_unsafe } + listen = query["listen"]?.try { |q| (q == "true" || q == "1").to_unsafe } + local = query["local"]?.try { |q| (q == "true" || q == "1").to_unsafe } player_style = query["player_style"]? preferred_captions = query["subtitles"]?.try &.split(",").map { |a| a.downcase } quality = query["quality"]? region = query["region"]? - related_videos = query["related_videos"]? && (query["related_videos"] == "true" || query["related_videos"] == "1").to_unsafe + related_videos = query["related_videos"]?.try { |q| (q == "true" || q == "1").to_unsafe } speed = query["speed"]?.try &.rchop("x").to_f? - video_loop = query["loop"]?.try &.to_i? + video_loop = query["loop"]?.try { |q| (q == "true" || q == "1").to_unsafe } volume = query["volume"]?.try &.to_i? if preferences @@ -1341,17 +1341,10 @@ def process_video_params(query, preferences) local = false end - if query["t"]? - video_start = decode_time(query["t"]) + if start = query["t"]? || query["time_continue"]? || query["start"]? + video_start = decode_time(start) end video_start ||= 0 - if query["time_continue"]? - video_start = decode_time(query["time_continue"]) - end - video_start ||= 0 - if query["start"]? - video_start = decode_time(query["start"]) - end if query["end"]? video_end = decode_time(query["end"])