Remove top page

This commit is contained in:
Omar Roth 2020-06-15 17:00:34 -05:00
parent d30a972a90
commit 4d4b6a2fa0
No known key found for this signature in database
GPG Key ID: B8254FB7EC3D37F2
5 changed files with 2 additions and 145 deletions

View File

@ -195,15 +195,6 @@ if config.statistics_enabled
end end
end end
top_videos = [] of Video
if config.top_enabled
spawn do
pull_top_videos(config, PG_DB) do |videos|
top_videos = videos
end
end
end
popular_videos = [] of ChannelVideo popular_videos = [] of ChannelVideo
spawn do spawn do
pull_popular_videos(PG_DB) do |videos| pull_popular_videos(PG_DB) do |videos|
@ -367,12 +358,6 @@ get "/" do |env|
templated "empty" templated "empty"
when "Popular" when "Popular"
templated "popular" templated "popular"
when "Top"
if config.top_enabled
templated "top"
else
templated "empty"
end
when "Trending" when "Trending"
env.redirect "/feed/trending" env.redirect "/feed/trending"
when "Subscriptions" when "Subscriptions"
@ -2123,10 +2108,6 @@ post "/preferences" do |env|
end end
config.default_user_preferences.feed_menu = admin_feed_menu config.default_user_preferences.feed_menu = admin_feed_menu
top_enabled = env.params.body["top_enabled"]?.try &.as(String)
top_enabled ||= "off"
config.top_enabled = top_enabled == "on"
captcha_enabled = env.params.body["captcha_enabled"]?.try &.as(String) captcha_enabled = env.params.body["captcha_enabled"]?.try &.as(String)
captcha_enabled ||= "off" captcha_enabled ||= "off"
config.captcha_enabled = captcha_enabled == "on" config.captcha_enabled = captcha_enabled == "on"
@ -3044,13 +3025,8 @@ end
get "/feed/top" do |env| get "/feed/top" do |env|
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = LOCALES[env.get("preferences").as(Preferences).locale]?
if config.top_enabled
templated "top"
else
env.redirect "/" env.redirect "/"
end end
end
get "/feed/popular" do |env| get "/feed/popular" do |env|
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = LOCALES[env.get("preferences").as(Preferences).locale]?
@ -4171,41 +4147,7 @@ get "/api/v1/top" do |env|
locale = LOCALES[env.get("preferences").as(Preferences).locale]? locale = LOCALES[env.get("preferences").as(Preferences).locale]?
env.response.content_type = "application/json" env.response.content_type = "application/json"
"[]"
if !config.top_enabled
error_message = {"error" => "Administrator has disabled this endpoint."}.to_json
env.response.status_code = 400
next error_message
end
JSON.build do |json|
json.array do
top_videos.each do |video|
# Top videos have much more information than provided below (adaptiveFormats, etc)
# but can be very out of date, so we only provide a subset here
json.object do
json.field "title", video.title
json.field "videoId", video.id
json.field "videoThumbnails" do
generate_thumbnails(json, video.id, config, Kemal.config)
end
json.field "lengthSeconds", video.length_seconds
json.field "viewCount", video.views
json.field "author", video.author
json.field "authorId", video.ucid
json.field "authorUrl", "/channel/#{video.ucid}"
json.field "published", video.published.to_unix
json.field "publishedText", translate(locale, "`x` ago", recode_date(video.published, locale))
json.field "description", html_to_content(video.description_html)
json.field "descriptionHtml", video.description_html
end
end
end
end
end end
get "/api/v1/channels/:ucid" do |env| get "/api/v1/channels/:ucid" do |env|

View File

