mirror of
https://gitea.invidious.io/iv-org/invidious-copy-2022-04-11.git
synced 2024-08-15 00:43:26 +00:00
Move 'extract_text()' to 'extractors_utils.cr'
This commit is contained in:
parent
33d9be0ffb
commit
cb9b84f940
2 changed files with 31 additions and 31 deletions
|
@ -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? = "",
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue