lumiere 0.0.6 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lumiere/version.rb +1 -1
- data/lib/lumiere.rb +1 -0
- data/lib/playlist.rb +9 -0
- data/lib/provider/vimeo/representer.rb +1 -0
- data/lib/provider/vimeo/vimeo.rb +4 -0
- data/lib/provider/vimeoplaylist/representer.rb +14 -0
- data/lib/provider/vimeoplaylist/vimeoplaylist.rb +116 -0
- data/lib/provider/youtube/youtube.rb +17 -10
- data/lib/provider/youtubeplaylist/youtubeplaylist.rb +30 -20
- data/lib/provider.rb +3 -3
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 181c9f99a468e59da34456795def60868712e56b
|
4
|
+
data.tar.gz: 47ea9aeab6778b32dea015e865a39730005938cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b14a9fe81e877dc06954a084e256b6cb67200f555b451ebb0f073d1714dc365d17f899f50cb9f3b9855a966857c08c6bf27cd087310eab73a2f38382a93759d0
|
7
|
+
data.tar.gz: 5bf3581d0e13ed1a0c456a8a2f1d0d05cd7351a30cd159700dacc19cfb72a8cae792b6f494887e3913691320a2b2002ea708fafe0bbd70a01dacbd6f130e311c
|
data/lib/lumiere/version.rb
CHANGED
data/lib/lumiere.rb
CHANGED
data/lib/playlist.rb
ADDED
data/lib/provider/vimeo/vimeo.rb
CHANGED
@@ -0,0 +1,14 @@
|
|
1
|
+
module Lumiere
|
2
|
+
module VimeoPlaylistRepresenter
|
3
|
+
include Representable::JSON
|
4
|
+
include Representable::Coercion
|
5
|
+
|
6
|
+
property :title
|
7
|
+
property :description
|
8
|
+
property :upload_date, type: DateTime, as: :created_on
|
9
|
+
property :thumbnail_small
|
10
|
+
property :thumbnail_medium
|
11
|
+
property :thumbnail_large
|
12
|
+
property :total_videos, type: Integer
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
module Lumiere
|
2
|
+
class VimeoPlaylist < Provider
|
3
|
+
attr_accessor :url
|
4
|
+
|
5
|
+
USEABLE = ['vimeo.com', 'player.vimeo.com', 'www.vimeo.com']
|
6
|
+
MAX_RESULTS = 20
|
7
|
+
|
8
|
+
def self.useable?(url)
|
9
|
+
uri = URISchemeless.parse(url)
|
10
|
+
return false unless USEABLE.include?(uri.host)
|
11
|
+
split_path = uri.path.split('/')
|
12
|
+
split_path.include?('album')
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(url)
|
16
|
+
@url = url
|
17
|
+
end
|
18
|
+
|
19
|
+
def provider
|
20
|
+
"Vimeo"
|
21
|
+
end
|
22
|
+
|
23
|
+
def playlist_id
|
24
|
+
@playlist_id ||= calculate_playlist_id
|
25
|
+
end
|
26
|
+
|
27
|
+
def api_url
|
28
|
+
"http://vimeo.com/api/v2/album/#{playlist_id}/info.json"
|
29
|
+
end
|
30
|
+
|
31
|
+
def embed_url
|
32
|
+
"http://player.vimeo.com/hubnut/album/#{playlist_id}"
|
33
|
+
end
|
34
|
+
|
35
|
+
def embed_code
|
36
|
+
"<iframe src=\"//player.vimeo.com/hubnut/album/#{playlist_id}?autoplay=0&byline=0&portrait=0&title=0\" frameborder=\"0\"></iframe>"
|
37
|
+
end
|
38
|
+
|
39
|
+
def title
|
40
|
+
fetch! unless @title
|
41
|
+
@title
|
42
|
+
end
|
43
|
+
|
44
|
+
def description
|
45
|
+
fetch! unless @description
|
46
|
+
@description
|
47
|
+
end
|
48
|
+
|
49
|
+
def upload_date
|
50
|
+
fetch! unless @upload_date
|
51
|
+
@upload_date
|
52
|
+
end
|
53
|
+
|
54
|
+
def thumbnail_small
|
55
|
+
fetch! unless @thumbnail_small
|
56
|
+
@thumbnail_small
|
57
|
+
end
|
58
|
+
|
59
|
+
def thumbnail_medium
|
60
|
+
fetch! unless @thumbnail_medium
|
61
|
+
@thumbnail_medium
|
62
|
+
end
|
63
|
+
|
64
|
+
def thumbnail_large
|
65
|
+
fetch! unless @thumbnail_large
|
66
|
+
@thumbnail_large
|
67
|
+
end
|
68
|
+
|
69
|
+
def total_videos
|
70
|
+
fetch! unless @total_videos
|
71
|
+
@total_videos
|
72
|
+
end
|
73
|
+
|
74
|
+
def videos
|
75
|
+
return @videos if @videos
|
76
|
+
|
77
|
+
@videos ||= []
|
78
|
+
page_count = Playlist.page_count(total_videos, MAX_RESULTS)
|
79
|
+
page_count = 3 if page_count > 3 #VIMEO CANT DEAL WITH MORE THAN 60 RESULTS ON SIMPLE API...
|
80
|
+
|
81
|
+
page_count.times.with_index(1) do |times, index|
|
82
|
+
@videos += fetch_videos(index)
|
83
|
+
end
|
84
|
+
|
85
|
+
@videos = @videos.map do |video|
|
86
|
+
Vimeo.new_from_video_id(video.id)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
private
|
91
|
+
|
92
|
+
attr_writer :title, :description, :upload_date, :thumbnail_small, :thumbnail_medium, :thumbnail_large, :total_videos
|
93
|
+
|
94
|
+
def fetch!
|
95
|
+
self.extend(VimeoPlaylistRepresenter).from_json(raw_response)
|
96
|
+
end
|
97
|
+
|
98
|
+
def fetch_videos(page=1)
|
99
|
+
[].extend(VimeoVideosRepresenter).from_json(raw_response_videos(page))
|
100
|
+
end
|
101
|
+
|
102
|
+
def raw_response_videos(page=1)
|
103
|
+
url = "http://vimeo.com/api/v2/album/#{playlist_id}/videos.json?page=#{page}"
|
104
|
+
open(url).read
|
105
|
+
end
|
106
|
+
|
107
|
+
def calculate_playlist_id
|
108
|
+
uri = URISchemeless.parse(url)
|
109
|
+
uri.path.gsub!('/hubnut/album/', '')
|
110
|
+
uri.path.gsub!('/album/', '')
|
111
|
+
uri.path.delete!('/')
|
112
|
+
uri.path
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
end
|
@@ -52,22 +52,29 @@ class YouTube < Provider
|
|
52
52
|
@thumbnails[2].url
|
53
53
|
end
|
54
54
|
|
55
|
-
|
55
|
+
def title
|
56
|
+
fetch! unless defined?(@title)
|
57
|
+
@title
|
58
|
+
end
|
56
59
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
instance_variable_get("@#{attribute}")
|
61
|
-
end
|
60
|
+
def description
|
61
|
+
fetch! unless defined?(@description)
|
62
|
+
@description
|
62
63
|
end
|
63
64
|
|
64
|
-
|
65
|
+
def duration
|
66
|
+
fetch! unless defined?(@duration)
|
67
|
+
@duration
|
68
|
+
end
|
65
69
|
|
66
|
-
|
67
|
-
|
70
|
+
def upload_date
|
71
|
+
fetch! unless defined?(@upload_date)
|
72
|
+
@upload_date
|
68
73
|
end
|
69
74
|
|
70
|
-
|
75
|
+
private
|
76
|
+
|
77
|
+
attr_writer :thumbnails, :video_id, :title, :description, :duration, :upload_date
|
71
78
|
|
72
79
|
def fetch!
|
73
80
|
self.extend(YouTubeVideoEntryRepresenter).from_json(raw_response)
|
@@ -3,6 +3,7 @@ class YouTubePlaylist < Provider
|
|
3
3
|
attr_accessor :url
|
4
4
|
|
5
5
|
USEABLE = ['www.youtube.com', 'youtube.com', 'youtu.be']
|
6
|
+
MAX_RESULTS = 25
|
6
7
|
|
7
8
|
def self.useable?(url)
|
8
9
|
uri = URISchemeless.parse(url)
|
@@ -12,7 +13,6 @@ class YouTubePlaylist < Provider
|
|
12
13
|
def initialize(url, opts={})
|
13
14
|
@url = url
|
14
15
|
@start_index = opts[:start_index] || 1
|
15
|
-
@max_results = opts[:max_results] || 25
|
16
16
|
end
|
17
17
|
|
18
18
|
def provider
|
@@ -25,7 +25,7 @@ class YouTubePlaylist < Provider
|
|
25
25
|
|
26
26
|
def api_url
|
27
27
|
url = "http://gdata.youtube.com/feeds/api/playlists/#{playlist_id}"
|
28
|
-
url << "?max-results=#{
|
28
|
+
url << "?max-results=#{MAX_RESULTS}"
|
29
29
|
url << "&start-index=#{@start_index}"
|
30
30
|
url << "&v=2&alt=json"
|
31
31
|
url
|
@@ -40,49 +40,59 @@ class YouTubePlaylist < Provider
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def videos
|
43
|
-
|
43
|
+
if @videos && @videos.size == total_results
|
44
|
+
return @videos
|
45
|
+
end
|
46
|
+
|
47
|
+
#take into account the first request that calling total_results will trigger through fetch!
|
48
|
+
#todo refactor this
|
49
|
+
remaining_pages = page_count - 1
|
44
50
|
|
45
|
-
|
51
|
+
remaining_pages.times do
|
46
52
|
@start_index =+ @videos.size + 1
|
47
53
|
fetch!
|
48
54
|
end
|
49
55
|
|
50
|
-
@
|
51
|
-
YouTube.new_from_video_id(video.video_id)
|
52
|
-
end
|
56
|
+
@videos
|
53
57
|
end
|
54
58
|
|
55
59
|
def thumbnail_small
|
56
|
-
fetch! unless
|
60
|
+
fetch! unless @thumbnails
|
57
61
|
@thumbnails[0].url
|
58
62
|
end
|
59
63
|
|
60
64
|
def thumbnail_medium
|
61
|
-
fetch! unless
|
65
|
+
fetch! unless @thumbnails
|
62
66
|
@thumbnails[1].url
|
63
67
|
end
|
64
68
|
|
65
69
|
def thumbnail_large
|
66
|
-
fetch! unless
|
70
|
+
fetch! unless @thumbnails
|
67
71
|
@thumbnails[2].url
|
68
72
|
end
|
69
73
|
|
70
|
-
|
74
|
+
def title
|
75
|
+
fetch! unless @title
|
76
|
+
@title
|
77
|
+
end
|
71
78
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
79
|
+
def description
|
80
|
+
fetch! unless @description
|
81
|
+
@description
|
82
|
+
end
|
83
|
+
|
84
|
+
def total_results
|
85
|
+
fetch! unless @total_results
|
86
|
+
@total_results
|
77
87
|
end
|
78
88
|
|
79
89
|
private
|
80
90
|
|
81
|
-
|
82
|
-
attr_writer attribute
|
83
|
-
end
|
91
|
+
attr_writer :thumbnails, :title, :description, :total_results
|
84
92
|
|
85
|
-
|
93
|
+
def page_count
|
94
|
+
Playlist.page_count(total_results, MAX_RESULTS)
|
95
|
+
end
|
86
96
|
|
87
97
|
def videos=(videos)
|
88
98
|
@videos ||= []
|
data/lib/provider.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Lumiere
|
2
2
|
class Provider
|
3
3
|
|
4
|
-
PROVIDERS = %w(YouTubePlaylist YouTube Vimeo)
|
4
|
+
PROVIDERS = %w(YouTubePlaylist VimeoPlaylist YouTube Vimeo)
|
5
5
|
PROVIDERS.each do |provider|
|
6
6
|
require_relative "provider/#{provider.downcase}/#{provider.downcase}"
|
7
7
|
require_relative "provider/#{provider.downcase}/representer"
|
@@ -80,8 +80,8 @@ module Lumiere
|
|
80
80
|
end
|
81
81
|
|
82
82
|
def ==(other)
|
83
|
-
if other.respond_to?(:
|
84
|
-
|
83
|
+
if other.respond_to?(:video_id)
|
84
|
+
video_id == other.video_id
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lumiere
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Karl Entwistle
|
@@ -132,9 +132,12 @@ files:
|
|
132
132
|
- lib/extended_uri.rb
|
133
133
|
- lib/lumiere.rb
|
134
134
|
- lib/lumiere/version.rb
|
135
|
+
- lib/playlist.rb
|
135
136
|
- lib/provider.rb
|
136
137
|
- lib/provider/vimeo/representer.rb
|
137
138
|
- lib/provider/vimeo/vimeo.rb
|
139
|
+
- lib/provider/vimeoplaylist/representer.rb
|
140
|
+
- lib/provider/vimeoplaylist/vimeoplaylist.rb
|
138
141
|
- lib/provider/youtube/representer.rb
|
139
142
|
- lib/provider/youtube/youtube.rb
|
140
143
|
- lib/provider/youtubeplaylist/representer.rb
|