@ -239,7 +239,6 @@ struct Config
hmac_key: String?, # HMAC signing key for CSRF tokens and verifying pubsub subscriptions hmac_key: String?, # HMAC signing key for CSRF tokens and verifying pubsub subscriptions
domain: String?, # Domain to be used for links to resources on the site where an absolute URL is required domain: String?, # Domain to be used for links to resources on the site where an absolute URL is required
use_pubsub_feeds: {type: Bool | Int32, default: false}, # Subscribe to channels using PubSubHubbub (requires domain, hmac_key) use_pubsub_feeds: {type: Bool | Int32, default: false}, # Subscribe to channels using PubSubHubbub (requires domain, hmac_key)
top_enabled: {type: Bool, default: true},
captcha_enabled: {type: Bool, default: true}, captcha_enabled: {type: Bool, default: true},
login_enabled: {type: Bool, default: true}, login_enabled: {type: Bool, default: true},
registration_enabled: {type: Bool, default: true}, registration_enabled: {type: Bool, default: true},
@ -276,30 +275,6 @@ struct DBConfig
}) })
end end
def rank_videos(db, n)
top = [] of {Float64, String}
db.query("SELECT id, wilson_score, published FROM videos WHERE views > 5000 ORDER BY published DESC LIMIT 1000") do |rs|
rs.each do
id = rs.read(String)
wilson_score = rs.read(Float64)
published = rs.read(Time)
# Exponential decay, older videos tend to rank lower
temperature = wilson_score * Math.exp(-0.000005*((Time.utc - published).total_minutes))
top << {temperature, id}
end
end
top.sort!
# Make hottest come first
top.reverse!
top = top.map { |a, b| b }
return top[0..n - 1]
end
def login_req(f_req) def login_req(f_req)
data = { data = {
# Unfortunately there's not much information available on `bgRequest`; part of Google's BotGuard # Unfortunately there's not much information available on `bgRequest`; part of Google's BotGuard

View File

@ -170,41 +170,6 @@ def subscribe_to_feeds(db, logger, key, config)
end end
end end
def pull_top_videos(config, db)
loop do
begin
top = rank_videos(db, 40)
rescue ex
sleep 1.minute
Fiber.yield
next
end
if top.size == 0
sleep 1.minute
Fiber.yield
next
end
videos = [] of Video
top.each do |id|
begin
videos << get_video(id, db)
rescue ex
next
end
end
yield videos
sleep 1.minute
Fiber.yield
end
end
def pull_popular_videos(db) def pull_popular_videos(db)
loop do loop do
videos = db.query_all("SELECT DISTINCT ON (ucid) * FROM channel_videos WHERE ucid IN \ videos = db.query_all("SELECT DISTINCT ON (ucid) * FROM channel_videos WHERE ucid IN \

View File

@ -227,11 +227,6 @@
<% end %> <% end %>
</div> </div>
<div class="pure-control-group">
<label for="top_enabled"><%= translate(locale, "Top enabled: ") %></label>
<input name="top_enabled" id="top_enabled" type="checkbox" <% if config.top_enabled %>checked<% end %>>
</div>
<div class="pure-control-group"> <div class="pure-control-group">
<label for="captcha_enabled"><%= translate(locale, "CAPTCHA enabled: ") %></label> <label for="captcha_enabled"><%= translate(locale, "CAPTCHA enabled: ") %></label>
<input name="captcha_enabled" id="captcha_enabled" type="checkbox" <% if config.captcha_enabled %>checked<% end %>> <input name="captcha_enabled" id="captcha_enabled" type="checkbox" <% if config.captcha_enabled %>checked<% end %>>

View File

@ -1,20 +0,0 @@
<% content_for "header" do %>
<meta name="description" content="<%= translate(locale, "An alternative front-end to YouTube") %>">
<title>
<% if env.get("preferences").as(Preferences).default_home != "Top" %>
<%= translate(locale, "Top") %> - Invidious
<% else %>
Invidious
<% end %>
</title>
<% end %>
<%= rendered "components/feed_menu" %>
<div class="pure-g">
<% top_videos.each_slice(4) do |slice| %>
<% slice.each do |item| %>
<%= rendered "components/item" %>
<% end %>
<% end %>
</div>