Module: PinterestDL::Extractors::Video
- Defined in:
- lib/pinterest_dl/extractors/video.rb
Overview
Extracts the direct video URL for a pin from raw HTML.
Class Method Summary collapse
- .extract(html) ⇒ Object
- .from_content_url(html) ⇒ Object
- .from_json_ld(html) ⇒ Object
- .from_open_graph(html) ⇒ Object
- .unescape(url) ⇒ Object
Class Method Details
.extract(html) ⇒ Object
10 11 12 13 14 15 |
# File 'lib/pinterest_dl/extractors/video.rb', line 10 def extract(html) url = from_json_ld(html) || from_open_graph(html) || from_content_url(html) return nil unless url unescape(url) end |
.from_content_url(html) ⇒ Object
26 27 28 29 |
# File 'lib/pinterest_dl/extractors/video.rb', line 26 def from_content_url(html) match = html.match(/"contentUrl"\s*:\s*"([^"]+\.mp4[^"]*)"/) match && match[1] end |
.from_json_ld(html) ⇒ Object
17 18 19 |
# File 'lib/pinterest_dl/extractors/video.rb', line 17 def from_json_ld(html) PinterestDL::Extractors::JsonLd.content_url(html, 'VideoObject') end |
.from_open_graph(html) ⇒ Object
21 22 23 24 |
# File 'lib/pinterest_dl/extractors/video.rb', line 21 def from_open_graph(html) match = html.match(/<meta[^>]*property=["']og:video["'][^>]*content=["']([^"']+)["']/) match && match[1] end |
.unescape(url) ⇒ Object
31 32 33 |
# File 'lib/pinterest_dl/extractors/video.rb', line 31 def unescape(url) url.gsub('\\u002F', '/').gsub('\\', '') end |