osdb 0.0.1 → 0.0.2

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.
data.tar.gz.sig CHANGED
Binary file
data/Manifest CHANGED
@@ -1,10 +1,15 @@
1
1
  Manifest
2
2
  Rakefile
3
+ bin/getsub
3
4
  lib/osdb.rb
5
+ lib/osdb/language.rb
4
6
  lib/osdb/movie.rb
5
7
  lib/osdb/server.rb
6
8
  lib/osdb/sub.rb
9
+ osdb.gemspec
7
10
  spec/fixtures/somemovie.avi
11
+ spec/osdb/language_spec.rb
8
12
  spec/osdb/movie_spec.rb
9
13
  spec/osdb/server_spec.rb
14
+ spec/osdb/sub_spec.rb
10
15
  spec/spec_helper.rb
data/Rakefile CHANGED
@@ -10,7 +10,7 @@ end
10
10
  begin
11
11
  require 'echoe'
12
12
 
13
- Echoe.new('osdb', '0.0.1') do |p|
13
+ Echoe.new('osdb', '0.0.2') do |p|
14
14
  p.description = "Ruby library to access OSDb services like OpenSubtitles.org"
15
15
  p.url = "http://github.com/byroot/ruby-osdb"
16
16
  p.author = "Jean Boussier"
@@ -0,0 +1,64 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'optparse'
4
+ require 'uri'
5
+ require 'rubygems'
6
+ require "osdb"
7
+
8
+ def env_lang
9
+ OSDb::Language.from_locale(ENV['LANG'])
10
+ end
11
+
12
+ @options = {:language => env_lang.to_iso639_2b, :force => false }
13
+ @parser ||= OptionParser.new do |opts|
14
+ opts.banner = "Automatically download subs for your video files using opensubtitle.org"
15
+ opts.separator ""
16
+ opts.separator "Usage: getsub [options] VIDEO_FILE [VIDEO_FILE ...]"
17
+ opts.separator ""
18
+ opts.separator "Main options:"
19
+
20
+ opts.on("-l", "--language LANGUAGE", "Sub language ISO 963 code like fre or eng. Default: env $LANG (#{env_lang.to_iso639_2b})") do |language|
21
+ @options[:language] = language
22
+ end
23
+
24
+ opts.on("-f", "--force", "Download sub even if video already has one") { @options[:force] = true }
25
+ end.parse!
26
+
27
+
28
+ class OSDb::Movie
29
+
30
+ def has_sub?
31
+ exist = false
32
+ %w(.srt .sub).each{ |ext| exist ||= File.exist?(path.gsub(File.extname(path), ext)) }
33
+ exist
34
+ end
35
+
36
+ def sub_path(format)
37
+ path.gsub(File.extname(path), ".#{format}")
38
+ end
39
+
40
+ end
41
+
42
+ movies = ARGV.map{ |path| OSDb::Movie.new(path) }
43
+ movies.reject!(&:has_sub?) unless @options[:force]
44
+
45
+ server = OSDb::Server.new(
46
+ :host => 'api.opensubtitles.org',
47
+ :path => '/xml-rpc',
48
+ :timeout => 90,
49
+ :useragent => "SubDownloader 2.0.10" # register useragent ? WTF ? too boring.
50
+ )
51
+ STDOUT.sync = true
52
+
53
+ movies.each do |movie|
54
+ puts "* search subs for: #{movie.path}"
55
+ subs = server.search_subtitles(:moviehash => movie.hash, :moviebytesize => movie.size, :sublanguageid => @options[:language])
56
+ if subs.any?
57
+ sub_path = movie.sub_path(subs.first.format)
58
+ puts "download sub to #{sub_path}"
59
+ %x{ curl '#{subs.first.url}' | gunzip > #{sub_path} & }
60
+ else
61
+ puts "no sub found"
62
+ end
63
+ puts
64
+ end
@@ -2,6 +2,7 @@ require 'xmlrpc/client'
2
2
 
3
3
  module OSDb
4
4
  base_path = File.expand_path(File.dirname(__FILE__) + '/osdb')
5
+ autoload :Language, "#{base_path}/language"
5
6
  autoload :Movie, "#{base_path}/movie"
6
7
  autoload :Server, "#{base_path}/server"
7
8
  autoload :Sub, "#{base_path}/sub"
@@ -0,0 +1,84 @@
1
+ module OSDb
2
+
3
+ LANGUAGES = [
4
+ {:iso639_1 => 'sq', :iso639_2b => 'alb', :locale => 'sq', :name => 'Albanian'},
5
+ {:iso639_1 => 'ar', :iso639_2b => 'ara', :locale => 'ar', :name => 'Arabic'},
6
+ {:iso639_1 => 'hy', :iso639_2b => 'arm', :locale => 'hy', :name => 'Armenian'},
7
+ {:iso639_1 => 'ms', :iso639_2b => 'may', :locale => 'ms', :name => 'Malay'},
8
+ {:iso639_1 => 'bs', :iso639_2b => 'bos', :locale => 'bs', :name => 'Bosnian'},
9
+ {:iso639_1 => 'bg', :iso639_2b => 'bul', :locale => 'bg', :name => 'Bulgarian'},
10
+ {:iso639_1 => 'ca', :iso639_2b => 'cat', :locale => 'ca', :name => 'Catalan'},
11
+ {:iso639_1 => 'eu', :iso639_2b => 'eus', :locale => 'eu', :name => 'Basque'},
12
+ {:iso639_1 => 'zh', :iso639_2b => 'chi', :locale => 'zh_CN', :name => 'Chinese (China)'},
13
+ {:iso639_1 => 'hr', :iso639_2b => 'hrv', :locale => 'hr', :name => 'Croatian'},
14
+ {:iso639_1 => 'cs', :iso639_2b => 'cze', :locale => 'cs', :name => 'Czech'},
15
+ {:iso639_1 => 'da', :iso639_2b => 'dan', :locale => 'da', :name => 'Danish'},
16
+ {:iso639_1 => 'nl', :iso639_2b => 'dut', :locale => 'nl', :name => 'Dutch'},
17
+ {:iso639_1 => 'en', :iso639_2b => 'eng', :locale => 'en', :name => 'English (US)'},
18
+ {:iso639_1 => 'en', :iso639_2b => 'bre', :locale => 'en_GB', :name => 'English (UK)'},
19
+ {:iso639_1 => 'eo', :iso639_2b => 'epo', :locale => 'eo', :name => 'Esperanto'},
20
+ {:iso639_1 => 'et', :iso639_2b => 'est', :locale => 'et', :name => 'Estonian'},
21
+ {:iso639_1 => 'fi', :iso639_2b => 'fin', :locale => 'fi', :name => 'Finnish'},
22
+ {:iso639_1 => 'fr', :iso639_2b => 'fre', :locale => 'fr', :name => 'French'},
23
+ {:iso639_1 => 'gl', :iso639_2b => 'glg', :locale => 'gl', :name => 'Galician'},
24
+ {:iso639_1 => 'ka', :iso639_2b => 'geo', :locale => 'ka', :name => 'Georgian'},
25
+ {:iso639_1 => 'de', :iso639_2b => 'ger', :locale => 'de', :name => 'German'},
26
+ {:iso639_1 => 'el', :iso639_2b => 'ell', :locale => 'el', :name => 'Greek'},
27
+ {:iso639_1 => 'he', :iso639_2b => 'heb', :locale => 'he', :name => 'Hebrew'},
28
+ {:iso639_1 => 'hu', :iso639_2b => 'hun', :locale => 'hu', :name => 'Hungarian'},
29
+ {:iso639_1 => 'id', :iso639_2b => 'ind', :locale => 'id', :name => 'Indonesian'},
30
+ {:iso639_1 => 'it', :iso639_2b => 'ita', :locale => 'it', :name => 'Italian'},
31
+ {:iso639_1 => 'ja', :iso639_2b => 'jpn', :locale => 'ja', :name => 'Japanese'},
32
+ {:iso639_1 => 'kk', :iso639_2b => 'kaz', :locale => 'kk', :name => 'Kazakh'},
33
+ {:iso639_1 => 'ko', :iso639_2b => 'kor', :locale => 'ko', :name => 'Korean'},
34
+ {:iso639_1 => 'lv', :iso639_2b => 'lav', :locale => 'lv', :name => 'Latvian'},
35
+ {:iso639_1 => 'lt', :iso639_2b => 'lit', :locale => 'lt', :name => 'Lithuanian'},
36
+ {:iso639_1 => 'lb', :iso639_2b => 'ltz', :locale => 'lb', :name => 'Luxembourgish'},
37
+ {:iso639_1 => 'mk', :iso639_2b => 'mac', :locale => 'mk', :name => 'Macedonian'},
38
+ {:iso639_1 => 'no', :iso639_2b => 'nor', :locale => 'no', :name => 'Norwegian'},
39
+ {:iso639_1 => 'fa', :iso639_2b => 'per', :locale => 'fa', :name => 'Persian'},
40
+ {:iso639_1 => 'pl', :iso639_2b => 'pol', :locale => 'pl', :name => 'Polish'},
41
+ {:iso639_1 => 'pt', :iso639_2b => 'por', :locale => 'pt_PT', :name => 'Portuguese (Portugal)'},
42
+ {:iso639_1 => 'pb', :iso639_2b => 'pob', :locale => 'pt_BR', :name => 'Portuguese (Brazil)'},
43
+ {:iso639_1 => 'ro', :iso639_2b => 'rum', :locale => 'ro', :name => 'Romanian'},
44
+ {:iso639_1 => 'ru', :iso639_2b => 'rus', :locale => 'ru', :name => 'Russian'},
45
+ {:iso639_1 => 'sr', :iso639_2b => 'scc', :locale => 'sr', :name => 'Serbian'},
46
+ {:iso639_1 => 'sk', :iso639_2b => 'slo', :locale => 'sk', :name => 'Slovak'},
47
+ {:iso639_1 => 'sl', :iso639_2b => 'slv', :locale => 'sl', :name => 'Slovenian'},
48
+ {:iso639_1 => 'es', :iso639_2b => 'spa', :locale => 'es_ES', :name => 'Spanish (Spain)'},
49
+ {:iso639_1 => 'sv', :iso639_2b => 'swe', :locale => 'sv', :name => 'Swedish'},
50
+ {:iso639_1 => 'th', :iso639_2b => 'tha', :locale => 'th', :name => 'Thai'},
51
+ {:iso639_1 => 'tr', :iso639_2b => 'tur', :locale => 'tr', :name => 'Turkish'},
52
+ {:iso639_1 => 'uk', :iso639_2b => 'ukr', :locale => 'uk', :name => 'Ukrainian'},
53
+ {:iso639_1 => 'vi', :iso639_2b => 'vie', :locale => 'vi', :name => 'Vietnamese'}
54
+ ]
55
+
56
+ class Language
57
+
58
+ class << self
59
+
60
+ def from_locale(locale)
61
+ locale = locale.split('.').first
62
+ lang = LANGUAGES.find{ |lang| lang[:locale] == locale }
63
+ return from_locale(locale.split('_').first) if !lang && locale.include?('_')
64
+ new(lang)
65
+ end
66
+
67
+ def from_iso639_2b(code)
68
+ new(LANGUAGES.find{ |lang| lang[:iso639_2b] == code })
69
+ end
70
+
71
+ end
72
+
73
+ attr_reader :name, :to_iso639_1, :to_iso639_2b, :to_locale
74
+
75
+ def initialize(hash)
76
+ @name = hash[:name]
77
+ @to_iso639_1 = hash[:iso639_1]
78
+ @to_iso639_2b = hash[:iso639_2b]
79
+ @to_locale = hash[:locale]
80
+ end
81
+
82
+ end
83
+
84
+ end
@@ -10,7 +10,7 @@ module OSDb
10
10
  def initialize(options={})
11
11
  @username = options[:username] || ''
12
12
  @password = options[:password] || ''
13
- @language = options[:language] || 'en'
13
+ @language = options[:language] || 'eng'
14
14
  @useragent = options[:useragent] || 'ruby-osdb v0.1'
15
15
  @client = ::XMLRPC::Client.new(*options.values_at(:host, :path, :port, :proxy_host, :proxy_port, :http_user, :http_password, :use_ssl, :timeout))
16
16
  end
@@ -37,7 +37,8 @@ module OSDb
37
37
  end
38
38
 
39
39
  def search_subtitles(*queries)
40
- client.call('SearchSubtitles', token, queries)
40
+ subs = client.call('SearchSubtitles', token, queries)['data']
41
+ subs ? subs.map{ |s| Sub.new(s) } : []
41
42
  end
42
43
 
43
44
  def info
@@ -1,4 +1,19 @@
1
+ require 'uri'
2
+
1
3
  module OSDb
4
+
2
5
  class Sub
6
+
7
+ attr_reader :url, :format, :language, :rating, :raw_data
8
+
9
+ def initialize(data)
10
+ @url = URI.parse(data['SubDownloadLink'])
11
+ @format = data['SubFormat']
12
+ @language = Language.from_iso639_2b(data['SubLanguageID'])
13
+ @rating = data['SubRating']
14
+ @raw_data = data
15
+ end
16
+
3
17
  end
18
+
4
19
  end
@@ -2,21 +2,23 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{osdb}
5
- s.version = "0.0.1"
5
+ s.version = "0.0.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Jean Boussier"]
9
9
  s.cert_chain = ["/Users/byroot/.ssh/gem-public_cert.pem"]
