summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamantaz Fox <coding@samantaz.fr>2022-03-27 01:20:00 +0100
committerSamantaz Fox <coding@samantaz.fr>2022-04-03 22:28:11 +0200
commitaf029177666486d7524a7d1fae03aed91b58e556 (patch)
treee65ee6791991c84196a6b5dd78c192f937940c13
parentd93a7b315db42474aac4a8e27c3745dc4b5abdeb (diff)
downloadinvidious-af029177666486d7524a7d1fae03aed91b58e556.tar.gz
invidious-af029177666486d7524a7d1fae03aed91b58e556.tar.bz2
invidious-af029177666486d7524a7d1fae03aed91b58e556.zip
Code cleanup
-rw-r--r--.ameba.yml4
-rw-r--r--spec/spec_helper.cr2
-rw-r--r--src/invidious/exceptions.cr8
-rw-r--r--src/invidious/search.cr75
-rw-r--r--src/invidious/search/ctoken.cr32
5 files changed, 41 insertions, 80 deletions
diff --git a/.ameba.yml b/.ameba.yml
index 247705e8..96cbc8f0 100644
--- a/.ameba.yml
+++ b/.ameba.yml
@@ -77,10 +77,6 @@ Metrics/CyclomaticComplexity:
# process_video_params(query, preferences) => [20/10]
- src/invidious/videos.cr
- # produce_search_params(page, sort, ...) => [29/10]
- # process_search_query(query, page, ...) => [14/10]
- - src/invidious/search.cr
-
#src/invidious/playlists.cr:327:5
diff --git a/spec/spec_helper.cr b/spec/spec_helper.cr
index 09320750..6c492e2f 100644
--- a/spec/spec_helper.cr
+++ b/spec/spec_helper.cr
@@ -8,7 +8,7 @@ require "../src/invidious/channels/*"
require "../src/invidious/videos"
require "../src/invidious/comments"
require "../src/invidious/playlists"
-require "../src/invidious/search"
+require "../src/invidious/search/ctoken"
require "../src/invidious/trending"
require "spectator"
diff --git a/src/invidious/exceptions.cr b/src/invidious/exceptions.cr
index 490d98cd..bfaa3fd5 100644
--- a/src/invidious/exceptions.cr
+++ b/src/invidious/exceptions.cr
@@ -1,3 +1,11 @@
+# Exception used to hold the bogus UCID during a channel search.
+class ChannelSearchException < InfoException
+ getter channel : String
+
+ def initialize(@channel)
+ end
+end
+
# Exception used to hold the name of the missing item
# Should be used in all parsing functions
class BrokenTubeException < Exception
diff --git a/src/invidious/search.cr b/src/invidious/search.cr
deleted file mode 100644
index e4c21bd4..00000000
--- a/src/invidious/search.cr
+++ /dev/null
@@ -1,75 +0,0 @@
-class ChannelSearchException < InfoException
- getter channel : String
-
- def initialize(@channel)
- end
-end
-
-def produce_channel_search_continuation(ucid, query, page)
- if page <= 1
- idx = 0_i64
- else
- idx = 30_i64 * (page - 1)
- end
-
- object = {
- "80226972:embedded" => {
- "2:string" => ucid,
- "3:base64" => {
- "2:string" => "search",
- "6:varint" => 1_i64,
- "7:varint" => 1_i64,
- "12:varint" => 1_i64,
- "15:base64" => {
- "3:varint" => idx,
- },
- "23:varint" => 0_i64,
- },
- "11:string" => query,
- "35:string" => "browse-feed#{ucid}search",
- },
- }
-
- continuation = object.try { |i| Protodec::Any.cast_json(i) }
- .try { |i| Protodec::Any.from_json(i) }
- .try { |i| Base64.urlsafe_encode(i) }
- .try { |i| URI.encode_www_form(i) }
-
- return continuation
-end
-
-def process_search_query(query, page, user, region)
- # Parse legacy query
- filters, channel, search_query, subscriptions = Invidious::Search::Filters.from_legacy_filters(query)
-
- if !channel.nil? && !channel.empty?
- items = Invidious::Search::Processors.channel(search_query, page, channel)
- elsif subscriptions
- if user
- user = user.as(Invidious::User)
- items = Invidious::Search::Processors.subscriptions(query, page, user)
- else
- items = [] of ChannelVideo
- end
- else
- search_params = filters.to_yt_params(page: page)
- items = search(search_query, search_params, region)
- end
-
- # Light processing to flatten search results out of Categories.
- # They should ideally be supported in the future.
- items_without_category = [] of SearchItem | ChannelVideo
- items.each do |i|
- if i.is_a? Category
- i.contents.each do |nest_i|
- if !nest_i.is_a? Video
- items_without_category << nest_i
- end
- end
- else
- items_without_category << i
- end
- end
-
- {search_query, items_without_category, filters}
-end
diff --git a/src/invidious/search/ctoken.cr b/src/invidious/search/ctoken.cr
new file mode 100644
index 00000000..161065e0
--- /dev/null
+++ b/src/invidious/search/ctoken.cr
@@ -0,0 +1,32 @@
+def produce_channel_search_continuation(ucid, query, page)
+ if page <= 1
+ idx = 0_i64
+ else
+ idx = 30_i64 * (page - 1)
+ end
+
+ object = {
+ "80226972:embedded" => {
+ "2:string" => ucid,
+ "3:base64" => {
+ "2:string" => "search",
+ "6:varint" => 1_i64,
+ "7:varint" => 1_i64,
+ "12:varint" => 1_i64,
+ "15:base64" => {
+ "3:varint" => idx,
+ },
+ "23:varint" => 0_i64,
+ },
+ "11:string" => query,
+ "35:string" => "browse-feed#{ucid}search",
+ },
+ }
+
+ continuation = object.try { |i| Protodec::Any.cast_json(i) }
+ .try { |i| Protodec::Any.from_json(i) }
+ .try { |i| Base64.urlsafe_encode(i) }
+ .try { |i| URI.encode_www_form(i) }
+
+ return continuation
+end