lumiere 0.0.8 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/fetcher.rb +33 -0
- data/lib/lumiere/version.rb +1 -1
- data/lib/lumiere.rb +1 -0
- data/lib/playlist.rb +2 -3
- data/lib/provider/dailymotion/dailymotion.rb +84 -0
- data/lib/provider/dailymotion/representer.rb +16 -0
- data/lib/provider/vimeo/representer.rb +1 -1
- data/lib/provider/vimeo/vimeo.rb +10 -4
- data/lib/provider/vimeoplaylist/vimeoplaylist.rb +64 -41
- data/lib/provider/youtube/youtube.rb +17 -21
- data/lib/provider/youtubeplaylist/representer.rb +1 -1
- data/lib/provider/youtubeplaylist/youtubeplaylist.rb +25 -27
- data/lib/provider.rb +1 -7
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 62fa0f81be349c04c0c59893fa3933f82d96b802
|
4
|
+
data.tar.gz: 6cef7cfa92eb369e2400b529ff041f6fb209642e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9047d106b199f42e6b98c47801219421d9207df90914807f55d2c1a12a90ba2ea476461ddced51c6af279c001bb373ef42796f5d51e2d989ccc1fd289576491e
|
7
|
+
data.tar.gz: 4b8ccafdef4ee51c51374fa0211719b323e9a152ab09726ab9003c199bfa5d6d7b2b2c703bdb1e077a9ad6e8703aad8344d3543fbd42a7d18c33528d3d0dc166
|
data/lib/fetcher.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
|
3
|
+
module Lumiere
|
4
|
+
class Fetcher
|
5
|
+
|
6
|
+
def initialize(context)
|
7
|
+
@api_url = context.api_url
|
8
|
+
@unpack_into = context.unpack_into
|
9
|
+
end
|
10
|
+
|
11
|
+
def remote_attributes
|
12
|
+
unless request_hash[@api_url]
|
13
|
+
request_hash[@api_url] = unpack
|
14
|
+
end
|
15
|
+
request_hash[@api_url]
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def request_hash
|
21
|
+
@request_hash ||= {}
|
22
|
+
end
|
23
|
+
|
24
|
+
def unpack
|
25
|
+
@unpack_into.from_json(raw_response)
|
26
|
+
end
|
27
|
+
|
28
|
+
def raw_response
|
29
|
+
open(@api_url).read
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
data/lib/lumiere/version.rb
CHANGED
data/lib/lumiere.rb
CHANGED
data/lib/playlist.rb
CHANGED
@@ -0,0 +1,84 @@
|
|
1
|
+
module Lumiere
|
2
|
+
class Dailymotion < Provider
|
3
|
+
attr_accessor :url
|
4
|
+
|
5
|
+
USEABLE = ['www.dailymotion.com', 'dailymotion.com']
|
6
|
+
|
7
|
+
def self.useable?(url)
|
8
|
+
uri = URISchemeless.parse(url)
|
9
|
+
USEABLE.include?(uri.host)
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(url)
|
13
|
+
@url = url
|
14
|
+
end
|
15
|
+
|
16
|
+
def provider
|
17
|
+
"Dailymotion"
|
18
|
+
end
|
19
|
+
|
20
|
+
def video_id
|
21
|
+
@video_id ||= calculate_video_id
|
22
|
+
end
|
23
|
+
|
24
|
+
def api_url
|
25
|
+
"https://api.dailymotion.com/video/#{video_id}?fields=id,title,description,duration,created_time,url,thumbnail_720_url,thumbnail_240_url,thumbnail_60_url"
|
26
|
+
end
|
27
|
+
|
28
|
+
def embed_url
|
29
|
+
"http://www.dailymotion.com/embed/video/#{video_id}"
|
30
|
+
end
|
31
|
+
|
32
|
+
def embed_code
|
33
|
+
"<iframe frameborder=\"0\" src=\"//www.dailymotion.com/embed/video/#{video_id}\" allowfullscreen></iframe>"
|
34
|
+
end
|
35
|
+
|
36
|
+
def title
|
37
|
+
fetch.title
|
38
|
+
end
|
39
|
+
|
40
|
+
def description
|
41
|
+
fetch.description
|
42
|
+
end
|
43
|
+
|
44
|
+
def duration
|
45
|
+
fetch.duration
|
46
|
+
end
|
47
|
+
|
48
|
+
def upload_date
|
49
|
+
fetch.upload_date
|
50
|
+
end
|
51
|
+
|
52
|
+
def thumbnail_small
|
53
|
+
fetch.thumbnail_small
|
54
|
+
end
|
55
|
+
|
56
|
+
def thumbnail_medium
|
57
|
+
fetch.thumbnail_medium
|
58
|
+
end
|
59
|
+
|
60
|
+
def thumbnail_large
|
61
|
+
fetch.thumbnail_large
|
62
|
+
end
|
63
|
+
|
64
|
+
def unpack_into
|
65
|
+
struct = OpenStruct.new
|
66
|
+
struct.extend(DailymotionVideoRepresenter)
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def fetch
|
72
|
+
@fetch ||= Fetcher.new(self).remote_attributes
|
73
|
+
end
|
74
|
+
|
75
|
+
def calculate_video_id
|
76
|
+
uri = URISchemeless.parse(url)
|
77
|
+
uri.path.gsub!('/embed/video/', '')
|
78
|
+
uri.path.gsub!('/video/', '')
|
79
|
+
uri.path.delete!('/')
|
80
|
+
uri.path.split('_')[0]
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Lumiere
|
2
|
+
module DailymotionVideoRepresenter
|
3
|
+
include Representable::JSON
|
4
|
+
include Representable::Coercion
|
5
|
+
|
6
|
+
property :video_id, as: :id, type: String
|
7
|
+
property :title
|
8
|
+
property :description
|
9
|
+
property :duration, type: Integer
|
10
|
+
property :upload_date, as: :created_time, type: DateTime
|
11
|
+
property :thumbnail_small, as: :thumbnail_60_url
|
12
|
+
property :thumbnail_medium, as: :thumbnail_240_url
|
13
|
+
property :thumbnail_large, as: :thumbnail_720_url
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
data/lib/provider/vimeo/vimeo.rb
CHANGED
@@ -9,12 +9,13 @@ class Vimeo < Provider
|
|
9
9
|
USEABLE.include?(uri.host)
|
10
10
|
end
|
11
11
|
|
12
|
-
def self.new_from_video_id(video_id)
|
13
|
-
new("http://vimeo.com/#{video_id}")
|
12
|
+
def self.new_from_video_id(video_id, fetched=nil)
|
13
|
+
new("http://vimeo.com/#{video_id}", fetched)
|
14
14
|
end
|
15
15
|
|
16
|
-
def initialize(url)
|
16
|
+
def initialize(url, fetched=nil)
|
17
17
|
@url = url
|
18
|
+
@fetched = fetched
|
18
19
|
end
|
19
20
|
|
20
21
|
def provider
|
@@ -65,10 +66,15 @@ class Vimeo < Provider
|
|
65
66
|
fetch.thumbnail_large
|
66
67
|
end
|
67
68
|
|
69
|
+
def unpack_into
|
70
|
+
struct = []
|
71
|
+
struct.extend(VimeoVideosRepresenter)
|
72
|
+
end
|
73
|
+
|
68
74
|
private
|
69
75
|
|
70
76
|
def fetch
|
71
|
-
@fetch ||=
|
77
|
+
@fetch ||= Fetcher.new(self).remote_attributes[0]
|
72
78
|
end
|
73
79
|
|
74
80
|
def calculate_video_id
|
@@ -3,7 +3,7 @@ class VimeoPlaylist < Provider
|
|
3
3
|
attr_accessor :url
|
4
4
|
|
5
5
|
USEABLE = ['vimeo.com', 'player.vimeo.com', 'www.vimeo.com']
|
6
|
-
|
6
|
+
RESULTS_PER_REQUEST = 20
|
7
7
|
|
8
8
|
def self.useable?(url)
|
9
9
|
uri = URISchemeless.parse(url)
|
@@ -37,71 +37,46 @@ class VimeoPlaylist < Provider
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def title
|
40
|
-
fetch
|
41
|
-
@title
|
40
|
+
fetch.title
|
42
41
|
end
|
43
42
|
|
44
43
|
def description
|
45
|
-
fetch
|
46
|
-
@description
|
44
|
+
fetch.description
|
47
45
|
end
|
48
46
|
|
49
47
|
def upload_date
|
50
|
-
fetch
|
51
|
-
@upload_date
|
48
|
+
fetch.upload_date
|
52
49
|
end
|
53
50
|
|
54
51
|
def thumbnail_small
|
55
|
-
fetch
|
56
|
-
@thumbnail_small
|
52
|
+
fetch.thumbnail_small
|
57
53
|
end
|
58
54
|
|
59
55
|
def thumbnail_medium
|
60
|
-
fetch
|
61
|
-
@thumbnail_medium
|
56
|
+
fetch.thumbnail_medium
|
62
57
|
end
|
63
58
|
|
64
59
|
def thumbnail_large
|
65
|
-
fetch
|
66
|
-
@thumbnail_large
|
60
|
+
fetch.thumbnail_large
|
67
61
|
end
|
68
62
|
|
69
63
|
def total_videos
|
70
|
-
fetch
|
71
|
-
@total_videos
|
64
|
+
fetch.total_videos
|
72
65
|
end
|
73
66
|
|
74
|
-
def
|
75
|
-
|
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
|
67
|
+
def unpack_into
|
68
|
+
struct = OpenStruct.new
|
69
|
+
struct.extend(VimeoPlaylistRepresenter)
|
88
70
|
end
|
89
71
|
|
90
|
-
|
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)
|
72
|
+
def videos
|
73
|
+
@videos ||= VideoFetcher.new(playlist_id, total_videos).videos
|
96
74
|
end
|
97
75
|
|
98
|
-
|
99
|
-
[].extend(VimeoVideosRepresenter).from_json(raw_response_videos(page))
|
100
|
-
end
|
76
|
+
private
|
101
77
|
|
102
|
-
def
|
103
|
-
|
104
|
-
open(url).read
|
78
|
+
def fetch
|
79
|
+
@fetch ||= Fetcher.new(self).remote_attributes
|
105
80
|
end
|
106
81
|
|
107
82
|
def calculate_playlist_id
|
@@ -112,5 +87,53 @@ class VimeoPlaylist < Provider
|
|
112
87
|
uri.path
|
113
88
|
end
|
114
89
|
|
90
|
+
class VideoFetcher
|
91
|
+
RESULTS_PER_REQUEST = 20
|
92
|
+
|
93
|
+
def initialize(playlist_id, total_videos)
|
94
|
+
@playlist_id = playlist_id
|
95
|
+
@total_videos = total_videos
|
96
|
+
@page = 1
|
97
|
+
end
|
98
|
+
|
99
|
+
def videos
|
100
|
+
videos = []
|
101
|
+
page_count.times do
|
102
|
+
videos += fetched_videos
|
103
|
+
@page += 1
|
104
|
+
end
|
105
|
+
|
106
|
+
videos.map do |video|
|
107
|
+
Vimeo.new_from_video_id(video.video_id, video)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def api_url
|
112
|
+
"http://vimeo.com/api/v2/album/#{@playlist_id}/videos.json?page=#{@page}"
|
113
|
+
end
|
114
|
+
|
115
|
+
def unpack_into
|
116
|
+
struct = []
|
117
|
+
struct.extend(VimeoVideosRepresenter)
|
118
|
+
end
|
119
|
+
|
120
|
+
private
|
121
|
+
|
122
|
+
def fetched_videos
|
123
|
+
fetch
|
124
|
+
end
|
125
|
+
|
126
|
+
def fetch
|
127
|
+
Fetcher.new(self).remote_attributes
|
128
|
+
end
|
129
|
+
|
130
|
+
def page_count
|
131
|
+
page_count = Playlist.page_count(@total_videos, RESULTS_PER_REQUEST)
|
132
|
+
#VIMEO CANT DEAL WITH MORE THAN 60 RESULTS ON SIMPLE API...
|
133
|
+
page_count = 3 if page_count > 3
|
134
|
+
page_count
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
115
138
|
end
|
116
139
|
end
|
@@ -9,12 +9,13 @@ class YouTube < Provider
|
|
9
9
|
USEABLE.include?(uri.host)
|
10
10
|
end
|
11
11
|
|
12
|
-
def self.new_from_video_id(video_id)
|
12
|
+
def self.new_from_video_id(video_id, fetched=nil)
|
13
13
|
new("http://www.youtube.com/watch?v=#{video_id}")
|
14
14
|
end
|
15
15
|
|
16
|
-
def initialize(url=nil)
|
16
|
+
def initialize(url, fetched=nil)
|
17
17
|
@url = url
|
18
|
+
@fetched = fetched
|
18
19
|
end
|
19
20
|
|
20
21
|
def provider
|
@@ -38,46 +39,42 @@ class YouTube < Provider
|
|
38
39
|
end
|
39
40
|
|
40
41
|
def thumbnail_small
|
41
|
-
fetch
|
42
|
-
@thumbnails[0].url
|
42
|
+
fetch.thumbnails[0].url
|
43
43
|
end
|
44
44
|
|
45
45
|
def thumbnail_medium
|
46
|
-
fetch
|
47
|
-
@thumbnails[1].url
|
46
|
+
fetch.thumbnails[1].url
|
48
47
|
end
|
49
48
|
|
50
49
|
def thumbnail_large
|
51
|
-
fetch
|
52
|
-
@thumbnails[2].url
|
50
|
+
fetch.thumbnails[2].url
|
53
51
|
end
|
54
52
|
|
55
53
|
def title
|
56
|
-
fetch
|
57
|
-
@title
|
54
|
+
fetch.title
|
58
55
|
end
|
59
56
|
|
60
57
|
def description
|
61
|
-
fetch
|
62
|
-
@description
|
58
|
+
fetch.description
|
63
59
|
end
|
64
60
|
|
65
61
|
def duration
|
66
|
-
fetch
|
67
|
-
@duration
|
62
|
+
fetch.duration
|
68
63
|
end
|
69
64
|
|
70
65
|
def upload_date
|
71
|
-
fetch
|
72
|
-
@upload_date
|
66
|
+
fetch.upload_date
|
73
67
|
end
|
74
68
|
|
75
|
-
|
69
|
+
def unpack_into
|
70
|
+
struct = OpenStruct.new
|
71
|
+
struct.extend(YouTubeVideoEntryRepresenter)
|
72
|
+
end
|
76
73
|
|
77
|
-
|
74
|
+
private
|
78
75
|
|
79
|
-
def fetch
|
80
|
-
|
76
|
+
def fetch
|
77
|
+
@fetch ||= Fetcher.new(self).remote_attributes
|
81
78
|
end
|
82
79
|
|
83
80
|
def calculate_video_id
|
@@ -93,6 +90,5 @@ class YouTube < Provider
|
|
93
90
|
uri.path
|
94
91
|
end
|
95
92
|
end
|
96
|
-
|
97
93
|
end
|
98
94
|
end
|
@@ -3,7 +3,7 @@ class YouTubePlaylist < Provider
|
|
3
3
|
attr_accessor :url
|
4
4
|
|
5
5
|
USEABLE = ['www.youtube.com', 'youtube.com', 'youtu.be']
|
6
|
-
|
6
|
+
RESULTS_PER_REQUEST = 25
|
7
7
|
|
8
8
|
def self.useable?(url)
|
9
9
|
uri = URISchemeless.parse(url)
|
@@ -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=#{RESULTS_PER_REQUEST}"
|
29
29
|
url << "&start-index=#{@start_index}"
|
30
30
|
url << "&v=2&alt=json"
|
31
31
|
url
|
@@ -44,63 +44,61 @@ class YouTubePlaylist < Provider
|
|
44
44
|
return @videos
|
45
45
|
end
|
46
46
|
|
47
|
+
@videos = fetch.videos
|
47
48
|
#take into account the first request that calling total_results will trigger through fetch!
|
48
49
|
#todo refactor this
|
49
50
|
remaining_pages = page_count - 1
|
50
|
-
|
51
51
|
remaining_pages.times do
|
52
52
|
@start_index =+ @videos.size + 1
|
53
|
-
fetch
|
53
|
+
@videos += fetch!.videos
|
54
|
+
end
|
55
|
+
|
56
|
+
@videos.map do |video|
|
57
|
+
YouTube.new_from_video_id(video.video_id, video)
|
54
58
|
end
|
59
|
+
end
|
55
60
|
|
56
|
-
|
61
|
+
def page_count
|
62
|
+
Playlist.page_count(total_results, RESULTS_PER_REQUEST)
|
57
63
|
end
|
58
64
|
|
59
65
|
def thumbnail_small
|
60
|
-
fetch
|
61
|
-
@thumbnails[0].url
|
66
|
+
fetch.thumbnails[0].url
|
62
67
|
end
|
63
68
|
|
64
69
|
def thumbnail_medium
|
65
|
-
fetch
|
66
|
-
@thumbnails[1].url
|
70
|
+
fetch.thumbnails[1].url
|
67
71
|
end
|
68
72
|
|
69
73
|
def thumbnail_large
|
70
|
-
fetch
|
71
|
-
@thumbnails[2].url
|
74
|
+
fetch.thumbnails[2].url
|
72
75
|
end
|
73
76
|
|
74
77
|
def title
|
75
|
-
fetch
|
76
|
-
@title
|
78
|
+
fetch.title
|
77
79
|
end
|
78
80
|
|
79
81
|
def description
|
80
|
-
fetch
|
81
|
-
@description
|
82
|
+
fetch.description
|
82
83
|
end
|
83
84
|
|
84
85
|
def total_results
|
85
|
-
fetch
|
86
|
-
@total_results
|
86
|
+
fetch.total_results
|
87
87
|
end
|
88
88
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
def page_count
|
94
|
-
Playlist.page_count(total_results, MAX_RESULTS)
|
89
|
+
def unpack_into
|
90
|
+
struct = OpenStruct.new
|
91
|
+
struct.extend(YouTubePlaylistRepresenter)
|
95
92
|
end
|
96
93
|
|
97
|
-
|
98
|
-
|
99
|
-
|
94
|
+
private
|
95
|
+
|
96
|
+
def fetch
|
97
|
+
@fetch ||= fetch!
|
100
98
|
end
|
101
99
|
|
102
100
|
def fetch!
|
103
|
-
|
101
|
+
Fetcher.new(self).remote_attributes
|
104
102
|
end
|
105
103
|
|
106
104
|
def calculate_playlist_id
|
data/lib/provider.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module Lumiere
|
2
2
|
class Provider
|
3
3
|
|
4
|
-
PROVIDERS = %w(YouTubePlaylist VimeoPlaylist YouTube Vimeo)
|
4
|
+
PROVIDERS = %w(YouTubePlaylist VimeoPlaylist YouTube Vimeo Dailymotion)
|
5
5
|
PROVIDERS.each do |provider|
|
6
6
|
require_relative "provider/#{provider.downcase}/#{provider.downcase}"
|
7
7
|
require_relative "provider/#{provider.downcase}/representer"
|
@@ -84,11 +84,5 @@ module Lumiere
|
|
84
84
|
video_id == other.video_id
|
85
85
|
end
|
86
86
|
end
|
87
|
-
|
88
|
-
private
|
89
|
-
|
90
|
-
def raw_response
|
91
|
-
open(api_url).read
|
92
|
-
end
|
93
87
|
end
|
94
88
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lumiere
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Karl Entwistle
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: representable
|
@@ -130,10 +130,13 @@ extra_rdoc_files: []
|
|
130
130
|
files:
|
131
131
|
- LICENSE.txt
|
132
132
|
- lib/extended_uri.rb
|
133
|
+
- lib/fetcher.rb
|
133
134
|
- lib/lumiere.rb
|
134
135
|
- lib/lumiere/version.rb
|
135
136
|
- lib/playlist.rb
|
136
137
|
- lib/provider.rb
|
138
|
+
- lib/provider/dailymotion/dailymotion.rb
|
139
|
+
- lib/provider/dailymotion/representer.rb
|
137
140
|
- lib/provider/vimeo/representer.rb
|
138
141
|
- lib/provider/vimeo/vimeo.rb
|
139
142
|
- lib/provider/vimeoplaylist/representer.rb
|