10
- s.date = %q{2010-08-29}
10
+ s.date = %q{2010-09-29}
11
+ s.default_executable = %q{getsub}
11
12
  s.description = %q{Ruby library to access OSDb services like OpenSubtitles.org}
12
13
  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"]
14
+ s.executables = ["getsub"]
15
+ s.extra_rdoc_files = ["bin/getsub", "lib/osdb.rb", "lib/osdb/language.rb", "lib/osdb/movie.rb", "lib/osdb/server.rb", "lib/osdb/sub.rb"]
16
+ s.files = ["Manifest", "Rakefile", "bin/getsub", "lib/osdb.rb", "lib/osdb/language.rb", "lib/osdb/movie.rb", "lib/osdb/server.rb", "lib/osdb/sub.rb", "osdb.gemspec", "spec/fixtures/somemovie.avi", "spec/osdb/language_spec.rb", "spec/osdb/movie_spec.rb", "spec/osdb/server_spec.rb", "spec/osdb/sub_spec.rb", "spec/spec_helper.rb"]
15
17
  s.homepage = %q{http://github.com/byroot/ruby-osdb}
16
18
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Osdb"]
17
19
  s.require_paths = ["lib"]
18
20
  s.rubyforge_project = %q{osdb}
19
- s.rubygems_version = %q{1.3.6}
21
+ s.rubygems_version = %q{1.3.7}
20
22
  s.signing_key = %q{/Users/byroot/.ssh/gem-private_key.pem}
21
23
  s.summary = %q{Ruby library to access OSDb services like OpenSubtitles.org}
22
24
 
@@ -24,7 +26,7 @@ Gem::Specification.new do |s|
24
26
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
25
27
  s.specification_version = 3
26
28
 
27
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
29
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
28
30
  else
29
31
  end
30
32
  else
@@ -0,0 +1,57 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe OSDb::Language do
4
+
5
+ describe '.from_locale' do
6
+
7
+ describe "simple locale" do
8
+
9
+ subject{ OSDb::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{ OSDb::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{ OSDb::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{ OSDb::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
@@ -1,6 +1,6 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
2
 
3
- describe OSDb::Server do
3
+ describe OSDb::Movie do
4
4
 
5
5
  subject do
6
6
  OSDb::Movie.new(File.dirname(__FILE__) + '/../fixtures/somemovie.avi')
@@ -54,22 +54,22 @@ describe OSDb::Server do
54
54
  describe '#search_subtitles' do
55
55
 
56
56
  it 'can search by hash and size' do
57
- subs = subject.search_subtitles(:moviehash => 'bd71526264fd8bd9', :moviebytesize => '183406990', :sublanguageid => 'fre')['data']
57
+ subs = subject.search_subtitles(:moviehash => 'bd71526264fd8bd9', :moviebytesize => '183406990', :sublanguageid => 'fre')
58
58
  subs.should be_a(Array)
59
59
  subs.length.should >= 2
60
60
  subs.each do |sub|
61
- sub['LanguageName'].should == 'French'
62
- sub['MovieName'].should == '"How I Met Your Mother"'
61
+ sub.language.name.should == 'French'
62
+ sub.raw_data['MovieName'].should == '"How I Met Your Mother"'
63
63
  end
64
64
  end
65
65
 
66
66
  it 'can search by imdbid' do
67
- subs = subject.search_subtitles(:imdbid => "0117500", :sublanguageid => 'fre')['data']
67
+ subs = subject.search_subtitles(:imdbid => "0117500", :sublanguageid => 'fre')
68
68
  subs.should be_a(Array)
69
69
  subs.length.should >= 1
70
70
  subs.each do |sub|
71
- sub['LanguageName'].should == 'French'
72
- sub['MovieName'].should == 'The Rock'
71
+ sub.language.name.should == 'French'
72
+ sub.raw_data['MovieName'].should == 'The Rock'
73
73
  end
74
74
  end
75
75
 
@@ -0,0 +1,22 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe OSDb::Sub do
4
+
5
+ subject do
6
+ OSDb::Sub.new(
7
+ 'SubFormat' => 'srt',
8
+ 'SubDownloadLink' => 'http://example.com/foo.srt.gz',
9
+ 'SubRating' => 7.89,
10
+ 'SubLanguageID' => 'dut'
11
+ )
12
+ end
13
+
14
+ its(:format) { should == 'srt' }
15
+
16
+ its(:url) { should be_an(URI::HTTP) }
17
+
18
+ its(:language) { should be_a(OSDb::Language) }
19
+
20
+ its(:rating) { should == 7.89 }
21
+
22
+ end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: osdb
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 27
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 0
8
- - 1
9
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
10
11
  platform: ruby
11
12
  authors:
12
13
  - Jean Boussier
@@ -35,33 +36,39 @@ cert_chain:
35
36
  V/TAGOVlGVotOBnewCUdlw==
36
37
  -----END CERTIFICATE-----
37
38
 
38
- date: 2010-08-29 00:00:00 +02:00
39
+ date: 2010-09-29 00:00:00 +02:00
39
40
  default_executable:
40
41
  dependencies: []
41
42
 
42
43
  description: Ruby library to access OSDb services like OpenSubtitles.org
43
44
  email: jean.boussier @nospam@ gmail.com
44
- executables: []
45
-
45
+ executables:
46
+ - getsub
46
47
  extensions: []
47
48
 
48
49
  extra_rdoc_files:
50
+ - bin/getsub
49
51
  - lib/osdb.rb
52
+ - lib/osdb/language.rb
50
53
  - lib/osdb/movie.rb
51
54
  - lib/osdb/server.rb
52
55
  - lib/osdb/sub.rb
53
56
  files:
54
57
  - Manifest
55
58
  - Rakefile
59
+ - bin/getsub
56
60
  - lib/osdb.rb
61
+ - lib/osdb/language.rb
57
62
  - lib/osdb/movie.rb
58
63
  - lib/osdb/server.rb
59
64
  - lib/osdb/sub.rb
65
+ - osdb.gemspec
60
66
  - spec/fixtures/somemovie.avi
67
+ - spec/osdb/language_spec.rb
61
68
  - spec/osdb/movie_spec.rb
62
69
  - spec/osdb/server_spec.rb
70
+ - spec/osdb/sub_spec.rb
63
71
  - spec/spec_helper.rb
64
- - osdb.gemspec
65
72
  has_rdoc: true
66
73
  homepage: http://github.com/byroot/ruby-osdb
67
74
  licenses: []
@@ -75,16 +82,20 @@ rdoc_options:
75
82
  require_paths:
76
83
  - lib
77
84
  required_ruby_version: !ruby/object:Gem::Requirement
85
+ none: false
78
86
  requirements:
79
87
  - - ">="
80
88
  - !ruby/object:Gem::Version
89
+ hash: 3
81
90
  segments:
82
91
  - 0
83
92
  version: "0"
84
93
  required_rubygems_version: !ruby/object:Gem::Requirement
94
+ none: false
85
95
  requirements:
86
96
  - - ">="
87
97
  - !ruby/object:Gem::Version
98
+ hash: 11
88
99
  segments:
89
100
  - 1
90
101
  - 2
@@ -92,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
103
  requirements: []
93
104
 
94
105
  rubyforge_project: osdb
95
- rubygems_version: 1.3.6
106
+ rubygems_version: 1.3.7
96
107
  signing_key:
97
108
  specification_version: 3
98
109
  summary: Ruby library to access OSDb services like OpenSubtitles.org
metadata.gz.sig CHANGED
Binary file