Module: PinterestDL::Extractors::JsonLd
- Defined in:
- lib/pinterest_dl/extractors/video.rb
Class Method Summary collapse
Class Method Details
.content_url(html, type) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/pinterest_dl/extractors/video.rb', line 39 def content_url(html, type) html.to_s.scan(%r{<script[^>]*type=["']application/ld\+json["'][^>]*>(.*?)</script>}m).each do |(raw)| data = safe_parse(raw) next unless data data = data[0] if data.is_a?(Array) && !data.empty? next unless data.is_a?(Hash) return data['contentUrl'] if data['@type'] == type && data['contentUrl'] end nil end |
.safe_parse(raw) ⇒ Object
52 53 54 55 56 |
# File 'lib/pinterest_dl/extractors/video.rb', line 52 def safe_parse(raw) JSON.parse(raw) rescue JSON::ParserError nil end |