Module: PinterestDL::Extractors::Video
- Defined in:
- lib/pinterest_dl/extractors/video.rb
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
9 10 11 12 13 14 |
# File 'lib/pinterest_dl/extractors/video.rb', line 9 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
25 26 27 28 |
# File 'lib/pinterest_dl/extractors/video.rb', line 25 def from_content_url(html) match = html.match(/"contentUrl"\s*:\s*"([^"]+\.mp4[^"]*)"/) match && match[1] end |
.from_json_ld(html) ⇒ Object
16 17 18 |
# File 'lib/pinterest_dl/extractors/video.rb', line 16 def from_json_ld(html) PinterestDL::Extractors::JsonLd.content_url(html, 'VideoObject') end |
.from_open_graph(html) ⇒ Object
20 21 22 23 |
# File 'lib/pinterest_dl/extractors/video.rb', line 20 def from_open_graph(html) match = html.match(/<meta[^>]*property=["']og:video["'][^>]*content=["']([^"']+)["']/) match && match[1] end |
.unescape(url) ⇒ Object
30 31 32 |
# File 'lib/pinterest_dl/extractors/video.rb', line 30 def unescape(url) url.gsub('\\u002F', '/').gsub('\\', '') end |