Module: SourceMonitor::Items::ItemCreator::EntryParser::MediaExtraction
- Included in:
- SourceMonitor::Items::ItemCreator::EntryParser
- Defined in:
- lib/source_monitor/items/item_creator/entry_parser/media_extraction.rb
Instance Method Summary collapse
Instance Method Details
#extract_enclosures ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/source_monitor/items/item_creator/entry_parser/media_extraction.rb', line 8 def extract_enclosures enclosures = [] if entry.respond_to?(:enclosure_nodes) Array(entry.enclosure_nodes).each do |node| url = string_or_nil(node&.url) next if url.blank? enclosures << { "url" => url, "type" => string_or_nil(node&.type), "length" => safe_integer(node&.length), "source" => "rss_enclosure" }.compact end end if atom_entry? && entry.respond_to?(:link_nodes) Array(entry.link_nodes).each do |link| next unless string_or_nil(link&.rel)&.downcase == "enclosure" url = string_or_nil(link&.href) next if url.blank? enclosures << { "url" => url, "type" => string_or_nil(link&.type), "length" => safe_integer(link&.length), "source" => "atom_link" }.compact end end if json_entry? && entry.respond_to?(:json) && entry.json Array(entry.json["attachments"]).each do || url = string_or_nil(["url"]) next if url.blank? enclosures << { "url" => url, "type" => string_or_nil(["mime_type"]), "length" => safe_integer(["size_in_bytes"]), "duration" => safe_integer(["duration_in_seconds"]), "title" => string_or_nil(["title"]), "source" => "json_feed_attachment" }.compact end end enclosures.uniq end |
#extract_media_content ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/source_monitor/items/item_creator/entry_parser/media_extraction.rb', line 69 def extract_media_content contents = [] if entry.respond_to?(:media_content_nodes) Array(entry.media_content_nodes).each do |node| url = string_or_nil(node&.url) next if url.blank? contents << { "url" => url, "type" => string_or_nil(node&.type), "medium" => string_or_nil(node&.medium), "height" => safe_integer(node&.height), "width" => safe_integer(node&.width), "file_size" => safe_integer(node&.file_size), "duration" => safe_integer(node&.duration), "expression" => string_or_nil(node&.expression) }.compact end end contents.uniq end |
#extract_media_thumbnail_url ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/source_monitor/items/item_creator/entry_parser/media_extraction.rb', line 60 def extract_media_thumbnail_url if entry.respond_to?(:media_thumbnail_nodes) thumbnail = Array(entry.media_thumbnail_nodes).find { |node| string_or_nil(node&.url).present? } return string_or_nil(thumbnail&.url) if thumbnail end string_or_nil(entry.image) if entry.respond_to?(:image) end |