ぼざクリタグ広場 https://hub.nizika.monster
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

30 lines
750 B

  1. module Youtube
  2. class VideoItem
  3. attr_reader :id, :title, :channel_id, :published_at, :thumbnail_url, :raw_tags
  4. def initialize item
  5. snippet = item.fetch('snippet')
  6. @id = item.fetch('id')
  7. @title = snippet['title']
  8. @channel_id = snippet['channelId']
  9. @published_at = Time.iso8601(snippet['publishedAt'])
  10. @thumbnail_url = pick_thumbnail(snippet['thumbnails'] || { })
  11. @raw_tags = snippet['tags'] || []
  12. end
  13. def url = "https://www.youtube.com/watch?v=#{ @id }"
  14. private
  15. def pick_thumbnail thumbnails
  16. ['maxres', 'standard', 'high', 'medium', 'default'].each do |key|
  17. url = thumbnails.dig(key, 'url')
  18. return url if url.present?
  19. end
  20. nil
  21. end
  22. end
  23. end