ぼざクリタグ広場 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.
 
 
 
 
 

33 lines
767 B

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