Skip to content

Instantly share code, notes, and snippets.

@SpiceMan
Created July 12, 2020 13:25
Show Gist options
  • Save SpiceMan/bdc4785035efcdd54bddf72668c7f41b to your computer and use it in GitHub Desktop.
Save SpiceMan/bdc4785035efcdd54bddf72668c7f41b to your computer and use it in GitHub Desktop.
diff --git a/IRC/plugins/URL/URL.rb b/IRC/plugins/URL/URL.rb
index 7511bb8..be5b2f3 100644
--- a/IRC/plugins/URL/URL.rb
+++ b/IRC/plugins/URL/URL.rb
@@ -120,6 +120,8 @@ accept either index (1 is the most recent one) or substring of the desired URL",
text = nil
fetch_by_uri(uri) do |result|
+ # ZZZ. Net::HTTPResponse.uri only has the uri if the request used an URI instance. (why not ducktype, ffs?)
+ result['uri'] = uri
text, _ = format_http_info(result)
end
@@ -141,10 +143,23 @@ accept either index (1 is the most recent one) or substring of the desired URL",
doc = html_to_nokogiri(result)
return [] unless doc
- text_node = doc.css('title')[0]
- return [] unless text_node
+ title = nil
- title = text_node.text.chomp
+ # Youtube started setting the title dynamically with JS instead of just the HTML tag
+ # Steal it from a meta HTML tag for twitter
+ if Addressable::URI.parse(result['uri']).host =~ /^(www\.)?youtu(\.be|be\.com)/;
+ title_meta = doc.css('meta[name="twitter:title"]')
+
+ return [] unless title_meta
+
+ title = title_meta.attr("content").value.chomp
+ else
+ text_node = doc.css('title')[0]
+
+ return [] unless text_node
+
+ title = text_node.text.chomp
+ end
title.gsub!(/[ \t\n\f\r]+/, ' ')
title.strip!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment