opensubtitles 0.0.1

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.
Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +4 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +10 -0
  5. data/Gemfile +3 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +50 -0
  8. data/Rakefile +9 -0
  9. data/bin/getsub +157 -0
  10. data/lib/opensubtitles.rb +21 -0
  11. data/lib/opensubtitles/finder.rb +8 -0
  12. data/lib/opensubtitles/finder/first.rb +13 -0
  13. data/lib/opensubtitles/finder/interactive.rb +21 -0
  14. data/lib/opensubtitles/finder/score.rb +13 -0
  15. data/lib/opensubtitles/language.rb +84 -0
  16. data/lib/opensubtitles/movie.rb +16 -0
  17. data/lib/opensubtitles/movie_file.rb +67 -0
  18. data/lib/opensubtitles/search.rb +9 -0
  19. data/lib/opensubtitles/search/imdb.rb +27 -0
  20. data/lib/opensubtitles/search/movie_hash.rb +21 -0
  21. data/lib/opensubtitles/search/name.rb +28 -0
  22. data/lib/opensubtitles/search/path.rb +20 -0
  23. data/lib/opensubtitles/selector.rb +7 -0
  24. data/lib/opensubtitles/selector/format.rb +17 -0
  25. data/lib/opensubtitles/selector/movie.rb +29 -0
  26. data/lib/opensubtitles/server.rb +70 -0
  27. data/lib/opensubtitles/sub.rb +55 -0
  28. data/lib/opensubtitles/subtitle_finder.rb +30 -0
  29. data/lib/opensubtitles/version.rb +3 -0
  30. data/lib/opensubtitles/xmlrpc_monkey_patch.rb +88 -0
  31. data/opensubtitles.gemspec +26 -0
  32. data/spec/fixtures/http/check_movie_hash.yml +225 -0
  33. data/spec/fixtures/http/get_imdb_movie_details.yml +342 -0
  34. data/spec/fixtures/http/log_in.yml +86 -0
  35. data/spec/fixtures/http/log_out.yml +68 -0
  36. data/spec/fixtures/http/search_imdb.yml +761 -0
  37. data/spec/fixtures/http/search_subtitles_for_himym.yml +1189 -0
  38. data/spec/fixtures/http/search_subtitles_for_the_rock.yml +4124 -0
  39. data/spec/fixtures/http/server_info.yml +492 -0
  40. data/spec/fixtures/somemovie.avi +0 -0
  41. data/spec/opensubtitles/language_spec.rb +57 -0
  42. data/spec/opensubtitles/movie_file_spec.rb +18 -0
  43. data/spec/opensubtitles/server_spec.rb +123 -0
  44. data/spec/opensubtitles/sub_spec.rb +33 -0
  45. data/spec/spec_helper.rb +15 -0
  46. metadata +159 -0
