Invidious is an alternative front-end to YouTube
General cleanup
Omar Roth6a7d19163eb7
diff --git a/src/helpers.cr b/src/helpers.crindex 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)enddiff --git a/src/invidious.cr b/src/invidious.crindex 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 doconfig.api_key = CONFIG.dl_api_key.not_nil!endfilter = true- else- filter = falseend+ filter ||= false+loop dobegintop = rank_videos(PG_DB, 40, filter, YT_URL)@@ -286,9 +286,8 @@ get "/watch" do |env|if video.likes > 0 || video.dislikes > 0calculated_rating = (video.likes.to_f/(video.likes.to_f + video.dislikes.to_f) * 4 + 1)- else- calculated_rating = 0.0end+ calculated_rating ||= 0.0if 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 idid = id.content.lchop("/watch?v=")- else- id = ""end+ id ||= ""video["id"] = idtitle = root.xpath_node(%q(div[@class="yt-lockup-content"]/h3/a))if titlevideo["title"] = title.content- else- video["title"] = ""end+ video["title"] ||= ""author = root.xpath_node(%q(div[@class="yt-lockup-content"]/div/a))if authorvideo["author"] = author.contentvideo["ucid_url"] = author["href"]- else- video["author"] = ""- video["ucid_url"] = ""end+ video["author"] ||= ""+ video["ucid_url"] ||= ""videos << videoend@@ -395,6 +391,10 @@ get "/login" do |env|referer = "/feed/subscriptions"end+ if referer.size > 32+ referer = "/feed/subscriptions"+ end+templated "login"end