hktv 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +64 -0
- data/Rakefile +2 -0
- data/bin/hktv +4 -0
- data/hktv.gemspec +31 -0
- data/lib/hktv.rb +241 -0
- data/lib/hktv/command.rb +183 -0
- data/lib/hktv/version.rb +3 -0
- data/spec/cassettes/HKTV/with_authentication/_ott_token/should_retrieve_a_token.yml +140 -0
- data/spec/cassettes/HKTV/with_authentication/_playlist/should_find_playlist_for_a_video.yml +42 -0
- data/spec/cassettes/HKTV/with_no_token_and_auth/_features/should_list_feature.yml +274 -0
- data/spec/cassettes/HKTV/with_no_token_and_auth/_ott_token/should_retrieve_a_token.yml +81 -0
- data/spec/cassettes/HKTV/with_no_token_and_auth/_playlist/should_retrieve_a_playlist.yml +81 -0
- data/spec/cassettes/HKTV/with_no_token_and_auth/_programs/should_list_programs.yml +5698 -0
- data/spec/cassettes/auth.yml +52 -0
- data/spec/hktv_spec.rb +123 -0
- data/spec/spec_helper.rb +30 -0
- metadata +217 -0
@@ -0,0 +1,52 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: post
|
5
|
+
uri: https://www.hktvmall.com/hktvwebservices/oauth/token?rand=1420049220
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: grant_type=password&username=<HKTV_USER_NAME>&password=<HKTV_PASSWORD>
|
9
|
+
headers:
|
10
|
+
Content-Type:
|
11
|
+
- application/x-www-form-urlencoded
|
12
|
+
Accept:
|
13
|
+
- "*/*"
|
14
|
+
response:
|
15
|
+
status:
|
16
|
+
code: 200
|
17
|
+
message: OK
|
18
|
+
headers:
|
19
|
+
Server:
|
20
|
+
- nginx/1.6.2
|
21
|
+
Date:
|
22
|
+
- Wed, 31 Dec 2014 18:07:00 GMT
|
23
|
+
Content-Type:
|
24
|
+
- application/json
|
25
|
+
Content-Length:
|
26
|
+
- '170'
|
27
|
+
Connection:
|
28
|
+
- keep-alive
|
29
|
+
Vary:
|
30
|
+
- Accept-Encoding
|
31
|
+
Cache-Control:
|
32
|
+
- no-store
|
33
|
+
Pragma:
|
34
|
+
- no-cache
|
35
|
+
Etag:
|
36
|
+
- '"0ad2c0e483c1e018b3aefc39d0909e11e"'
|
37
|
+
Httpd-Srv-Id:
|
38
|
+
- ecweb-tu03
|
39
|
+
X-Indicator-Srv:
|
40
|
+
- ecweb-tu03
|
41
|
+
body:
|
42
|
+
encoding: UTF-8
|
43
|
+
string: |-
|
44
|
+
{
|
45
|
+
"access_token": "b9008875-1170-4bab-94ee-ce8ef5ccb7b5",
|
46
|
+
"token_type": "bearer",
|
47
|
+
"refresh_token": "1a2d4f93-9ad8-48ed-ad75-21224b06c068",
|
48
|
+
"expires_in": 2592000
|
49
|
+
}
|
50
|
+
http_version:
|
51
|
+
recorded_at: Wed, 31 Dec 2014 18:07:00 GMT
|
52
|
+
recorded_with: VCR 2.9.3
|
data/spec/hktv_spec.rb
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
require_relative "../lib/hktv"
|
2
|
+
require_relative './spec_helper'
|
3
|
+
require 'pry'
|
4
|
+
|
5
|
+
vcr_options = {:record => :new_episodes, :match_requests_on => [:method, :anonymized_uri]}
|
6
|
+
|
7
|
+
describe HKTV do
|
8
|
+
describe "Persistence" do
|
9
|
+
context "::to_hash" do
|
10
|
+
it "should save to Hash" do
|
11
|
+
hktv = HKTV.new({uuid: "uuid", access_token: "access_token", expires_date: Time.at(10000000), refresh_token: "refresh_token", user_id: "1", user_level: 1, ott_token: "token", ott_expires_date: Time.at(10000000)})
|
12
|
+
hash = hktv.to_hash
|
13
|
+
expect(hash).to eql({uuid: "uuid", access_token: "access_token", expires_date: 10000000, refresh_token: "refresh_token", user_id: "1", user_level: 1, ott_token: "token", ott_expires_date: 10000000})
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context "::from_hash" do
|
18
|
+
it "should load from Hash" do
|
19
|
+
hktv = HKTV.from_hash({uuid: "uuid", access_token: "access_token", expires_date: 10000000, refresh_token: "refresh_token", user_id: "1", user_level: 1, ott_token: "token", ott_expires_date: 10000000})
|
20
|
+
hash = hktv.to_hash
|
21
|
+
expect(hash).to eql({uuid: "uuid", access_token: "access_token", expires_date: 10000000, refresh_token: "refresh_token", user_id: "1", user_level: 1, ott_token: "token", ott_expires_date: 10000000})
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "with no token and auth", :vcr => vcr_options do
|
27
|
+
context "#ott_token" do
|
28
|
+
it "should retrieve a token" do
|
29
|
+
token = subject.ott_token
|
30
|
+
|
31
|
+
expect(token).to be_truthy
|
32
|
+
expect(subject.ott_token).to_not be_nil
|
33
|
+
expect(subject.user_id).to_not be_nil
|
34
|
+
expect(subject.user_level).to_not be_nil
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "#features" do
|
39
|
+
it "should list feature" do
|
40
|
+
features = subject.features
|
41
|
+
expect(features).to be_a(Array)
|
42
|
+
|
43
|
+
program = features.first
|
44
|
+
expect(program["video_id"]).to_not be_nil
|
45
|
+
expect(program["video_level"]).to_not be_nil
|
46
|
+
expect(program["permission_level"]).to_not be_nil
|
47
|
+
expect(program["title"]).to_not be_nil
|
48
|
+
expect(program["duration"]).to_not be_nil
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "#programs" do
|
53
|
+
it "should list programs" do
|
54
|
+
programs = subject.programs
|
55
|
+
expect(programs).to be_a(Array)
|
56
|
+
|
57
|
+
program = programs.first
|
58
|
+
expect(program["video_id"]).to_not be_nil
|
59
|
+
expect(program["video_level"]).to_not be_nil
|
60
|
+
expect(program["permission_level"]).to_not be_nil
|
61
|
+
expect(program["title"]).to_not be_nil
|
62
|
+
expect(program["duration"]).to_not be_nil
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context "#playlist" do
|
67
|
+
it "should retrieve a playlist" do
|
68
|
+
playlist = subject.playlist("1")
|
69
|
+
expect(playlist).to_not be_nil
|
70
|
+
expect(playlist).to match(/^http:/)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "with authentication", :vcr => vcr_options do
|
76
|
+
before(:all) do
|
77
|
+
@subject = HKTV.new
|
78
|
+
VCR.use_cassette 'auth', vcr_options do
|
79
|
+
@subject.auth(ENV["HKTV_USER_NAME"], ENV["HKTV_PASSWORD"])
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
after(:all) do
|
84
|
+
VCR.use_cassette 'auth', vcr_options do
|
85
|
+
@subject.logout
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context "#auth" do
|
90
|
+
it "should retrieve auth token and token" do
|
91
|
+
expect(@subject).to be_authenticated
|
92
|
+
expect(@subject.access_token).to_not be_nil
|
93
|
+
expect(@subject.expires_date).to_not be_nil
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context "#ott_token" do
|
98
|
+
it "should retrieve a token" do
|
99
|
+
token = @subject.ott_token
|
100
|
+
expect(token).to be_truthy
|
101
|
+
expect(@subject.ott_token).to_not be_nil
|
102
|
+
expect(@subject.user_id).to_not be_nil
|
103
|
+
expect(@subject.user_level).to_not be_nil
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
context "#playlist" do
|
108
|
+
it "should find playlist for a video" do
|
109
|
+
video = @subject.playlist("1670")
|
110
|
+
expect(video).to_not be_nil
|
111
|
+
expect(video).to match(/^http:/)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
context "#logout" do
|
116
|
+
it "should success logout" do
|
117
|
+
logout = @subject.logout
|
118
|
+
expect(logout).to be_truthy
|
119
|
+
expect(@subject.access_token).to be_nil
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'vcr'
|
2
|
+
require 'cgi'
|
3
|
+
|
4
|
+
VCR.configure do |c|
|
5
|
+
c.cassette_library_dir = 'spec/cassettes'
|
6
|
+
c.hook_into :webmock
|
7
|
+
c.configure_rspec_metadata!
|
8
|
+
|
9
|
+
# Removes all private data (Basic Auth, Set-Cookie headers...)
|
10
|
+
c.before_record do |i|
|
11
|
+
i.response.headers.delete('Set-Cookie')
|
12
|
+
i.request.headers.delete('Authorization')
|
13
|
+
u = URI.parse(i.request.uri)
|
14
|
+
i.request.uri.sub!(/:\/\/.*#{Regexp.escape(u.host)}/, "://#{u.host}" )
|
15
|
+
end
|
16
|
+
|
17
|
+
c.filter_sensitive_data('<HKTV_PASSWORD>') do
|
18
|
+
CGI.escape ENV['HKTV_PASSWORD']
|
19
|
+
end
|
20
|
+
|
21
|
+
c.filter_sensitive_data('<HKTV_USER_NAME>') do
|
22
|
+
CGI.escape ENV['HKTV_USER_NAME']
|
23
|
+
end
|
24
|
+
|
25
|
+
# Matches authenticated requests regardless of their Basic auth string (https://user:pass@domain.tld)
|
26
|
+
c.register_request_matcher :anonymized_uri do |request_1, request_2|
|
27
|
+
(URI(request_1.uri).port == URI(request_2.uri).port) &&
|
28
|
+
URI(request_1.uri).path == URI(request_2.uri).path
|
29
|
+
end
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,217 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hktv
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Francis Chong
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: vcr
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: webmock
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: httparty
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.13'
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: 0.13.1
|
107
|
+
type: :runtime
|
108
|
+
prerelease: false
|
109
|
+
version_requirements: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - "~>"
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0.13'
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: 0.13.1
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: retriable
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - "~>"
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '1.4'
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: 1.4.1
|
127
|
+
type: :runtime
|
128
|
+
prerelease: false
|
129
|
+
version_requirements: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - "~>"
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '1.4'
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: 1.4.1
|
137
|
+
- !ruby/object:Gem::Dependency
|
138
|
+
name: commander
|
139
|
+
requirement: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - "~>"
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '4.2'
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: 4.2.1
|
147
|
+
type: :runtime
|
148
|
+
prerelease: false
|
149
|
+
version_requirements: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - "~>"
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '4.2'
|
154
|
+
- - ">="
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
version: 4.2.1
|
157
|
+
description: Command line utilities to find and download HKTV videos.
|
158
|
+
email:
|
159
|
+
- francis@ignition.hk
|
160
|
+
executables:
|
161
|
+
- hktv
|
162
|
+
extensions: []
|
163
|
+
extra_rdoc_files: []
|
164
|
+
files:
|
165
|
+
- ".gitignore"
|
166
|
+
- Gemfile
|
167
|
+
- LICENSE.txt
|
168
|
+
- README.md
|
169
|
+
- Rakefile
|
170
|
+
- bin/hktv
|
171
|
+
- hktv.gemspec
|
172
|
+
- lib/hktv.rb
|
173
|
+
- lib/hktv/command.rb
|
174
|
+
- lib/hktv/version.rb
|
175
|
+
- spec/cassettes/HKTV/with_authentication/_ott_token/should_retrieve_a_token.yml
|
176
|
+
- spec/cassettes/HKTV/with_authentication/_playlist/should_find_playlist_for_a_video.yml
|
177
|
+
- spec/cassettes/HKTV/with_no_token_and_auth/_features/should_list_feature.yml
|
178
|
+
- spec/cassettes/HKTV/with_no_token_and_auth/_ott_token/should_retrieve_a_token.yml
|
179
|
+
- spec/cassettes/HKTV/with_no_token_and_auth/_playlist/should_retrieve_a_playlist.yml
|
180
|
+
- spec/cassettes/HKTV/with_no_token_and_auth/_programs/should_list_programs.yml
|
181
|
+
- spec/cassettes/auth.yml
|
182
|
+
- spec/hktv_spec.rb
|
183
|
+
- spec/spec_helper.rb
|
184
|
+
homepage: https://github.com/siuying/ruby-hktv
|
185
|
+
licenses:
|
186
|
+
- MIT
|
187
|
+
metadata: {}
|
188
|
+
post_install_message:
|
189
|
+
rdoc_options: []
|
190
|
+
require_paths:
|
191
|
+
- lib
|
192
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
193
|
+
requirements:
|
194
|
+
- - ">="
|
195
|
+
- !ruby/object:Gem::Version
|
196
|
+
version: '0'
|
197
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - ">="
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '0'
|
202
|
+
requirements: []
|
203
|
+
rubyforge_project:
|
204
|
+
rubygems_version: 2.4.5
|
205
|
+
signing_key:
|
206
|
+
specification_version: 4
|
207
|
+
summary: Find and download HKTV videos.
|
208
|
+
test_files:
|
209
|
+
- spec/cassettes/HKTV/with_authentication/_ott_token/should_retrieve_a_token.yml
|
210
|
+
- spec/cassettes/HKTV/with_authentication/_playlist/should_find_playlist_for_a_video.yml
|
211
|
+
- spec/cassettes/HKTV/with_no_token_and_auth/_features/should_list_feature.yml
|
212
|
+
- spec/cassettes/HKTV/with_no_token_and_auth/_ott_token/should_retrieve_a_token.yml
|
213
|
+
- spec/cassettes/HKTV/with_no_token_and_auth/_playlist/should_retrieve_a_playlist.yml
|
214
|
+
- spec/cassettes/HKTV/with_no_token_and_auth/_programs/should_list_programs.yml
|
215
|
+
- spec/cassettes/auth.yml
|
216
|
+
- spec/hktv_spec.rb
|
217
|
+
- spec/spec_helper.rb
|