summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamantaz Fox <coding@samantaz.fr>2021-10-18 16:14:37 +0200
committerSamantaz Fox <coding@samantaz.fr>2021-10-18 16:14:37 +0200
commitcb9b84f940a3cb05a35790f73c055d6a5a62ec4f (patch)
tree21f5dddc077d1d593028bff645c136cb71d56481
parent33d9be0ffb6bad28eb2f624aec4a7ba8f9a1795c (diff)
downloadinvidious-cb9b84f940a3cb05a35790f73c055d6a5a62ec4f.tar.gz
invidious-cb9b84f940a3cb05a35790f73c055d6a5a62ec4f.tar.bz2
invidious-cb9b84f940a3cb05a35790f73c055d6a5a62ec4f.zip
Move 'extract_text()' to 'extractors_utils.cr'
-rw-r--r--src/invidious/yt_backend/extractors.cr31
-rw-r--r--src/invidious/yt_backend/extractors_utils.cr31
2 files changed, 31 insertions, 31 deletions
diff --git a/src/invidious/yt_backend/extractors.cr b/src/invidious/yt_backend/extractors.cr
index 0277d43b..8398ca8e 100644
--- a/src/invidious/yt_backend/extractors.cr
+++ b/src/invidious/yt_backend/extractors.cr
@@ -533,37 +533,6 @@ private module HelperExtractors
end
end
-# Extracts text from InnerTube response
-#
-# InnerTube can package text in three different formats
-# "runs": [
-# {"text": "something"},
-# {"text": "cont"},
-# ...
-# ]
-#
-# "SimpleText": "something"
-#
-# Or sometimes just none at all as with the data returned from
-# category continuations.
-#
-# In order to facilitate calling this function with `#[]?`:
-# A nil will be accepted. Of course, since nil cannot be parsed,
-# another nil will be returned.
-def extract_text(item : JSON::Any?) : String?
- if item.nil?
- return nil
- end
-
- if text_container = item["simpleText"]?
- return text_container.as_s
- elsif text_container = item["runs"]?
- return text_container.as_a.map(&.["text"].as_s).join("")
- else
- nil
- end
-end
-
# Parses an item from Youtube's JSON response into a more usable structure.
# The end result can either be a SearchVideo, SearchPlaylist or SearchChannel.
def extract_item(item : JSON::Any, author_fallback : String? = "",
diff --git a/src/invidious/yt_backend/extractors_utils.cr b/src/invidious/yt_backend/extractors_utils.cr
index b76fa09a..97cc0997 100644
--- a/src/invidious/yt_backend/extractors_utils.cr
+++ b/src/invidious/yt_backend/extractors_utils.cr
@@ -1,3 +1,34 @@
+# Extracts text from InnerTube response
+#
+# InnerTube can package text in three different formats
+# "runs": [
+# {"text": "something"},
+# {"text": "cont"},
+# ...
+# ]
+#
+# "SimpleText": "something"
+#
+# Or sometimes just none at all as with the data returned from
+# category continuations.
+#
+# In order to facilitate calling this function with `#[]?`:
+# A nil will be accepted. Of course, since nil cannot be parsed,
+# another nil will be returned.
+def extract_text(item : JSON::Any?) : String?
+ if item.nil?
+ return nil
+ end
+
+ if text_container = item["simpleText"]?
+ return text_container.as_s
+ elsif text_container = item["runs"]?
+ return text_container.as_a.map(&.["text"].as_s).join("")
+ else
+ nil
+ end
+end
+
def extract_videos(initial_data : Hash(String, JSON::Any), author_fallback : String? = nil, author_id_fallback : String? = nil)
extracted = extract_items(initial_data, author_fallback, author_id_fallback)