@@ -0,0 +1,57 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Opensubtitles::Language do
4
+
5
+ describe '.from_locale' do
6
+
7
+ describe "simple locale" do
8
+
9
+ subject{ Opensubtitles::Language.from_locale('fr') }
10
+
11
+ its(:name) { should == 'French' }
12
+
13
+ its(:to_iso639_1) { should == 'fr' }
14
+
15
+ its(:to_iso639_2b) { should == 'fre' }
16
+
17
+ end
18
+
19
+ describe "locale with territory" do
20
+
21
+ subject{ Opensubtitles::Language.from_locale('en_US') }
22
+
23
+ its(:name) { should == 'English (US)' }
24
+
25
+ its(:to_iso639_1) { should == 'en' }
26
+
27
+ its(:to_iso639_2b) { should == 'eng' }
28
+
29
+ end
30
+
31
+ describe "locale with territory and encoding" do
32
+
33
+ subject{ Opensubtitles::Language.from_locale('es_ES.UTF8') }
34
+
35
+ its(:name) { should == 'Spanish (Spain)' }
36
+
37
+ its(:to_iso639_1) { should == 'es' }
38
+
39
+ its(:to_iso639_2b) { should == 'spa' }
40
+
41
+ end
42
+
43
+ end
44
+
45
+ describe ".from_iso_639_2b" do
46
+
47
+ subject{ Opensubtitles::Language.from_iso639_2b('bre') }
48
+
49
+ its(:name) { should == 'English (UK)' }
50
+
51
+ its(:to_iso639_1) { should == 'en' }
52
+
53
+ its(:to_locale) { should == 'en_GB' }
54
+
55
+ end
56
+
57
+ end
@@ -0,0 +1,18 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Opensubtitles::MovieFile do
4
+
5
+ subject do
6
+ Opensubtitles::MovieFile.new(File.dirname(__FILE__) + '/../fixtures/somemovie.avi')
7
+ end
8
+
9
+ its(:hash) { should == '243339b48f4e8741' }
10
+ its(:name) { should == 'somemovie' }
11
+
12
+ describe '#sub_path' do
13
+ it 'should only change the extension of the movie' do
14
+ movie_file = Opensubtitles::MovieFile.new('directory-with-extension.avi/movie-file.avi', false)
15
+ movie_file.sub_path('srt').should == 'directory-with-extension.avi/movie-file.srt'
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,123 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Opensubtitles::Server do
4
+
5
+ before :all do
6
+ @server = Opensubtitles::Server.new(
7
+ :host => 'api.opensubtitles.org',
8
+ :path => '/xml-rpc',
9
+ :timeout => 60, # OS.org is very very slow ....
10
+ :useragent => 'OS Test User Agent'
11
+ )
12
+ end
13
+
14
+ subject { @server }
15
+
16
+ let(:expected_info) do
17
+ {
18
+ "website_url"=>"http://www.opensubtitles.org",
19
+ "contact"=>"admin@opensubtitles.org",
20
+ "application"=>"OpenSuber v0.2",
21
+ "xmlrpc_version"=>"0.1",
22
+ "xmlrpc_url"=>"http://api.opensubtitles.org/xml-rpc"
23
+ }
24
+ end
25
+
26
+ it 'should respond to #info' do
27
+ VCR.use_cassette('server_info') do
28
+ info = subject.info
29
+ expected_info.each do |key, value|
30
+ info[key].should == value
31
+ end
32
+ info['seconds'].should be_a(Float)
33
+ info['last_update_strings'].should be_a(Hash)
34
+ end
35
+ end
36
+
37
+ it 'should automatically call #login when token is needed' do
38
+ VCR.use_cassette('log_in') do
39
+ subject.instance_variable_get('@token').should be_nil
40
+ subject.token.should match(/[a-z0-9]{26}/)
41
+ subject.instance_variable_get('@token').should == subject.token
42
+ end
43
+ end
44
+
45
+ it 'should clear @login after #logout' do
46
+ VCR.use_cassette('log_in') do
47
+ subject.token
48
+ end
49
+ VCR.use_cassette('log_out') do
50
+ expect {
51
+ subject.logout
52
+ }.to change{ subject.instance_variable_get('@token') }.from(instance_of(String)).to(nil)
53
+ end
54
+ end
55
+
56
+ describe "#check_movie_hash" do
57
+
58
+ it 'should identify movie' do
59
+ VCR.use_cassette('check_movie_hash') do
60
+ subject.check_movie_hash('37d0c7d0cfcbe280')['data'].should == {
61
+ "37d0c7d0cfcbe280" => {
62
+ "MovieYear" => "1996",
63
+ "MovieImdbID" => "0117500",
64
+ "MovieName" => "The Rock",
65
+ "MovieHash" => "37d0c7d0cfcbe280",
66
+ "MovieKind" => "movie",
67
+ "SeriesSeason" => "0",
68
+ "SeriesEpisode" => "0"
69
+ }
70
+ }
71
+ end
72
+ end
73
+
74
+ end
75
+
76
+ describe '#search_subtitles' do
77
+
78
+ it 'can search by hash and size' do
79
+ VCR.use_cassette('search_subtitles_for_himym') do
80
+ subs = subject.search_subtitles(:moviehash => 'bd71526264fd8bd9', :moviebytesize => '183406990', :sublanguageid => 'fre')
81
+ subs.should be_a(Array)
82
+ subs.length.should >= 2
83
+ subs.each do |sub|
84
+ sub.language.name.should == 'French'
85
+ sub.raw_data['MovieName'].should =~ /How I Met Your Mother/
86
+ end
87
+ end
88
+ end
89
+
90
+ it 'can search by imdbid' do
91
+ VCR.use_cassette('search_subtitles_for_the_rock') do
92
+ subs = subject.search_subtitles(:imdbid => "0117500", :sublanguageid => 'fre')
93
+ subs.should be_a(Array)
94
+ subs.length.should >= 1
95
+ subs.each do |sub|
96
+ sub.language.name.should == 'French'
97
+ sub.raw_data['MovieName'].should == 'The Rock'
98
+ end
99
+ end
100
+ end
101
+
102
+ end
103
+
104
+ describe "#search_imdb" do
105
+ it "can search imdb by title" do
106
+ VCR.use_cassette('search_imdb') do
107
+ imdb = subject.search_imdb(:query => "Troy")
108
+ imdb.each do |movie|
109
+ movie.title.should =~ /Troy/
110
+ end
111
+ end
112
+ end
113
+
114
+ it "can get the details of a movie from an id" do
115
+ VCR.use_cassette('get_imdb_movie_details') do
116
+ movie = subject.get_imdb_movie_details('0176415')
117
+ movie.title.should == 'El abuelo'
118
+ movie.year.should == 1998
119
+ end
120
+ end
121
+ end
122
+
123
+ end
@@ -0,0 +1,33 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Opensubtitles::Sub do
4
+
5
+ before :each do
6
+ @response = {
7
+ 'SubFormat' => 'srt',
8
+ 'SubDownloadLink' => 'http://example.com/foo.srt.gz',
9
+ 'SubRating' => '7.89',
10
+ 'SubLanguageID' => 'dut',
11
+ 'MovieName' => 'Lock, Stock and Two Smoking Barrels'
12
+ }
13
+ end
14
+
15
+ subject do
16
+ Opensubtitles::Sub.new @response
17
+ end
18
+
19
+ its(:format) { should == 'srt' }
20
+
21
+ its(:url) { should be_an(URI::HTTP) }
22
+
23
+ its(:language) { should be_a(Opensubtitles::Language) }
24
+
25
+ its(:rating) { should == 7.89 }
26
+
27
+ its(:movie_name) { should == 'Lock, Stock and Two Smoking Barrels' }
28
+
29
+ it 'should be comparable' do
30
+ [subject, Opensubtitles::Sub.new(@response.merge('SubRating' => '2.45'))].max.should == subject
31
+ end
32
+
33
+ end
@@ -0,0 +1,15 @@
1
+ require File.dirname(__FILE__) + '/../lib/opensubtitles'
2
+ require 'rspec'
3
+ require 'rspec/its'
4
+
5
+ require 'webmock/rspec'
6
+ require 'vcr'
7
+
8
+ RSpec.configure do |c|
9
+ c.mock_with :rspec
10
+ end
11
+
12
+ VCR.configure do |c|
13
+ c.cassette_library_dir = 'spec/fixtures/http'
14
+ c.hook_into :webmock
15
+ end
metadata ADDED
@@ -0,0 +1,159 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: opensubtitles
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Evandro Jr
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-12-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec-its
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: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.8.11
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.8.11
69
+ - !ruby/object:Gem::Dependency
70
+ name: vcr
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 2.3.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 2.3.0
83
+ description:
84
+ email:
85
+ - evandrojr@gmail.com
86
+ executables:
87
+ - getsub
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - bin/getsub
99
+ - lib/opensubtitles.rb
100
+ - lib/opensubtitles/finder.rb
101
+ - lib/opensubtitles/finder/first.rb
102
+ - lib/opensubtitles/finder/interactive.rb
103
+ - lib/opensubtitles/finder/score.rb
104
+ - lib/opensubtitles/language.rb
105
+ - lib/opensubtitles/movie.rb
106
+ - lib/opensubtitles/movie_file.rb
107
+ - lib/opensubtitles/search.rb
108
+ - lib/opensubtitles/search/imdb.rb
109
+ - lib/opensubtitles/search/movie_hash.rb
110
+ - lib/opensubtitles/search/name.rb
111
+ - lib/opensubtitles/search/path.rb
112
+ - lib/opensubtitles/selector.rb
113
+ - lib/opensubtitles/selector/format.rb
114
+ - lib/opensubtitles/selector/movie.rb
115
+ - lib/opensubtitles/server.rb
116
+ - lib/opensubtitles/sub.rb
117
+ - lib/opensubtitles/subtitle_finder.rb
118
+ - lib/opensubtitles/version.rb
119
+ - lib/opensubtitles/xmlrpc_monkey_patch.rb
120
+ - opensubtitles.gemspec
121
+ - spec/fixtures/http/check_movie_hash.yml
122
+ - spec/fixtures/http/get_imdb_movie_details.yml
123
+ - spec/fixtures/http/log_in.yml
124
+ - spec/fixtures/http/log_out.yml
125
+ - spec/fixtures/http/search_imdb.yml
126
+ - spec/fixtures/http/search_subtitles_for_himym.yml
127
+ - spec/fixtures/http/search_subtitles_for_the_rock.yml
128
+ - spec/fixtures/http/server_info.yml
129
+ - spec/fixtures/somemovie.avi
130
+ - spec/opensubtitles/language_spec.rb
131
+ - spec/opensubtitles/movie_file_spec.rb
132
+ - spec/opensubtitles/server_spec.rb
133
+ - spec/opensubtitles/sub_spec.rb
134
+ - spec/spec_helper.rb
135
+ homepage: http://github.com/evandrojr/opensubtitles
136
+ licenses:
137
+ - MIT
138
+ metadata: {}
139
+ post_install_message:
140
+ rdoc_options: []
141
+ require_paths:
142
+ - lib
143
+ required_ruby_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ required_rubygems_version: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ requirements: []
154
+ rubyforge_project: opensubtitles
155
+ rubygems_version: 2.4.8
156
+ signing_key:
157
+ specification_version: 4
158
+ summary: Ruby library to access Opensubtitles services like OpenSubtitles.org
159
+ test_files: []