mirror of
https://github.com/iv-org/invidious.git
synced 2026-08-16 21:10:53 -05:00
filter using regex instead of hostname
This commit is contained in:
parent
e2ea3cef78
commit
7ea63a320f
@ -80,13 +80,18 @@ def parse_description(desc, video_id : String) : String?
|
||||
length = cmd_start - index
|
||||
index += copy_string(str, iter, length)
|
||||
|
||||
if image = event.dig?("element", "type", "imageType", "image")
|
||||
source = image["sources"][0]
|
||||
url = source["url"].as_s
|
||||
# We need to copy the command's text using the iterator
|
||||
# and the special function defined above.
|
||||
cmd_content = String.build(cmd_length) do |str2|
|
||||
copy_string(str2, iter, cmd_length)
|
||||
end
|
||||
|
||||
# Check if event is an attachment AND a custom emoji using regex. Format is :<name>:
|
||||
# Members-only custom emojis have prefix :_ Built in YouTube emojis do not
|
||||
if (image = event.dig?("element", "type", "imageType", "image")) && cmd_content.matches?(/^:[^:\s]+:$/)
|
||||
# Source contains the emoji URL, height, and width
|
||||
source = image["sources"][0]
|
||||
|
||||
# Custom emoji attachment, so far URL is lh3.googleusercontent.com and yt3.googleusercontent.com
|
||||
# Filter out any description logo images, which use gstatic endpoint
|
||||
if url.includes?("googleusercontent")
|
||||
# Extract the emoji name
|
||||
label = event.dig?("element", "properties", "accessibilityProperties", "label").try &.as_s || ""
|
||||
|
||||
@ -94,7 +99,7 @@ def parse_description(desc, video_id : String) : String?
|
||||
str << %(<img class="channel-emoji" alt=")
|
||||
str << HTML.escape(label)
|
||||
str << %(" src="/ggpht)
|
||||
str << URI.parse(url).request_target
|
||||
str << URI.parse(url = source["url"].as_s).request_target
|
||||
str << %(" title=")
|
||||
str << HTML.escape(label)
|
||||
str << %(" width=")
|
||||
@ -103,17 +108,8 @@ def parse_description(desc, video_id : String) : String?
|
||||
str << source["height"]?.to_s
|
||||
str << %(" />)
|
||||
|
||||
# Use String::Builder.new to NOT append emoji text to final HTML output
|
||||
index += copy_string(String::Builder.new, iter, cmd_length)
|
||||
end
|
||||
|
||||
index += cmd_length
|
||||
else
|
||||
# We need to copy the command's text using the iterator
|
||||
# and the special function defined above.
|
||||
cmd_content = String.build(cmd_length) do |str2|
|
||||
copy_string(str2, iter, cmd_length)
|
||||
end
|
||||
|
||||
link = cmd_content
|
||||
if on_tap = event.dig?("onTap", "innertubeCommand")
|
||||
link = parse_link_endpoint(on_tap, cmd_content, video_id)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user