From 66605196ad9f2a7ebc733c946f7b1c14a7b61db4 Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Sun, 3 Mar 2019 11:51:28 -0600 Subject: [PATCH] Remove "detect_language" from dependencies --- shard.yml | 4 +--- src/invidious.cr | 1 - src/invidious/helpers/helpers.cr | 41 +++----------------------------- src/invidious/jobs.cr | 11 +-------- 4 files changed, 5 insertions(+), 52 deletions(-) diff --git a/shard.yml b/shard.yml index 6f63fed2..7edab354 100644 --- a/shard.yml +++ b/shard.yml @@ -9,8 +9,6 @@ targets: main: src/invidious.cr dependencies: - detect_language: - github: detectlanguage/detectlanguage-crystal kemal: github: kemalcr/kemal pg: @@ -18,6 +16,6 @@ dependencies: sqlite3: github: crystal-lang/crystal-sqlite3 -crystal: 0.27.1 +crystal: 0.27.2 license: AGPLv3 diff --git a/src/invidious.cr b/src/invidious.cr index 5764a239..d9b88a0c 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -14,7 +14,6 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -require "detect_language" require "digest/md5" require "file_utils" require "kemal" diff --git a/src/invidious/helpers/helpers.cr b/src/invidious/helpers/helpers.cr index b63fd8bb..37d88ef8 100644 --- a/src/invidious/helpers/helpers.cr +++ b/src/invidious/helpers/helpers.cr @@ -14,8 +14,7 @@ user: String, full_refresh: Bool, # Used for crawling channels: threads should check all videos uploaded by a channel https_only: Bool?, # Used to tell Invidious it is behind a proxy, so links to resources should be https:// hmac_key: String?, # HMAC signing key for CSRF tokens - domain: String, # Domain to be used for links to resources on the site where an absolute URL is required - dl_api_key: String?, # DetectLanguage API Key (used to filter non-English results from "top" page), mostly non-functional + domain: String?, # Domain to be used for links to resources on the site where an absolute URL is required default_home: {type: String, default: "Top"}, feed_menu: {type: Array(String), default: ["Popular", "Top", "Trending"]}, top_enabled: {type: Bool, default: true}, @@ -74,7 +73,7 @@ class DenyFrame < Kemal::Handler end end -def rank_videos(db, n, filter, url) +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| @@ -95,41 +94,7 @@ def rank_videos(db, n, filter, url) top.reverse! top = top.map { |a, b| b } - if filter - language_list = [] of String - top.each do |id| - if language_list.size == n - break - else - client = make_client(url) - begin - video = get_video(id, db) - rescue ex - next - end - - if video.language - language = video.language - else - description = XML.parse(video.description) - content = [video.title, description.content].join(" ") - content = content[0, 10000] - - results = DetectLanguage.detect(content) - language = results[0].language - - db.exec("UPDATE videos SET language = $1 WHERE id = $2", language, id) - end - - if language == "en" - language_list << id - end - end - end - return language_list - else - return top[0..n - 1] - end + return top[0..n - 1] end def login_req(login_form, f_req) diff --git a/src/invidious/jobs.cr b/src/invidious/jobs.cr index cc5f85d1..d9bd78d7 100644 --- a/src/invidious/jobs.cr +++ b/src/invidious/jobs.cr @@ -154,18 +154,9 @@ def refresh_feeds(db, logger, max_threads = 1) end def pull_top_videos(config, db) - if config.dl_api_key - DetectLanguage.configure do |dl_config| - dl_config.api_key = config.dl_api_key.not_nil! - end - filter = true - end - - filter ||= false - loop do begin - top = rank_videos(db, 40, filter, YT_URL) + top = rank_videos(db, 40) rescue ex next end