osdb 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ k(%Ԕ��5/���ͩ#$%��uOQ�f��� ��/r�-ıu�t��͎��j�v�.�)��a}A�Y�*�=uj |���m>��B�Z!p�z9:bp&:�{��|_#3g��f����l�(�شPFj1�P���(���O��~
2
+ c��G�ֳ�'a@��*�[�����ӌ?%�{���y/�_��B=�r��Ê ��m�9�u�9Oyz4|2�G�$�t߽�� �aG�Ó\ƶۿ
3
+
@@ -0,0 +1,10 @@
1
+ Manifest
2
+ Rakefile
3
+ lib/osdb.rb
4
+ lib/osdb/movie.rb
5
+ lib/osdb/server.rb
6
+ lib/osdb/sub.rb
7
+ spec/fixtures/somemovie.avi
8
+ spec/osdb/movie_spec.rb
9
+ spec/osdb/server_spec.rb
10
+ spec/spec_helper.rb
@@ -0,0 +1,23 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'spec/rake/spectask'
4
+
5
+ Spec::Rake::SpecTask.new(:spec) do |spec|
6
+ spec.libs << 'lib' << 'spec'
7
+ spec.spec_files = FileList['spec/**/*_spec.rb']
8
+ end
9
+
10
+ begin
11
+ require 'echoe'
12
+
13
+ Echoe.new('osdb', '0.0.1') do |p|
14
+ p.description = "Ruby library to access OSDb services like OpenSubtitles.org"
15
+ p.url = "http://github.com/byroot/ruby-osdb"
16
+ p.author = "Jean Boussier"
17
+ p.email = "jean.boussier @nospam@ gmail.com"
18
+ end
19
+
20
+ rescue LoadError
21
+ end
22
+
23
+ task :default => :spec
@@ -0,0 +1,8 @@
1
+ require 'xmlrpc/client'
2
+
3
+ module OSDb
4
+ base_path = File.expand_path(File.dirname(__FILE__) + '/osdb')
5
+ autoload :Movie, "#{base_path}/movie"
6
+ autoload :Server, "#{base_path}/server"
7
+ autoload :Sub, "#{base_path}/sub"
8
+ end
@@ -0,0 +1,45 @@
1
+ module OSDb
2
+ class Movie
3
+
4
+ attr_reader :path
5
+
6
+ def initialize(path)
7
+ @path = path
8
+ end
9
+
10
+ def hash
11
+ @hash ||= self.class.compute_hash(path)
12
+ end
13
+
14
+ def size
15
+ @size ||= File.size(path)
16
+ end
17
+
18
+ CHUNK_SIZE = 64 * 1024 # in bytes
19
+
20
+ # from http://trac.opensubtitles.org/projects/opensubtitles/wiki/HashSourceCodes
21
+ def self.compute_hash(path)
22
+ filesize = File.size(path)
23
+ hash = filesize
24
+
25
+ # Read 64 kbytes, divide up into 64 bits and add each
26
+ # to hash. Do for beginning and end of file.
27
+ File.open(path, 'rb') do |f|
28
+ # Q = unsigned long long = 64 bit
29
+ f.read(CHUNK_SIZE).unpack("Q*").each do |n|
30
+ hash = hash + n & 0xffffffffffffffff # to remain as 64 bit number
31
+ end
32
+
33
+ f.seek([0, filesize - CHUNK_SIZE].max, IO::SEEK_SET)
34
+
35
+ # And again for the end of the file
36
+ f.read(CHUNK_SIZE).unpack("Q*").each do |n|
37
+ hash = hash + n & 0xffffffffffffffff
38
+ end
39
+ end
40
+
41
+ sprintf("%016x", hash)
42
+ end
43
+
44
+ end
45
+ end
@@ -0,0 +1,48 @@
1
+ module OSDb
2
+
3
+ class LoginFailed < ::Exception
4
+ end
5
+
6
+ class Server
7
+
8
+ attr_reader :username, :password, :language, :useragent, :client
9
+
10
+ def initialize(options={})
11
+ @username = options[:username] || ''
12
+ @password = options[:password] || ''
13
+ @language = options[:language] || 'en'
14
+ @useragent = options[:useragent] || 'ruby-osdb v0.1'
15
+ @client = ::XMLRPC::Client.new(*options.values_at(:host, :path, :port, :proxy_host, :proxy_port, :http_user, :http_password, :use_ssl, :timeout))
16
+ end
17
+
18
+ def token
19
+ @token ||= login
20
+ end
21
+
22
+ def login
23
+ response = client.call('LogIn', username, password, language, useragent)
24
+ if response['status'] != '200 OK'
25
+ raise LoginFailed.new("Failed to login with #{username} : #{password}. Server return code: #{response['status']}")
26
+ end
27
+ response['token']
28
+ end
29
+
30
+ def logout
31
+ client.call('LogOut', token)
32
+ @token = nil
33
+ end
34
+
35
+ def check_movie_hash(*hashes)
36
+ client.call('CheckMovieHash', token, hashes)
37
+ end
38
+
39
+ def search_subtitles(*queries)
40
+ client.call('SearchSubtitles', token, queries)
41
+ end
42
+
43
+ def info
44
+ client.call('ServerInfo')
45
+ end
46
+
47
+ end
48
+ end
@@ -0,0 +1,4 @@
1
+ module OSDb
2
+ class Sub
3
+ end
4
+ end
@@ -0,0 +1,32 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{osdb}
5
+ s.version = "0.0.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Jean Boussier"]
9
+ s.cert_chain = ["/Users/byroot/.ssh/gem-public_cert.pem"]
10
+ s.date = %q{2010-08-29}
11
+ s.description = %q{Ruby library to access OSDb services like OpenSubtitles.org}
12
+ s.email = %q{jean.boussier @nospam@ gmail.com}
13
+ s.extra_rdoc_files = ["lib/osdb.rb", "lib/osdb/movie.rb", "lib/osdb/server.rb", "lib/osdb/sub.rb"]
14
+ s.files = ["Manifest", "Rakefile", "lib/osdb.rb", "lib/osdb/movie.rb", "lib/osdb/server.rb", "lib/osdb/sub.rb", "spec/fixtures/somemovie.avi", "spec/osdb/movie_spec.rb", "spec/osdb/server_spec.rb", "spec/spec_helper.rb", "osdb.gemspec"]
15
+ s.homepage = %q{http://github.com/byroot/ruby-osdb}
16
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Osdb"]
17
+ s.require_paths = ["lib"]
18
+ s.rubyforge_project = %q{osdb}
19
+ s.rubygems_version = %q{1.3.6}
20
+ s.signing_key = %q{/Users/byroot/.ssh/gem-private_key.pem}
21
+ s.summary = %q{Ruby library to access OSDb services like OpenSubtitles.org}
22
+
23
+ if s.respond_to? :specification_version then
24
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
25
+ s.specification_version = 3
26
+
27
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
28
+ else
29
+ end
30
+ else
31
+ end
32
+ end
@@ -0,0 +1,11 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe OSDb::Server do
4
+
5
+ subject do
6
+ OSDb::Movie.new(File.dirname(__FILE__) + '/../fixtures/somemovie.avi')
7
+ end
8
+
9
+ its(:hash) { should == '243339b48f4e8741' }
10
+
11
+ end
@@ -0,0 +1,78 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe OSDb::Server do
4
+
5
+ before :all do
6
+ @server = OSDb::Server.new(
7
+ :host => 'api.opensubtitles.org',
8
+ :path => '/xml-rpc',
9
+ :timeout => 60 # OS.org is very very slow ....
10
+ )
11
+ end
12
+
13
+ subject { @server }
14
+
15
+ it 'should respond to #info' do
16
+ hash_including(
17
+ "seconds" => instance_of(Float),
18
+ "last_update_strings" => instance_of(Hash),
19
+ "website_url"=>"http://www.opensubtitles.org",
20
+ "contact"=>"admin@opensubtitles.org",
21
+ "application"=>"OpenSuber v0.2",
22
+ "xmlrpc_version"=>"0.1",
23
+ "xmlrpc_url"=>"http://api.opensubtitles.net/xml-rpc"
24
+ ).should == subject.info
25
+ end
26
+
27
+ it 'should automatically call #login when token is needed' do
28
+ subject.instance_variable_get('@token').should be_nil
29
+ subject.token.should match(/[a-z0-9]{26}/)
30
+ subject.instance_variable_get('@token').should == subject.token
31
+ end
32
+
33
+ it 'should clear @login after #logout' do
34
+ expect{
35
+ subject.logout
36
+ }.to change{ subject.instance_variable_get('@token') }.from(instance_of(String)).to(nil)
37
+ end
38
+
39
+ describe "#check_movie_hash" do
40
+
41
+ it 'should identify movie' do
42
+ subject.check_movie_hash(:moviehash => '37d0c7d0cfcbe280')['data'].should == [{
43
+ "37d0c7d0cfcbe280" => {
44
+ "MovieYear" => "1996",
45
+ "MovieImdbID" => "0117500",
46
+ "MovieName" => "The Rock",
47
+ "MovieHash" => "37d0c7d0cfcbe280"
48
+ }
49
+ }]
50
+ end
51
+
52
+ end
53
+
54
+ describe '#search_subtitles' do
55
+
56
+ it 'can search by hash and size' do
57
+ subs = subject.search_subtitles(:moviehash => 'bd71526264fd8bd9', :moviebytesize => '183406990', :sublanguageid => 'fre')['data']
58
+ subs.should be_a(Array)
59
+ subs.length.should >= 2
60
+ subs.each do |sub|
61
+ sub['LanguageName'].should == 'French'
62
+ sub['MovieName'].should == '"How I Met Your Mother"'
63
+ end
64
+ end
65
+
66
+ it 'can search by imdbid' do
67
+ subs = subject.search_subtitles(:imdbid => "0117500", :sublanguageid => 'fre')['data']
68
+ subs.should be_a(Array)
69
+ subs.length.should >= 1
70
+ subs.each do |sub|
71
+ sub['LanguageName'].should == 'French'
72
+ sub['MovieName'].should == 'The Rock'
73
+ end
74
+ end
75
+
76
+ end
77
+
78
+ end
@@ -0,0 +1,7 @@
1
+ require File.dirname(__FILE__) + '/../lib/osdb'
2
+ require 'spec/autorun'
3
+
4
+ # Spec Helpers
5
+ Dir[File.dirname(__FILE__) + '/*_spec_helper.rb'].each do |f|
6
+ require File.expand_path(f)
7
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: osdb
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Jean Boussier
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain:
16
+ - |
17
+ -----BEGIN CERTIFICATE-----
18
+ MIIDPDCCAiSgAwIBAgIBADANBgkqhkiG9w0BAQUFADBEMRYwFAYDVQQDDA1qZWFu
19
+ LmJvdXNzaWVyMRUwEwYKCZImiZPyLGQBGRYFZ21haWwxEzARBgoJkiaJk/IsZAEZ
20
+ FgNjb20wHhcNMTAwODI5MTExMDIxWhcNMTEwODI5MTExMDIxWjBEMRYwFAYDVQQD
21
+ DA1qZWFuLmJvdXNzaWVyMRUwEwYKCZImiZPyLGQBGRYFZ21haWwxEzARBgoJkiaJ
22
+ k/IsZAEZFgNjb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDN2njY
23
+ b6NqJSE95vA4hrfh8yWP+O9M9V93prYsk2I+TdANS5WUnSCmrh/hp5I/E91A/MS3
24
+ m9OWCLYVWvk+4VyagZjfrCfAC8KDgeGJIb12qWnGTu74EPXnKfQe4v4C23VPfyRC
25
+ 5a4gYO7zYohnHhzXHHqwJM+yh/igC/t7tJn4YUK38zmj+PhvIIepDuiE35Ne27G9
26
+ jqQkXyiAen4qUcNRpX5rRYu6k/9yGmmH9xo5PgGbDaWsgg/HN15BQwqzfJSUrfq0
27
+ wdnuEwVXAulPP/o3WPnEYluUAxWRj3qzuUxB96MWx/37Tc1mou673F6MV94J6M7S
28
+ hoSqPUt/yAJMt3HTAgMBAAGjOTA3MAkGA1UdEwQCMAAwCwYDVR0PBAQDAgSwMB0G
29
+ A1UdDgQWBBSCtLBNhbd1+jrnuT7oUOoceKKGejANBgkqhkiG9w0BAQUFAAOCAQEA
30
+ FULotPT8gpQ8qM4BwycqqQNDfz4ZPZLiGPKqpGfNOWcPT7KU2asjNKr5HX1BC2iX
31
+ 3M7Tedz8NAyJ9CRftwZ/vLaA32ZQSQqEBt94ExYYACFYcfKIQvwo7nNN7eNxkooh
32
+ j1wVwmjwouf8ymN9nYqw/2Pxq5atoswAIGuqzfUy3y65n+fnqhqaoiBmwopsmZtC
33
+ 6HQejy3tLMLukAwJXWkDu6p3YZerOVDRVk4TYJrVy0wlYeDt6/jjQrEeG8+74ErU
34
+ rTLJCndudLnbKo5OeTlwapRqL2NxHRw2No8VtsZhvh+1CNY+fe1SMxY8wJctymkf
35
+ V/TAGOVlGVotOBnewCUdlw==
36
+ -----END CERTIFICATE-----
37
+
38
+ date: 2010-08-29 00:00:00 +02:00
39
+ default_executable:
40
+ dependencies: []
41
+
42
+ description: Ruby library to access OSDb services like OpenSubtitles.org
43
+ email: jean.boussier @nospam@ gmail.com
44
+ executables: []
45
+
46
+ extensions: []
47
+
48
+ extra_rdoc_files:
49
+ - lib/osdb.rb
50
+ - lib/osdb/movie.rb
51
+ - lib/osdb/server.rb
52
+ - lib/osdb/sub.rb
53
+ files:
54
+ - Manifest
55
+ - Rakefile
56
+ - lib/osdb.rb
57
+ - lib/osdb/movie.rb
58
+ - lib/osdb/server.rb
59
+ - lib/osdb/sub.rb
60
+ - spec/fixtures/somemovie.avi
61
+ - spec/osdb/movie_spec.rb
62
+ - spec/osdb/server_spec.rb
63
+ - spec/spec_helper.rb
64
+ - osdb.gemspec
65
+ has_rdoc: true
66
+ homepage: http://github.com/byroot/ruby-osdb
67
+ licenses: []
68
+
69
+ post_install_message:
70
+ rdoc_options:
71
+ - --line-numbers
72
+ - --inline-source
73
+ - --title
74
+ - Osdb
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ segments:
82
+ - 0
83
+ version: "0"
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ segments:
89
+ - 1
90
+ - 2
91
+ version: "1.2"
92
+ requirements: []
93
+
94
+ rubyforge_project: osdb
95
+ rubygems_version: 1.3.6
96
+ signing_key:
97
+ specification_version: 3
98
+ summary: Ruby library to access OSDb services like OpenSubtitles.org
99
+ test_files: []
100
+
Binary file