module VideoInfo::Providers::YoutubeAPI
Public Instance Methods
api_key()
click to toggle source
# File lib/video_info/providers/youtube_api.rb, line 15 def api_key VideoInfo.provider_api_keys[:youtube] end
available?()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
# File lib/video_info/providers/youtube_api.rb, line 36 def description _video_snippet["description"] end
duration()
click to toggle source
# 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()
click to toggle source
# File lib/video_info/providers/youtube_api.rb, line 40 def keywords _video_snippet["tags"] end
stats()
click to toggle source
# File lib/video_info/providers/youtube_api.rb, line 58 def stats return {} unless available? data["items"][0]["statistics"] end
title()
click to toggle source
# File lib/video_info/providers/youtube_api.rb, line 32 def title _video_snippet["title"] end
view_count()
click to toggle source
# File lib/video_info/providers/youtube_api.rb, line 54 def view_count stats["viewCount"].to_i end
Private Instance Methods
_api_base()
click to toggle source
# File lib/video_info/providers/youtube_api.rb, line 65 def _api_base "www.googleapis.com" end
_api_path()
click to toggle source
# File lib/video_info/providers/youtube_api.rb, line 69 def _api_path "/youtube/v3/videos?id=#{video_id}" \ "&part=snippet,statistics,status,contentDetails&fields=" \ "items(id,snippet,statistics,status,contentDetails)&key=#{api_key}" end
_api_url()
click to toggle source
# File lib/video_info/providers/youtube_api.rb, line 75 def _api_url "https://#{_api_base}#{_api_path}" end
_channel_api_url(channel_id)
click to toggle source
# File lib/video_info/providers/youtube_api.rb, line 84 def _channel_api_url(channel_id) "https://#{_api_base}/youtube/v3/channels?part=snippet&id" \ "=#{channel_id}&key=#{api_key}" end
_channel_info()
click to toggle source
# File lib/video_info/providers/youtube_api.rb, line 89 def _channel_info channel_url = _channel_api_url(_video_snippet["channelId"]) @_channel_info ||= JSON.parse(URI.parse(channel_url).read) end
_channel_snippet()
click to toggle source
# File lib/video_info/providers/youtube_api.rb, line 94 def _channel_snippet _channel_info["items"][0]["snippet"] end
_video_content_details()
click to toggle source
# File lib/video_info/providers/youtube_api.rb, line 98 def _video_content_details return {} unless available? data["items"][0]["contentDetails"] end
_video_snippet()
click to toggle source
# File lib/video_info/providers/youtube_api.rb, line 79 def _video_snippet return {} unless available? data["items"][0]["snippet"] end
_video_thumbnail(id)
click to toggle source
# File lib/video_info/providers/youtube_api.rb, line 103 def _video_thumbnail(id) _video_entry["media$group"]["media$thumbnail"][id]["url"] end