Module: VideoInfo::Providers::YoutubeAPI

Defined in:
lib/video_info/providers/youtube_api.rb

Instance Method Summary collapse

Instance Method Details

#api_keyObject



15
16
17
# File 'lib/video_info/providers/youtube_api.rb', line 15

def api_key
  VideoInfo.provider_api_keys[:youtube]
end

#authorObject



19
20
21
# File 'lib/video_info/providers/youtube_api.rb', line 19

def author
  _video_snippet["channelTitle"]
end

#author_thumbnailObject



23
24
25
# File 'lib/video_info/providers/youtube_api.rb', line 23

def author_thumbnail
  _channel_snippet["thumbnails"]["default"]["url"]
end

#author_urlObject



27
28
29
30
# File 'lib/video_info/providers/youtube_api.rb', line 27

def author_url
  channel_id = _channel_info["items"][0]["id"]
  "https://www.youtube.com/channel/" + channel_id
end

#available?Boolean

Returns:

  • (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

#dateObject



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

#descriptionObject



36
37
38
# File 'lib/video_info/providers/youtube_api.rb', line 36

def description
  _video_snippet["description"]
end

#durationObject



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

#keywordsObject



40
41
42
# File 'lib/video_info/providers/youtube_api.rb', line 40

def keywords
  _video_snippet["tags"]
end

#statsObject



58
59
60
61
# File 'lib/video_info/providers/youtube_api.rb', line 58

def stats
  return {} unless available?
  data["items"][0]["statistics"]
end

#titleObject



32
33
34
# File 'lib/video_info/providers/youtube_api.rb', line 32

def title
  _video_snippet["title"]
end

#view_countObject



54
55
56
# File 'lib/video_info/providers/youtube_api.rb', line 54

def view_count
  stats["viewCount"].to_i
end