dmcloud 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 +15 -0
- data/.gitignore +17 -0
- data/Gemfile +16 -0
- data/LICENSE.txt +22 -0
- data/README.md +157 -0
- data/Rakefile +52 -0
- data/VERSION +1 -0
- data/dmcloud.gemspec +78 -0
- data/lib/dm_cloud/builder/media.rb +117 -0
- data/lib/dm_cloud/media.rb +85 -0
- data/lib/dm_cloud/request.rb +43 -0
- data/lib/dm_cloud/signing.rb +189 -0
- data/lib/dm_cloud/streaming.rb +80 -0
- data/lib/dm_cloud/version.rb +3 -0
- data/lib/dm_cloud.rb +58 -0
- data/spec/dm_cloud/media_spec.rb +48 -0
- data/spec/dm_cloud/signing_spec.rb +35 -0
- data/spec/dm_cloud/streaming_spec.rb +23 -0
- data/spec/dm_cloud_spec.rb +28 -0
- data/spec/spec_helper.rb +57 -0
- data/spec/vcr_cassettes/dm_cloud/dm_cloud_streaming.yml +0 -0
- data/spec/vcr_cassettes/dm_cloud_media.yml +163 -0
- metadata +173 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MTViY2FhMmM0NzE2MGZlZjU3NGEyZTQ0NjAxNDZhNWM3ZTRhOGUyMA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZjBmY2ZiYjc1NmJiYjVhYTE4NjQ3ZjNmYjg5YmZiZjVhOTI0NDBjNQ==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
YjgyZDlkZTUwZTAwOGNlZWEwODk4NzNlMzBhMWIxYjg3NzMzOGY1ZmUxNWVl
|
10
|
+
OTViNTA5YWM4OTVhZWQxMzBkZjY5MzYwNjAxODEzNzdkZGZjZjMxNWE2ZjRj
|
11
|
+
OTViMTkwODUzZjI3MzgyNTcyMmE4MjBiOWE5NDg2OTM3ODg1OTE=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MjViOWFmYjdlMDc5ZTBjMDdlZjQwNGQ5YWU2ZTEyMmQ1ODQzY2YwMTFmNzAw
|
14
|
+
NTEwYTRkOTliYTM5Y2M1ZGI1MGY5YjQ0MDVlODVlMzhiYTczMDIwZmZlMjQz
|
15
|
+
ZmJiNTQzNzkyYTY3MGRlYmU3OWZmZDRkZmUxZDk5ZWI2YzJiMWE=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "rspec", "~> 2.8.0"
|
10
|
+
gem "rdoc", "~> 3.12"
|
11
|
+
gem "bundler"
|
12
|
+
gem "jeweler", "~> 1.8.4"
|
13
|
+
gem "rcov", ">= 0"
|
14
|
+
gem "vcr"
|
15
|
+
gem 'webmock', :git => "https://github.com/i0rek/webmock.git", :branch => "typhoeus_0.5.0"
|
16
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Jeremy Mortelette
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
# DmCloud
|
2
|
+
|
3
|
+
[](https://codeclimate.com/github/elentras/dm_cloud)
|
4
|
+
|
5
|
+
I created this gem to simplify request and responses from DailyMotion Cloud API.
|
6
|
+
With this gem, you can :
|
7
|
+
- get generated embed code as a string
|
8
|
+
- get direct access url to your files (I used this to provide video flux to TV-connected application)
|
9
|
+
- (Lists works, others on the way) create, delete, paginated lists of videos; with video informations (a/v encodings, bitrate, video lenght...)
|
10
|
+
- (I'm working on ) CRUD on videos' meta-data
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
gem 'dm_cloud', "0.0.60" #stable version
|
17
|
+
or
|
18
|
+
gem 'dm_cloud' # edge version
|
19
|
+
|
20
|
+
And then execute:
|
21
|
+
|
22
|
+
$ bundle
|
23
|
+
|
24
|
+
Or install it yourself as:
|
25
|
+
|
26
|
+
$ gem install dm_cloud
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
First, your will need to specify your :user_id, :api_key and your security level.
|
31
|
+
I used a file in `APP_ROOT/config/initializers/conf.rb`.
|
32
|
+
You can note the securitylevel, for more information about it, take a look at `lib/dm_cloud/signing.rb`.
|
33
|
+
|
34
|
+
# DAILYMOTION CLOUD SETTINGS
|
35
|
+
require 'dm_cloud'
|
36
|
+
DMC_USER_ID = 'your user id'
|
37
|
+
DMC_SECRET = 'your api key'
|
38
|
+
DMC_SECURITY_LEVEL = :none
|
39
|
+
|
40
|
+
DmCloud.configure( {
|
41
|
+
:user_key => DMC_USER_ID,
|
42
|
+
:secret_key => DMC_SECRET,
|
43
|
+
:security_level => DMC_SECURITY_LEVEL
|
44
|
+
})
|
45
|
+
|
46
|
+
Description of security levels :
|
47
|
+
|
48
|
+
* **None:**
|
49
|
+
The signed URL will be valid for everyone
|
50
|
+
* **ASNUM:**
|
51
|
+
The signed URL will only be valid for the AS of the end-user.
|
52
|
+
The ASNUM (for Autonomous System Number) stands for the network identification,
|
53
|
+
each ISP have a different ASNUM for instance.
|
54
|
+
* **IP:**
|
55
|
+
The signed URL will only be valid for the IP of the end-user.
|
56
|
+
This security level may wrongly block some users
|
57
|
+
which have their internet access load-balanced between several proxies.
|
58
|
+
This is the case in some office network or some ISPs.
|
59
|
+
* **User-Agent:**
|
60
|
+
Used in addition to one of the two former levels,
|
61
|
+
this level a limit on the exact user-agent of the end-user.
|
62
|
+
This is more secure but in some specific condition may lead to wrongly blocked users.
|
63
|
+
* **Use Once:**
|
64
|
+
The signed URL will only be usable once.
|
65
|
+
Note: should not be used with stream URLs.
|
66
|
+
* **Country:**
|
67
|
+
The URL can only be queried from specified countrie(s).
|
68
|
+
The rule can be reversed to allow all countries except some.
|
69
|
+
* **Referer:**
|
70
|
+
The URL can only be queried
|
71
|
+
if the Referer HTTP header contains a specified value.
|
72
|
+
If the URL contains a Referer header with a different value,
|
73
|
+
the request is refused. If the Referer header is missing,
|
74
|
+
the request is accepted in order to prevent from false positives as some browsers,
|
75
|
+
anti-virus or enterprise proxies may remove this header.
|
76
|
+
* **Delegate:**
|
77
|
+
This option instructs the signing algorithm
|
78
|
+
that security level information won’t be embeded into the signature
|
79
|
+
but gathered and lock at the first use.
|
80
|
+
|
81
|
+
|
82
|
+
Second part, get you embed url :
|
83
|
+
It will return a string containing the iframe with the DailyMotion Cloud player.
|
84
|
+
|
85
|
+
DmCloud::Streaming.embed('your video id looks like a secret key')
|
86
|
+
|
87
|
+
Or how to get your direct url :
|
88
|
+
It will return a string containing the direct link to your file.
|
89
|
+
|
90
|
+
DmCloud::Streaming.url('your video id', ['asset_name'], {options})
|
91
|
+
|
92
|
+
The next parts will come soon, just need some time to finish it
|
93
|
+
and create corresponding tests.
|
94
|
+
|
95
|
+
---
|
96
|
+
### Video explorer :
|
97
|
+
|
98
|
+
If you need to list your video you can use this method :
|
99
|
+
|
100
|
+
DmCloud::Media.list({:page => 1, :per_page => 10})
|
101
|
+
It will return videos information and more :
|
102
|
+
|
103
|
+
result to yaml :
|
104
|
+
|
105
|
+
'{"result": {
|
106
|
+
"list": [{
|
107
|
+
"embed_url": "http://api.DmCloud.net/player/embed/:your_id/:media_id",
|
108
|
+
"assets": {
|
109
|
+
"source": {
|
110
|
+
"status": "ready",
|
111
|
+
"video_fps": 25.0,
|
112
|
+
"file_extension": "mp4",
|
113
|
+
"video_fps_mode": "CFR",
|
114
|
+
"container": "MPEG-4",
|
115
|
+
"audio_samplerate": 44100,
|
116
|
+
"video_interlaced": false,
|
117
|
+
"video_rotation": 0.0,
|
118
|
+
"video_bitrate": 1000618,
|
119
|
+
"created": 1347641702,
|
120
|
+
"audio_nbr_channel": 2,
|
121
|
+
"download_url": "http://cdn.DmCloud.net/route/http/:your_id/:media_id/source-1347634502.mp4?filename=my_video_name-source-1347634502.mp4&auth=1351277028-3-672hcu1m-3fcab065b9bf103e70d3883aa8c657be",
|
122
|
+
"video_aspect": 1.7777777777777777,
|
123
|
+
"video_height": 576,
|
124
|
+
"audio_bitrate": 128017,
|
125
|
+
"audio_codec": "AAC LC",
|
126
|
+
"file_size": 119133958,
|
127
|
+
"duration": 839,
|
128
|
+
"video_codec": "AVC",
|
129
|
+
"video_width": 1024,
|
130
|
+
"global_bitrate": 1134696}},
|
131
|
+
"created": 1347641696,
|
132
|
+
"meta": { "title": "my video 1 title"},
|
133
|
+
"frame_ratio": 1.7740740740740739,
|
134
|
+
"id": "5053616094739936ec0006af" }],
|
135
|
+
"pages": 1,
|
136
|
+
"on_this_page": 3,
|
137
|
+
"per_page": 10,
|
138
|
+
"total": 3,
|
139
|
+
"page": 1}}'
|
140
|
+
|
141
|
+
As you can see, this give many information, you can submit a hash like this :
|
142
|
+
|
143
|
+
DmCloud::Media.list({:page => 1, :per_page => 10, :fields => {:meta => :title }, :assets => [:download_url, :created ]})
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
## Contributing
|
148
|
+
|
149
|
+
Your welcome to share and enhance this gem.
|
150
|
+
This is my first one (and not the last one) but I know some mistakes might be done by myself.
|
151
|
+
I do my best and I'm open to all ideas or comments about my work.
|
152
|
+
|
153
|
+
1. Fork it
|
154
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
155
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
156
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
157
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
gem.name = "dm_cloud"
|
17
|
+
# gem.version = DmCloud::VERSION
|
18
|
+
gem.authors = ["Jeremy Mortelette"]
|
19
|
+
gem.email = ["mortelette.jeremy@gmail.com"]
|
20
|
+
gem.description = 'This gem will simplify usage of DailyMotion Cloud API, it represent api in ruby style, with automated handler for search and upload files'
|
21
|
+
gem.summary = 'Simplify DailyMotion Cloud API usage'
|
22
|
+
gem.homepage = ""
|
23
|
+
|
24
|
+
gem.files = `git ls-files`.split($/)
|
25
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
26
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
27
|
+
gem.require_paths = ["lib"]
|
28
|
+
end
|
29
|
+
|
30
|
+
Jeweler::RubygemsDotOrgTasks.new
|
31
|
+
|
32
|
+
require 'rspec/core'
|
33
|
+
require 'rspec/core/rake_task'
|
34
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
35
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
36
|
+
end
|
37
|
+
|
38
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
39
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
40
|
+
spec.rcov = true
|
41
|
+
end
|
42
|
+
|
43
|
+
task :default => :spec
|
44
|
+
#
|
45
|
+
# Rake::RDocTask.new do |rdoc|
|
46
|
+
# version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
47
|
+
#
|
48
|
+
# rdoc.rdoc_dir = 'rdoc'
|
49
|
+
# rdoc.title = "twits #{version}"
|
50
|
+
# rdoc.rdoc_files.include('README*')
|
51
|
+
# rdoc.rdoc_files.include('lib/**/*.rb')
|
52
|
+
# end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.2.0
|
data/dmcloud.gemspec
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "dmcloud"
|
8
|
+
s.version = "1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Ritik Malhotra", "Tanooj Luthra"]
|
12
|
+
s.date = "2013-06-15"
|
13
|
+
s.description = "This gem will simplify usage of DailyMotion Cloud API. Originally authored by Jeremy Mortelette, modified by us to fix the bugs."
|
14
|
+
s.email = ["ritikmalhotra@gmail.com"]
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".gitignore",
|
21
|
+
"Gemfile",
|
22
|
+
"LICENSE.txt",
|
23
|
+
"README.md",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"dmcloud.gemspec",
|
27
|
+
"lib/dm_cloud.rb",
|
28
|
+
"lib/dm_cloud/builder/media.rb",
|
29
|
+
"lib/dm_cloud/media.rb",
|
30
|
+
"lib/dm_cloud/request.rb",
|
31
|
+
"lib/dm_cloud/signing.rb",
|
32
|
+
"lib/dm_cloud/streaming.rb",
|
33
|
+
"lib/dm_cloud/version.rb",
|
34
|
+
"spec/dm_cloud/media_spec.rb",
|
35
|
+
"spec/dm_cloud/signing_spec.rb",
|
36
|
+
"spec/dm_cloud/streaming_spec.rb",
|
37
|
+
"spec/dm_cloud_spec.rb",
|
38
|
+
"spec/spec_helper.rb",
|
39
|
+
"spec/vcr_cassettes/dm_cloud/dm_cloud_streaming.yml",
|
40
|
+
"spec/vcr_cassettes/dm_cloud_media.yml"
|
41
|
+
]
|
42
|
+
s.homepage = ""
|
43
|
+
s.require_paths = ["lib"]
|
44
|
+
s.rubygems_version = "1.8.24"
|
45
|
+
s.summary = "Simplify DailyMotion Cloud API usage"
|
46
|
+
s.test_files = ["spec/dm_cloud/media_spec.rb", "spec/dm_cloud/signing_spec.rb", "spec/dm_cloud/streaming_spec.rb", "spec/dm_cloud_spec.rb", "spec/spec_helper.rb", "spec/vcr_cassettes/dm_cloud/dm_cloud_streaming.yml", "spec/vcr_cassettes/dm_cloud_media.yml"]
|
47
|
+
|
48
|
+
if s.respond_to? :specification_version then
|
49
|
+
s.specification_version = 3
|
50
|
+
|
51
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
52
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
|
53
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
54
|
+
s.add_development_dependency(%q<bundler>, [">= 0"])
|
55
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
56
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
57
|
+
s.add_development_dependency(%q<vcr>, [">= 0"])
|
58
|
+
s.add_development_dependency(%q<webmock>, [">= 0"])
|
59
|
+
else
|
60
|
+
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
61
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
62
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
63
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
64
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
65
|
+
s.add_dependency(%q<vcr>, [">= 0"])
|
66
|
+
s.add_dependency(%q<webmock>, [">= 0"])
|
67
|
+
end
|
68
|
+
else
|
69
|
+
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
70
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
71
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
72
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
73
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
74
|
+
s.add_dependency(%q<vcr>, [">= 0"])
|
75
|
+
s.add_dependency(%q<webmock>, [">= 0"])
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
@@ -0,0 +1,117 @@
|
|
1
|
+
module DmCloud
|
2
|
+
module Builder
|
3
|
+
module Media
|
4
|
+
def self.create(url = '', assets_names = [], meta = {})
|
5
|
+
request = Hash.new
|
6
|
+
|
7
|
+
request['url'] = url
|
8
|
+
|
9
|
+
if not meta.empty?
|
10
|
+
request['meta'] = {}
|
11
|
+
request['meta']['author'] = meta[:author] if meta[:author]
|
12
|
+
request['meta']['author'] = meta[:title] if meta[:title]
|
13
|
+
end
|
14
|
+
|
15
|
+
request['assets_names'] = assets_names if not assets_names.empty?
|
16
|
+
|
17
|
+
request.rehash
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.info(media_id, assets_names = ['source'], fields = {})
|
21
|
+
raise StandardError, "missing :media_id in params" unless media_id
|
22
|
+
request = Hash.new
|
23
|
+
|
24
|
+
# the media id
|
25
|
+
request[:fields] = []
|
26
|
+
|
27
|
+
# requested media meta datas
|
28
|
+
fields[:meta] = ['title'] unless fields[:meta]
|
29
|
+
fields[:meta].each { |value| request[:fields] << "meta.#{value.to_s}" }
|
30
|
+
request[:fields] += ['id', 'created', 'embed_url', 'frame_ratio']
|
31
|
+
|
32
|
+
# the worldwide statistics on the number of views
|
33
|
+
# request['fields'] << 'stats.global.last_week' if fields[:stats][:global]
|
34
|
+
|
35
|
+
# TODO: handle statistics request per country
|
36
|
+
# fields[:stats].each { |key| request << "meta.#{key.to_s}" } if fields[:meta].present?
|
37
|
+
# request['stats'][COUNTRY_CODE][TIME_INTERVAL] : the statistics on the number of views in a specific country (eg: stats.fr.total, stats.us.last_week, etc...)
|
38
|
+
# request['extended_stats'][COUNTRY_CODE][TIME_INTERVAL]
|
39
|
+
|
40
|
+
assets_names = ['source'] if assets_names.nil?
|
41
|
+
if not fields[:assets]
|
42
|
+
request = all_assets_fields(request, assets_names)
|
43
|
+
else
|
44
|
+
assets_names.each do |name|
|
45
|
+
fields[:assets].each { |value| request[:fields] << "assets.#{name}.#{value.to_s}" }
|
46
|
+
end
|
47
|
+
end
|
48
|
+
request
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.list(page = 1, per_page = 10, fields = {})
|
52
|
+
# raise StandardError, "missing :media_id in params" unless media_id
|
53
|
+
request = Hash.new
|
54
|
+
|
55
|
+
request[:page] = page
|
56
|
+
request[:per_page] = per_page
|
57
|
+
request[:fields] = []
|
58
|
+
# requested media meta datas
|
59
|
+
fields[:meta] = ['title'] unless fields[:meta]
|
60
|
+
fields[:meta].each { |value| request[:fields] << "meta.#{value.to_s}" }
|
61
|
+
request[:fields] += ['id', 'created', 'embed_url', 'frame_ratio']
|
62
|
+
|
63
|
+
# TODO: handle global statistics request in another module
|
64
|
+
# the worldwide statistics on the number of views
|
65
|
+
# request << 'stats.global.last_week' if fields[:stats][:global]
|
66
|
+
|
67
|
+
# TODO: handle statistics request per country
|
68
|
+
# fields[:stats].each { |key| request << "meta.#{key.to_s}" } if fields[:meta].present?
|
69
|
+
# request['stats'][COUNTRY_CODE][TIME_INTERVAL] : the statistics on the number of views in a specific country (eg: stats.fr.total, stats.us.last_week, etc...)
|
70
|
+
# request['extended_stats'][COUNTRY_CODE][TIME_INTERVAL]
|
71
|
+
|
72
|
+
assets_names = ['source'] if assets_names.nil?
|
73
|
+
if not fields[:assets]
|
74
|
+
request = all_assets_fields(request, assets_names)
|
75
|
+
else
|
76
|
+
assets_names.each do |name|
|
77
|
+
fields[:assets].each { |value| request[:fields] << "assets.#{name}.#{value.to_s}" }
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
request
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
protected
|
86
|
+
# This method exclude stats, but return all information for a media (video or images)
|
87
|
+
# NOTE: This is outside the methods because : too long and recurent.
|
88
|
+
# It's also used as default if no fields params is submitted.
|
89
|
+
def self.all_assets_fields(request, assets_names)
|
90
|
+
assets_names.each do |name|
|
91
|
+
request[:fields] << "assets.#{name}.download_url"
|
92
|
+
request[:fields] << "assets.#{name}.status"
|
93
|
+
request[:fields] << "assets.#{name}.container"
|
94
|
+
request[:fields] << "assets.#{name}.duration"
|
95
|
+
request[:fields] << "assets.#{name}.global_bitrate"
|
96
|
+
request[:fields] << "assets.#{name}.video_codec"
|
97
|
+
request[:fields] << "assets.#{name}.video_width"
|
98
|
+
request[:fields] << "assets.#{name}.video_height"
|
99
|
+
request[:fields] << "assets.#{name}.video_bitrate"
|
100
|
+
request[:fields] << "assets.#{name}.video_rotation"
|
101
|
+
request[:fields] << "assets.#{name}.video_fps"
|
102
|
+
request[:fields] << "assets.#{name}.video_fps_mode"
|
103
|
+
request[:fields] << "assets.#{name}.video_aspect"
|
104
|
+
request[:fields] << "assets.#{name}.video_interlaced"
|
105
|
+
request[:fields] << "assets.#{name}.audio_codec"
|
106
|
+
request[:fields] << "assets.#{name}.audio_bitrate"
|
107
|
+
request[:fields] << "assets.#{name}.audio_nbr_channel"
|
108
|
+
request[:fields] << "assets.#{name}.audio_samplerate"
|
109
|
+
request[:fields] << "assets.#{name}.created"
|
110
|
+
request[:fields] << "assets.#{name}.file_extension"
|
111
|
+
request[:fields] << "assets.#{name}.file_size"
|
112
|
+
end
|
113
|
+
request
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'dm_cloud/builder/media'
|
2
|
+
|
3
|
+
module DmCloud
|
4
|
+
class Media
|
5
|
+
# Creates a new media object.
|
6
|
+
# This method can either create an empty media object
|
7
|
+
# or also download a media with the url paramater
|
8
|
+
# and use it as the source to encode the ASSET_NAME listed in assets_names
|
9
|
+
# Params :
|
10
|
+
# args:
|
11
|
+
# url: SCHEME://USER:PASSWORD@HOSTNAME/MY/PATH/FILENAME.EXTENSION (could be ftp or http)
|
12
|
+
# author: an author name
|
13
|
+
# title: a title for the film
|
14
|
+
# assets_names: (Array) – (optional) the list of ASSET_NAME you want to transcode,
|
15
|
+
# when you set this parameter you must also set the url parameter
|
16
|
+
# Return :
|
17
|
+
# media_id: return the media id of the object
|
18
|
+
def self.create(options)
|
19
|
+
call_type = "media.create"
|
20
|
+
|
21
|
+
params = {
|
22
|
+
:call => call_type,
|
23
|
+
args: Builder::Media.create(options)
|
24
|
+
}
|
25
|
+
DmCloud.config[:auto_call] == true ? DmCloud::Request.execute(call_type, params) : {call: call_type, params: params}
|
26
|
+
end
|
27
|
+
|
28
|
+
# Delete a media object with all its associated assets.
|
29
|
+
#
|
30
|
+
# Parameters:
|
31
|
+
# id (media ID) – (required) the id of the media object you want to delete.
|
32
|
+
# Return :
|
33
|
+
# Nothing
|
34
|
+
def self.delete(media_id)
|
35
|
+
raise StandardError, "missing :media_id in params" unless media_id
|
36
|
+
call_type = "media.delete"
|
37
|
+
|
38
|
+
params = {
|
39
|
+
:call => call_type,
|
40
|
+
args: { id: media_id}
|
41
|
+
}
|
42
|
+
DmCloud.config[:auto_call] == true ? DmCloud::Request.execute(call_type, params) : {call: call_type, params: params}
|
43
|
+
end
|
44
|
+
|
45
|
+
# Gives information about a given media object.
|
46
|
+
#
|
47
|
+
# Params :
|
48
|
+
# media_id: (media ID) – (required) the id of the new media object.
|
49
|
+
# fields (Array) – (required) the list of fields to retrieve.
|
50
|
+
# Returns:
|
51
|
+
# a multi-level structure containing about the media related to the requested fields.
|
52
|
+
def self.info(media_id, assets_names = ['source'], fields = {})
|
53
|
+
raise StandardError, "missing :media_id in params" unless media_id
|
54
|
+
call_type = "media.info"
|
55
|
+
|
56
|
+
params = {
|
57
|
+
:call => call_type,
|
58
|
+
args: DmCloud::Builder::Media.info(media_id, assets_names, fields)
|
59
|
+
}
|
60
|
+
DmCloud.config[:auto_call] == true ? DmCloud::Request.execute(call_type, params) : {call: call_type, params: params}
|
61
|
+
end
|
62
|
+
|
63
|
+
# Returns a paginated list of media info structures.
|
64
|
+
# You must specify the fields you want to retrieve.
|
65
|
+
# The fields are described in the documentation of the method info.
|
66
|
+
#
|
67
|
+
# Parameters:
|
68
|
+
# options:
|
69
|
+
# fields (Array) – (optional default return all informations) the fields to retrieve
|
70
|
+
# page (Integer) – (optional) the page number, default: 1
|
71
|
+
# per_page (Integer) – (optional) the number of objet per page, default: 10
|
72
|
+
# Returns:
|
73
|
+
# an object with information for the pagination and the result of the query.
|
74
|
+
def self.list(page = 1, per_page = 10, fields = {})
|
75
|
+
call_type = "media.list"
|
76
|
+
|
77
|
+
params = {
|
78
|
+
:call => call_type,
|
79
|
+
args: DmCloud::Builder::Media.list( page, per_page, fields)
|
80
|
+
}
|
81
|
+
DmCloud.config[:auto_call] == true ? DmCloud::Request.execute(call_type, params) : {call: call_type, params: params}
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module DmCloud
|
5
|
+
class Request
|
6
|
+
|
7
|
+
DAILYMOTION_API = 'http://api.DmCloud.net/api'
|
8
|
+
DAILYMOTION_STATIC = 'http://api.DmCloud.net/api'
|
9
|
+
|
10
|
+
# This method control signing for Media calls and handle request and response.
|
11
|
+
def self.execute(call, params = {})
|
12
|
+
url = define(call)
|
13
|
+
params['auth'] = DmCloud::Signing.identify(params)
|
14
|
+
|
15
|
+
result = send_request(params)
|
16
|
+
parse_response(result)
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
def self.send_request(params)
|
21
|
+
@uri = URI.parse(DAILYMOTION_API)
|
22
|
+
|
23
|
+
http = Net::HTTP.new(@uri.host, @uri.port)
|
24
|
+
request = Net::HTTP::Post.new(@uri.request_uri)
|
25
|
+
request.content_type = 'application/json'
|
26
|
+
request.body = params.to_json
|
27
|
+
|
28
|
+
# puts 'request (YAML format ): ' + request.to_yaml + "\n" + '-' * 80
|
29
|
+
|
30
|
+
http.request(request).body
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
def self.parse_response(result)
|
36
|
+
JSON.parse(result)
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.define(action)
|
40
|
+
DAILYMOTION_API
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|