Class: Lumiere::YouTubePlaylist
- Inherits:
-
Provider
- Object
- Provider
- Lumiere::YouTubePlaylist
show all
- Defined in:
- lib/provider/youtubeplaylist/youtubeplaylist.rb
Constant Summary
collapse
- USEABLE =
['www.youtube.com', 'youtube.com', 'youtu.be']
- RESULTS_PER_REQUEST =
25
Constants inherited
from Provider
Provider::PROVIDERS
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Provider
#==, #accessible?, delegate, #duration, #upload_date, #video_id
Constructor Details
Returns a new instance of YouTubePlaylist.
13
14
15
16
|
# File 'lib/provider/youtubeplaylist/youtubeplaylist.rb', line 13
def initialize(url, opts={})
@url = url
@start_index = opts[:start_index] || 1
end
|
Instance Attribute Details
#url ⇒ Object
Returns the value of attribute url.
3
4
5
|
# File 'lib/provider/youtubeplaylist/youtubeplaylist.rb', line 3
def url
@url
end
|
Class Method Details
.useable?(url) ⇒ Boolean
8
9
10
11
|
# File 'lib/provider/youtubeplaylist/youtubeplaylist.rb', line 8
def self.useable?(url)
uri = URISchemeless.parse(url)
USEABLE.include?(uri.host) && (uri.path == '/playlist' || uri.path == '/view_play_list')
end
|
Instance Method Details
#api_url ⇒ Object
26
27
28
29
30
31
32
|
# File 'lib/provider/youtubeplaylist/youtubeplaylist.rb', line 26
def api_url
url = "http://gdata.youtube.com/feeds/api/playlists/#{playlist_id}"
url << "?max-results=#{RESULTS_PER_REQUEST}"
url << "&start-index=#{@start_index}"
url << "&v=2&alt=json"
url
end
|
#description ⇒ Object
81
82
83
|
# File 'lib/provider/youtubeplaylist/youtubeplaylist.rb', line 81
def description
fetch.description
end
|
#embed_code ⇒ Object
38
39
40
|
# File 'lib/provider/youtubeplaylist/youtubeplaylist.rb', line 38
def embed_code
"<iframe src=\"#{embed_url}\" frameborder=\"0\" allowfullscreen></iframe>"
end
|
#embed_url ⇒ Object
34
35
36
|
# File 'lib/provider/youtubeplaylist/youtubeplaylist.rb', line 34
def embed_url
"//youtube.com/embed/?list=#{playlist_id}"
end
|
#playlist_id ⇒ Object
22
23
24
|
# File 'lib/provider/youtubeplaylist/youtubeplaylist.rb', line 22
def playlist_id
@playlist_id ||= calculate_playlist_id
end
|
#provider ⇒ Object
18
19
20
|
# File 'lib/provider/youtubeplaylist/youtubeplaylist.rb', line 18
def provider
"YouTube"
end
|
#thumbnail_large ⇒ Object
73
74
75
|
# File 'lib/provider/youtubeplaylist/youtubeplaylist.rb', line 73
def thumbnail_large
fetch.thumbnails[2].url
end
|
#thumbnail_medium ⇒ Object
69
70
71
|
# File 'lib/provider/youtubeplaylist/youtubeplaylist.rb', line 69
def thumbnail_medium
fetch.thumbnails[1].url
end
|
#thumbnail_small ⇒ Object
65
66
67
|
# File 'lib/provider/youtubeplaylist/youtubeplaylist.rb', line 65
def thumbnail_small
fetch.thumbnails[0].url
end
|
#title ⇒ Object
77
78
79
|
# File 'lib/provider/youtubeplaylist/youtubeplaylist.rb', line 77
def title
fetch.title
end
|
#total_results ⇒ Object
85
86
87
|
# File 'lib/provider/youtubeplaylist/youtubeplaylist.rb', line 85
def total_results
fetch.total_results
end
|
#unpack_into ⇒ Object
89
90
91
92
|
# File 'lib/provider/youtubeplaylist/youtubeplaylist.rb', line 89
def unpack_into
struct = OpenStruct.new
struct.extend(YouTubePlaylistRepresenter)
end
|
#videos ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/provider/youtubeplaylist/youtubeplaylist.rb', line 42
def videos
if @videos && @videos.size == total_results
return @videos
end
@videos = fetch.videos
remaining_pages = page_count - 1
remaining_pages.times do
@start_index =+ @videos.size + 1
@videos += fetch!.videos
end
@videos.map do |video|
YouTube.new_from_video_id(video.video_id, video)
end
end
|