From 6a7d19163eb7acb537c1b24dc8b1f5c1fab2be34 Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Sat, 28 Apr 2018 09:27:05 -0500 Subject: [PATCH] General cleanup --- src/helpers.cr | 2 +- src/invidious.cr | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/helpers.cr b/src/helpers.cr index 1506a3dd..6cfe7baa 100644 --- a/src/helpers.cr +++ b/src/helpers.cr @@ -531,7 +531,7 @@ def login_req(login_form, f_req) "flowEntry" => "ServiceLogin", } - data = data.merge(login_form) + data = login_form.merge(data) return HTTP::Params.encode(data) end diff --git a/src/invidious.cr b/src/invidious.cr index 2b8a8970..1948c8e2 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -20,8 +20,8 @@ require "option_parser" require "pg" require "xml" require "yaml" -require "./helpers" require "./cookie_fix" +require "./helpers" CONFIG = Config.from_yaml(File.read("config/config.yml")) @@ -147,10 +147,10 @@ spawn do config.api_key = CONFIG.dl_api_key.not_nil! end filter = true - else - filter = false end + filter ||= false + loop do begin top = rank_videos(PG_DB, 40, filter, YT_URL) @@ -286,9 +286,8 @@ get "/watch" do |env| if video.likes > 0 || video.dislikes > 0 calculated_rating = (video.likes.to_f/(video.likes.to_f + video.dislikes.to_f) * 4 + 1) - else - calculated_rating = 0.0 end + calculated_rating ||= 0.0 if video.info["ad_slots"]? ad_slots = video.info["ad_slots"].split(",") @@ -359,26 +358,23 @@ get "/search" do |env| id = root.xpath_node(%q(div[contains(@class,"yt-lockup-thumbnail")]/a/@href)) if id id = id.content.lchop("/watch?v=") - else - id = "" end + id ||= "" video["id"] = id title = root.xpath_node(%q(div[@class="yt-lockup-content"]/h3/a)) if title video["title"] = title.content - else - video["title"] = "" end + video["title"] ||= "" author = root.xpath_node(%q(div[@class="yt-lockup-content"]/div/a)) if author video["author"] = author.content video["ucid_url"] = author["href"] - else - video["author"] = "" - video["ucid_url"] = "" end + video["author"] ||= "" + video["ucid_url"] ||= "" videos << video end @@ -395,6 +391,10 @@ get "/login" do |env| referer = "/feed/subscriptions" end + if referer.size > 32 + referer = "/feed/subscriptions" + end + templated "login" end