summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsyeopite <syeopite@syeopite.dev>2021-06-28 23:11:04 -0700
committersyeopite <syeopite@syeopite.dev>2021-09-24 21:07:07 -0700
commitbe1a43a3377c543b84fd9bd534fd2033b7223e62 (patch)
treee4739d777a6527bc5de6dbe065a9dd4a269a167b
parentabca8f7a7ca043035459abce35d334013a71e957 (diff)
downloadinvidious-be1a43a3377c543b84fd9bd534fd2033b7223e62.tar.gz
invidious-be1a43a3377c543b84fd9bd534fd2033b7223e62.tar.bz2
invidious-be1a43a3377c543b84fd9bd534fd2033b7223e62.zip
Manually extract category refactor from 1b569bbc99207cae7c20aa285f42477ae361dd30
Also fixes some errors caused by cherry-picking
-rw-r--r--spec/helpers_spec.cr1
-rw-r--r--src/invidious/helpers/extractors.cr43
-rw-r--r--src/invidious/helpers/serialized_yt_data.cr4
-rw-r--r--src/invidious/search.cr2
-rw-r--r--src/invidious/videos.cr2
5 files changed, 11 insertions, 41 deletions
diff --git a/spec/helpers_spec.cr b/spec/helpers_spec.cr
index ada5b28f..b17c8d73 100644
--- a/spec/helpers_spec.cr
+++ b/spec/helpers_spec.cr
@@ -6,6 +6,7 @@ require "spec"
require "yaml"
require "../src/invidious/helpers/*"
require "../src/invidious/channels/*"
+require "../src/invidious/videos"
require "../src/invidious/comments"
require "../src/invidious/playlists"
require "../src/invidious/search"
diff --git a/src/invidious/helpers/extractors.cr b/src/invidious/helpers/extractors.cr
index 48885d48..c1f7205c 100644
--- a/src/invidious/helpers/extractors.cr
+++ b/src/invidious/helpers/extractors.cr
@@ -205,7 +205,6 @@ private class CategoryParser < ItemParser
def parse(item_contents, author_fallback)
# Title extraction is a bit complicated. There are two possible routes for it
# as well as times when the title attribute just isn't sent by YT.
-
title_container = item_contents["title"]? || ""
if !title_container.is_a? String
if title = title_container["simpleText"]?
@@ -217,37 +216,7 @@ private class CategoryParser < ItemParser
title = ""
end
- auxiliary_data = {} of String => String
- browse_endpoint = item_contents["endpoint"]?.try &.["browseEndpoint"] || nil
- browse_endpoint_data = ""
- category_type = 0 # 0: Video, 1: Channels, 2: Playlist/feed, 3: trending
-
- # There's no endpoint data for video and trending category
- if !item_contents["endpoint"]?
- if !item_contents["videoId"]?
- category_type = 3
- end
- end
-
- if !browse_endpoint.nil?
- # Playlist/feed categories doesn't need the params value (nor is it even included in yt response)
- # instead it uses the browseId parameter. So if there isn't a params value we can assume the
- # category is a playlist/feed
- if browse_endpoint["params"]?
- # However, even though the channel category type returns the browse endpoint param
- # we're not going to be using it in order to preserve compatablity with Youtube.
- # and for an URL that looks cleaner
- url = item_contents["endpoint"]["commandMetadata"]["webCommandMetadata"]["url"]
- url = URI.parse(url.as_s)
- auxiliary_data["view"] = url.query_params["view"]
- auxiliary_data["shelf_id"] = url.query_params["shelf_id"]
-
- category_type = 1
- else
- browse_endpoint_data = browse_endpoint["browseId"].as_s
- category_type = 2
- end
- end
+ url = item_contents["endpoint"]?.try &.["commandMetadata"]["webCommandMetadata"]["url"].as_s
# Sometimes a category can have badges.
badges = [] of Tuple(String, String) # (Badge style, label)
@@ -279,11 +248,11 @@ private class CategoryParser < ItemParser
end
Category.new({
- title: title,
- contents: contents,
- description_html: description_html,
- browse_endpoint_data: browse_endpoint_data,
- badges: badges,
+ title: title,
+ contents: contents,
+ description_html: description_html,
+ url: url,
+ badges: badges,
})
end
end
diff --git a/src/invidious/helpers/serialized_yt_data.cr b/src/invidious/helpers/serialized_yt_data.cr
index 2db838ea..61356555 100644
--- a/src/invidious/helpers/serialized_yt_data.cr
+++ b/src/invidious/helpers/serialized_yt_data.cr
@@ -230,8 +230,8 @@ class Category
include DB::Serializable
property title : String
- property contents : Array(SearchItem)
- property browse_endpoint_data : String?
+ property contents : Array(SearchItem) | Array(Video)
+ property url : String?
property description_html : String
property badges : Array(Tuple(String, String))?
diff --git a/src/invidious/search.cr b/src/invidious/search.cr
index adf079f3..d95d802e 100644
--- a/src/invidious/search.cr
+++ b/src/invidious/search.cr
@@ -247,5 +247,5 @@ def process_search_query(query, page, user, region)
end
end
- {search_query, items_without_category.size, items_without_category, url_params}
+ {search_query, items_without_category.size, items_without_category, operators}
end
diff --git a/src/invidious/videos.cr b/src/invidious/videos.cr
index d9c07142..0e6bd77c 100644
--- a/src/invidious/videos.cr
+++ b/src/invidious/videos.cr
@@ -275,7 +275,7 @@ struct Video
end
end
- def to_json(locale, json : JSON::Builder)
+ def to_json(locale : Hash(String, JSON::Any), json : JSON::Builder)
json.object do
json.field "type", "video"