subscene 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.rspec +2 -0
- data/.travis.yml +6 -0
- data/Gemfile +4 -0
- data/README.md +52 -3
- data/Rakefile +7 -0
- data/lib/subscene.rb +103 -1
- data/lib/subscene/error.rb +3 -0
- data/lib/subscene/response.rb +22 -0
- data/lib/subscene/response/html.rb +20 -0
- data/lib/subscene/response/raise_error.rb +20 -0
- data/lib/subscene/subtitle.rb +56 -0
- data/lib/subscene/subtitle_result.rb +35 -0
- data/lib/subscene/subtitle_result_set.rb +19 -0
- data/lib/subscene/version.rb +1 -1
- data/spec/fixtures/result_sample.html +31 -0
- data/spec/fixtures/result_set_sample.html +96 -0
- data/spec/fixtures/search_with_results.html +966 -0
- data/spec/fixtures/subtitle.zip +0 -0
- data/spec/fixtures/subtitle_sample.html +485 -0
- data/spec/spec_helper.rb +21 -0
- data/spec/subscene/response/raise_error_spec.rb +12 -0
- data/spec/subscene/subtitle_result_set_spec.rb +20 -0
- data/spec/subscene/subtitle_result_spec.rb +20 -0
- data/spec/subscene/subtitle_spec.rb +35 -0
- data/spec/subscene_spec.rb +43 -0
- data/subscene.gemspec +5 -1
- metadata +100 -5
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require "subscene"
|
2
|
+
require "webmock/rspec"
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
6
|
+
config.run_all_when_everything_filtered = true
|
7
|
+
config.filter_run :focus
|
8
|
+
config.order = 'random'
|
9
|
+
end
|
10
|
+
|
11
|
+
def stub_get(path)
|
12
|
+
stub_request(:get, [Subscene::ENDPOINT, path].join('/'))
|
13
|
+
end
|
14
|
+
|
15
|
+
def fixture_path
|
16
|
+
File.expand_path("../fixtures", __FILE__)
|
17
|
+
end
|
18
|
+
|
19
|
+
def fixture(file)
|
20
|
+
File.read(File.join(fixture_path, '/', file))
|
21
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Subscene::Response::RaiseError do
|
4
|
+
it "raises SearchNotSupported when looking for titles" do
|
5
|
+
stub_get("subtitles/release.aspx?q=asdf").
|
6
|
+
to_return(:status => 302, :body => "", :headers => {})
|
7
|
+
|
8
|
+
expect {
|
9
|
+
puts Subscene.search("asdf")
|
10
|
+
}.to raise_error(Subscene::SearchNotSupported)
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Subscene::SubtitleResultSet do
|
4
|
+
describe ".new" do
|
5
|
+
it "takes instances as attributes" do
|
6
|
+
Subscene::SubtitleResultSet.new({
|
7
|
+
instances: "foo" }).instances.should == "foo"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe ".build" do
|
12
|
+
it "takes html" do
|
13
|
+
html_string = fixture("result_set_sample.html")
|
14
|
+
html = Nokogiri::HTML(html_string)
|
15
|
+
|
16
|
+
Subscene::SubtitleResultSet.build(html).
|
17
|
+
instances.first.name.should == "The.Big.Bang.Theory.S01E01-08.HDTV.XviD-XOR"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Subscene::SubtitleResult do
|
4
|
+
describe ".new" do
|
5
|
+
it "takes a hash of attributes" do
|
6
|
+
Subscene::SubtitleResult.new({ name: "foo" }).
|
7
|
+
name.should == "foo"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe ".build" do
|
12
|
+
it "takes html" do
|
13
|
+
html_string = fixture("result_sample.html")
|
14
|
+
html = Nokogiri::HTML(html_string)
|
15
|
+
|
16
|
+
Subscene::SubtitleResult.build(html).
|
17
|
+
name.should == "The.Big.Bang.Theory.S01E01-08.HDTV.XviD-XOR"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Subscene::Subtitle do
|
4
|
+
describe ".new" do
|
5
|
+
it "takes a hash of attributes" do
|
6
|
+
Subscene::Subtitle.new({ name: "foo" }).
|
7
|
+
name.should == "foo"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe ".build" do
|
12
|
+
it "takes html" do
|
13
|
+
html_string = fixture("subtitle_sample.html")
|
14
|
+
html = Nokogiri::HTML(html_string)
|
15
|
+
|
16
|
+
Subscene::Subtitle.build(html).
|
17
|
+
name.should == "The.Big.Bang.Theory.S01E01-08.HDTV.XviD-XOR"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#download" do
|
22
|
+
it "returns binary data" do
|
23
|
+
html_string = fixture("subtitle_sample.html")
|
24
|
+
html = Nokogiri::HTML(html_string)
|
25
|
+
|
26
|
+
stub_request(:post, "http://subscene.com/subtitle/download?mac=YLTKmewkUW-EsE9YHksE8LXDYN2b4yBreI8TJIBfpdxgMbaDY5jWnkHqZi70CwVF0").
|
27
|
+
with(:headers => {'Referer'=>'http://subscene.com/136037'}).
|
28
|
+
to_return(:status => 200, :body => fixture("subtitle.zip"),
|
29
|
+
:headers => {'Content-Type'=>'application/x-zip-compressed; charset=utf-8'})
|
30
|
+
|
31
|
+
Subscene::Subtitle.build(html).
|
32
|
+
download.class.should == Faraday::Response
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Subscene do
|
4
|
+
it "has a version" do
|
5
|
+
Subscene::VERSION.should be
|
6
|
+
end
|
7
|
+
|
8
|
+
describe ".search" do
|
9
|
+
it "returns results" do
|
10
|
+
stub_get("subtitles/release.aspx?q=the%2Bbig%2Bbang%2Btheory%2Bs01e01").
|
11
|
+
to_return(:status => 200, :body => fixture("search_with_results.html"))
|
12
|
+
stub_get("subtitles/release.aspx?q=the%20big%20bang%20theory%20s01e01").
|
13
|
+
to_return(:status => 200, :body => fixture("search_with_results.html"))
|
14
|
+
|
15
|
+
subs = Subscene.search("the big bang theory s01e01")
|
16
|
+
subs.first.name.should == "The.Big.Bang.Theory.S01E01-08.HDTV.XviD-XOR"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "returns subtitles filtered by language" do
|
20
|
+
Subscene.language = 13
|
21
|
+
|
22
|
+
stub_get("subtitles/release.aspx?q=the%2Bbig%2Bbang%2Btheory%2Bs01e01").
|
23
|
+
with(:headers => { 'Cookie'=>'LanguageFilter=13;' }).
|
24
|
+
to_return(:status => 200, :body => "")
|
25
|
+
stub_get("subtitles/release.aspx?q=the%20big%20bang%20theory%20s01e01").
|
26
|
+
with(:headers => { 'Cookie'=>'LanguageFilter=13;' }).
|
27
|
+
to_return(:status => 200, :body => "")
|
28
|
+
|
29
|
+
Subscene::SubtitleResultSet.stub(:build).and_return(stub.as_null_object)
|
30
|
+
Subscene.search("the big bang theory s01e01")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe ".find" do
|
35
|
+
it "returns subtitle" do
|
36
|
+
stub_get("136037").to_return(:status => 200,
|
37
|
+
:body => fixture("subtitle_sample.html"))
|
38
|
+
|
39
|
+
Subscene.find(136037).
|
40
|
+
name.should == "The.Big.Bang.Theory.S01E01-08.HDTV.XviD-XOR"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/subscene.gemspec
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
1
|
lib = File.expand_path('../lib', __FILE__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
3
|
require 'subscene/version'
|
@@ -16,4 +15,9 @@ Gem::Specification.new do |gem|
|
|
16
15
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
16
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
17
|
gem.require_paths = ["lib"]
|
18
|
+
|
19
|
+
gem.add_dependency "faraday", "~> 0.8.6"
|
20
|
+
gem.add_dependency "nokogiri", "~> 1.5.6"
|
21
|
+
gem.add_development_dependency "rspec", "~> 2.13.0"
|
22
|
+
gem.add_development_dependency "webmock", "~> 1.10.0"
|
19
23
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: subscene
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,72 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
13
|
-
dependencies:
|
12
|
+
date: 2013-03-25 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: faraday
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.8.6
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.8.6
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: nokogiri
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.5.6
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.5.6
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 2.13.0
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.13.0
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: webmock
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.10.0
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 1.10.0
|
14
78
|
description: Ruby API Client for Subscene.com
|
15
79
|
email:
|
16
80
|
- javier@tractical.com
|
@@ -19,12 +83,32 @@ extensions: []
|
|
19
83
|
extra_rdoc_files: []
|
20
84
|
files:
|
21
85
|
- .gitignore
|
86
|
+
- .rspec
|
87
|
+
- .travis.yml
|
22
88
|
- Gemfile
|
23
89
|
- LICENSE.txt
|
24
90
|
- README.md
|
25
91
|
- Rakefile
|
26
92
|
- lib/subscene.rb
|
93
|
+
- lib/subscene/error.rb
|
94
|
+
- lib/subscene/response.rb
|
95
|
+
- lib/subscene/response/html.rb
|
96
|
+
- lib/subscene/response/raise_error.rb
|
97
|
+
- lib/subscene/subtitle.rb
|
98
|
+
- lib/subscene/subtitle_result.rb
|
99
|
+
- lib/subscene/subtitle_result_set.rb
|
27
100
|
- lib/subscene/version.rb
|
101
|
+
- spec/fixtures/result_sample.html
|
102
|
+
- spec/fixtures/result_set_sample.html
|
103
|
+
- spec/fixtures/search_with_results.html
|
104
|
+
- spec/fixtures/subtitle.zip
|
105
|
+
- spec/fixtures/subtitle_sample.html
|
106
|
+
- spec/spec_helper.rb
|
107
|
+
- spec/subscene/response/raise_error_spec.rb
|
108
|
+
- spec/subscene/subtitle_result_set_spec.rb
|
109
|
+
- spec/subscene/subtitle_result_spec.rb
|
110
|
+
- spec/subscene/subtitle_spec.rb
|
111
|
+
- spec/subscene_spec.rb
|
28
112
|
- subscene.gemspec
|
29
113
|
homepage: https://github.com/jassa/subscene
|
30
114
|
licenses: []
|
@@ -46,8 +130,19 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
46
130
|
version: '0'
|
47
131
|
requirements: []
|
48
132
|
rubyforge_project:
|
49
|
-
rubygems_version: 1.8.
|
133
|
+
rubygems_version: 1.8.23
|
50
134
|
signing_key:
|
51
135
|
specification_version: 3
|
52
136
|
summary: Subscene.com API Client
|
53
|
-
test_files:
|
137
|
+
test_files:
|
138
|
+
- spec/fixtures/result_sample.html
|
139
|
+
- spec/fixtures/result_set_sample.html
|
140
|
+
- spec/fixtures/search_with_results.html
|
141
|
+
- spec/fixtures/subtitle.zip
|
142
|
+
- spec/fixtures/subtitle_sample.html
|
143
|
+
- spec/spec_helper.rb
|
144
|
+
- spec/subscene/response/raise_error_spec.rb
|
145
|
+
- spec/subscene/subtitle_result_set_spec.rb
|
146
|
+
- spec/subscene/subtitle_result_spec.rb
|
147
|
+
- spec/subscene/subtitle_spec.rb
|
148
|
+
- spec/subscene_spec.rb
|