Module: VideoInfo::Providers::YoutubeAPI
- Defined in:
- lib/video_info/providers/youtube_api.rb
Instance Method Summary collapse
- #api_key ⇒ Object
- #author ⇒ Object
- #author_thumbnail ⇒ Object
- #author_url ⇒ Object
- #available? ⇒ Boolean
- #date ⇒ Object
- #description ⇒ Object
- #duration ⇒ Object
- #keywords ⇒ Object
- #stats ⇒ Object
- #title ⇒ Object
- #view_count ⇒ Object
Instance Method Details
#api_key ⇒ Object
15 16 17 |
# File 'lib/video_info/providers/youtube_api.rb', line 15 def api_key VideoInfo.provider_api_keys[:youtube] end |
#author ⇒ Object
19 20 21 |
# File 'lib/video_info/providers/youtube_api.rb', line 19 def _video_snippet["channelTitle"] end |
#author_thumbnail ⇒ Object
23 24 25 |
# File 'lib/video_info/providers/youtube_api.rb', line 23 def _channel_snippet["thumbnails"]["default"]["url"] end |
#author_url ⇒ Object
27 28 29 30 |
# File 'lib/video_info/providers/youtube_api.rb', line 27 def channel_id = _channel_info["items"][0]["id"] "https://www.youtube.com/channel/" + channel_id end |
#available? ⇒ Boolean
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/video_info/providers/youtube_api.rb', line 4 def available? if !data["items"].empty? upload_status = data["items"][0]["status"]["uploadStatus"] upload_status != "rejected" else false end rescue VideoInfo::HttpError false end |
#date ⇒ Object
49 50 51 52 |
# File 'lib/video_info/providers/youtube_api.rb', line 49 def date return unless (published_at = _video_snippet["publishedAt"]) Time.parse(published_at, Time.now.utc) end |
#description ⇒ Object
36 37 38 |
# File 'lib/video_info/providers/youtube_api.rb', line 36 def description _video_snippet["description"] end |
#duration ⇒ Object
44 45 46 47 |
# File 'lib/video_info/providers/youtube_api.rb', line 44 def duration video_duration = _video_content_details["duration"] || 0 ISO8601::Duration.new(video_duration).to_seconds.to_i end |
#keywords ⇒ Object
40 41 42 |
# File 'lib/video_info/providers/youtube_api.rb', line 40 def keywords _video_snippet["tags"] end |
#stats ⇒ Object
58 59 60 61 |
# File 'lib/video_info/providers/youtube_api.rb', line 58 def stats return {} unless available? data["items"][0]["statistics"] end |
#title ⇒ Object
32 33 34 |
# File 'lib/video_info/providers/youtube_api.rb', line 32 def title _video_snippet["title"] end |
#view_count ⇒ Object
54 55 56 |
# File 'lib/video_info/providers/youtube_api.rb', line 54 def view_count stats["viewCount"].to_i end |