Module: VideoInfo::Providers::YoutubeScraper
- Defined in:
- lib/video_info/providers/youtube_scraper.rb
Constant Summary collapse
- BASE_URL =
"https://www.youtube.com"
- CHANNEL_URL =
"#{BASE_URL}/channel/"
- THUMB_DEFAULT_SIZE =
88
Instance Method Summary collapse
- #author ⇒ Object
- #author_thumbnail ⇒ Object
- #author_url ⇒ Object
- #available? ⇒ Boolean
- #channel_id ⇒ Object
- #date ⇒ Object
- #description ⇒ Object
- #duration ⇒ Object
- #keywords ⇒ Object
- #stats ⇒ Object
- #title ⇒ Object
- #view_count ⇒ Object
Instance Method Details
#author ⇒ Object
21 22 23 |
# File 'lib/video_info/providers/youtube_scraper.rb', line 21 def (, "og:title") end |
#author_thumbnail ⇒ Object
25 26 27 28 29 |
# File 'lib/video_info/providers/youtube_scraper.rb', line 25 def image_hq_url = (, "og:image") resize_thumb(image_hq_url, THUMB_DEFAULT_SIZE) end |
#author_url ⇒ Object
39 40 41 |
# File 'lib/video_info/providers/youtube_scraper.rb', line 39 def URI.join(CHANNEL_URL, channel_id).to_s end |
#available? ⇒ Boolean
11 12 13 |
# File 'lib/video_info/providers/youtube_scraper.rb', line 11 def available? !!title end |
#channel_id ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/video_info/providers/youtube_scraper.rb', line 31 def channel_id # NOTE the previous implementation, based on itemprop_node_value("channelId"), # does not work well, probably due to some YouTube change page_content = data.to_s matches = page_content.match(/"channelId":"([a-zA-Z0-9_-]+)"/) matches[1] if matches end |
#date ⇒ Object
15 16 17 18 19 |
# File 'lib/video_info/providers/youtube_scraper.rb', line 15 def date date = itemprop_node_value("datePublished") Time.parse(date) if date end |
#description ⇒ Object
43 44 45 |
# File 'lib/video_info/providers/youtube_scraper.rb', line 43 def description (, "og:description") end |
#duration ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/video_info/providers/youtube_scraper.rb', line 47 def duration duration = itemprop_node_value("duration") if duration ISO8601::Duration.new(duration).to_seconds.to_i else 0 end end |
#keywords ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/video_info/providers/youtube_scraper.rb', line 57 def keywords return unless available? value = (, "keywords") value&.split(", ") end |
#stats ⇒ Object
74 75 76 77 78 |
# File 'lib/video_info/providers/youtube_scraper.rb', line 74 def stats { "viewCount" => view_count } end |
#title ⇒ Object
65 66 67 68 |
# File 'lib/video_info/providers/youtube_scraper.rb', line 65 def title return if (, "title").empty? (, "title") end |
#view_count ⇒ Object
70 71 72 |
# File 'lib/video_info/providers/youtube_scraper.rb', line 70 def view_count itemprop_node_value("interactionCount").to_i end |