osdb 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
Binary file
data/Manifest CHANGED
@@ -1,4 +1,5 @@
1
1
  Manifest
2
+ README.md
2
3
  Rakefile
3
4
  bin/getsub
4
5
  lib/osdb.rb
data/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # OSDb
2
+
3
+ Client library for the [OSDb protocol](http://trac.opensubtitles.org/projects/opensubtitles/wiki/XMLRPC).
4
+ Currently the implentation is limited to movie identification and subtitles search
5
+
6
+ ## Examples
7
+
8
+ Just read the source of `bin/getsub` it is a typical example of OSDb's capacities.
9
+
10
+ ## getsub
11
+
12
+ The osdb gem provide a simple script to find and download the best subtitle on
13
+ [opensubtitles.org](http://www.opensubtitles.org/) for your video file.
14
+
15
+ ### Installation
16
+
17
+ $ gem install osdb
18
+
19
+ ### Usage
20
+
21
+ You just have to execute `getsub` with some video files in arguments:
22
+
23
+ $ getsub somemovie.avi othermovie.mkv
24
+
25
+ For options details just run:
26
+
27
+ $ getsub --help
data/Rakefile CHANGED
@@ -10,14 +10,16 @@ end
10
10
  begin
11
11
  require 'echoe'
12
12
 
13
- Echoe.new('osdb', '0.0.2') do |p|
13
+ Echoe.new('osdb', '0.0.3') 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"
17
17
  p.email = "jean.boussier @nospam@ gmail.com"
18
18
  end
19
19
 
20
- rescue LoadError
20
+ rescue LoadError => e
21
+ puts "Failed to load Echoe"
22
+ puts e.message
21
23
  end
22
24
 
23
25
  task :default => :spec
data/bin/getsub CHANGED
@@ -22,7 +22,8 @@ end
22
22
  end
23
23
 
24
24
  opts.on("-f", "--force", "Download sub even if video already has one") { @options[:force] = true }
25
- end.parse!
25
+ end
26
+ @parser.parse!
26
27
 
27
28
 
28
29
  class OSDb::Movie
@@ -39,6 +40,56 @@ class OSDb::Movie
39
40
 
40
41
  end
41
42
 
43
+ def curl_available?
44
+ %x{ curl --version 2> /dev/null > /dev/null }
45
+ $?.success?
46
+ end
47
+
48
+ def wget_available?
49
+ %x{ wget --version 2> /dev/null > /dev/null }
50
+ $?.success?
51
+ end
52
+
53
+ def download!(url, local_path)
54
+ puts "* download #{url} to #{local_path}"
55
+ if curl_available?
56
+ %x{ curl '#{url}' | gunzip > '#{local_path}' }
57
+ elsif wget_available?
58
+ %x{ wget -O - '#{url}' | gunzip > '#{local_path}'}
59
+ else
60
+ puts "Can't found any curl or wget please install one of them or manualy download your sub"
61
+ puts url
62
+ end
63
+ end
64
+
65
+ def group_by_movie_name(subs)
66
+ subs.inject({}) do |hash, sub|
67
+ hash[sub.movie_name] ||= []
68
+ hash[sub.movie_name] << sub
69
+ hash
70
+ end
71
+ end
72
+
73
+ def ask_user_to_identify_movie(movies)
74
+ puts "D'oh! You stumbled upon a hash conflict, please resolve it:"
75
+ puts
76
+ movies.keys.each_with_index do |name, index|
77
+ puts " #{index} - #{name}"
78
+ end
79
+ puts
80
+ print 'id: '
81
+ str = STDIN.gets
82
+ movies[movies.keys[str.to_i]]
83
+ end
84
+
85
+ def select_sub(subs)
86
+ return subs.first if subs.length == 1
87
+ movies = group_by_movie_name(subs)
88
+ return movies.values.first.max(&:rating) if movies.length == 1
89
+ selected_movie_subs = ask_user_to_identify_movie(movies)
90
+ selected_movie_subs.max(&:rating)
91
+ end
92
+
42
93
  movies = ARGV.map{ |path| OSDb::Movie.new(path) }
43
94
  movies.reject!(&:has_sub?) unless @options[:force]
44
95
 
@@ -50,15 +101,21 @@ server = OSDb::Server.new(
50
101
  )
51
102
  STDOUT.sync = true
52
103
 
104
+ if movies.empty?
105
+ puts "No file provided"
106
+ puts @parser.help
107
+ exit 1
108
+ end
109
+
53
110
  movies.each do |movie|
54
111
  puts "* search subs for: #{movie.path}"
55
112
  subs = server.search_subtitles(:moviehash => movie.hash, :moviebytesize => movie.size, :sublanguageid => @options[:language])
56
113
  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} & }
114
+ sub = select_sub(subs)
115
+ sub_path = movie.sub_path(sub.format)
116
+ download!(sub.url, sub_path)
60
117
  else
61
- puts "no sub found"
118
+ puts "* no sub found"
62
119
  end
63
120
  puts
64
121
  end
data/lib/osdb/sub.rb CHANGED
@@ -4,13 +4,14 @@ module OSDb
4
4
 
5
5
  class Sub
6
6
 
7
- attr_reader :url, :format, :language, :rating, :raw_data
7
+ attr_reader :url, :format, :language, :rating, :movie_name, :raw_data
8
8
 
9
9
  def initialize(data)
10
10
  @url = URI.parse(data['SubDownloadLink'])
11
11
  @format = data['SubFormat']
12
12
  @language = Language.from_iso639_2b(data['SubLanguageID'])
13
13
  @rating = data['SubRating']
14
+ @movie_name = data['MovieName']
14
15
  @raw_data = data
15
16
  end
16
17
 
data/osdb.gemspec CHANGED
@@ -2,20 +2,20 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{osdb}
5
- s.version = "0.0.2"
5
+ s.version = "0.0.3"
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-09-29}
10
+ s.date = %q{2010-10-17}
11
11
  s.default_executable = %q{getsub}
12
12
  s.description = %q{Ruby library to access OSDb services like OpenSubtitles.org}
13
13
  s.email = %q{jean.boussier @nospam@ gmail.com}
14
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
+ s.extra_rdoc_files = ["README.md", "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", "README.md", "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"]
17
17
  s.homepage = %q{http://github.com/byroot/ruby-osdb}
18
- s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Osdb"]
18
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Osdb", "--main", "README.md"]
19
19
  s.require_paths = ["lib"]
20
20
  s.rubyforge_project = %q{osdb}
21
21
  s.rubygems_version = %q{1.3.7}
@@ -6,7 +6,8 @@ describe OSDb::Server do
6
6
  @server = OSDb::Server.new(
7
7
  :host => 'api.opensubtitles.org',
8
8
  :path => '/xml-rpc',
9
- :timeout => 60 # OS.org is very very slow ....
9
+ :timeout => 60, # OS.org is very very slow ....
10
+ :useragent => 'OS Test User Agent'
10
11
  )
11
12
  end
12
13
 
@@ -39,14 +40,14 @@ describe OSDb::Server do
39
40
  describe "#check_movie_hash" do
40
41
 
41
42
  it 'should identify movie' do
42
- subject.check_movie_hash(:moviehash => '37d0c7d0cfcbe280')['data'].should == [{
43
+ subject.check_movie_hash('37d0c7d0cfcbe280')['data'].should == {
43
44
  "37d0c7d0cfcbe280" => {
44
45
  "MovieYear" => "1996",
45
46
  "MovieImdbID" => "0117500",
46
47
  "MovieName" => "The Rock",
47
48
  "MovieHash" => "37d0c7d0cfcbe280"
48
49
  }
49
- }]
50
+ }
50
51
  end
51
52
 
52
53
  end
@@ -7,7 +7,8 @@ describe OSDb::Sub do
7
7
  'SubFormat' => 'srt',
8
8
  'SubDownloadLink' => 'http://example.com/foo.srt.gz',
9
9
  'SubRating' => 7.89,
10
- 'SubLanguageID' => 'dut'
10
+ 'SubLanguageID' => 'dut',
11
+ 'MovieName' => 'Lock, Stock and Two Smoking Barrels'
11
12
  )
12
13
  end
13
14
 
@@ -19,4 +20,6 @@ describe OSDb::Sub do
19
20
 
20
21
  its(:rating) { should == 7.89 }
21
22
 
22
- end
23
+ its(:movie_name) { should == 'Lock, Stock and Two Smoking Barrels' }
24
+
25
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: osdb
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jean Boussier
@@ -36,7 +36,7 @@ cert_chain:
36
36
  V/TAGOVlGVotOBnewCUdlw==
37
37
  -----END CERTIFICATE-----
38
38
 
39
- date: 2010-09-29 00:00:00 +02:00
39
+ date: 2010-10-17 00:00:00 +02:00
40
40
  default_executable:
41
41
  dependencies: []
42
42
 
@@ -47,6 +47,7 @@ executables:
47
47
  extensions: []
48
48
 
49
49
  extra_rdoc_files:
50
+ - README.md
50
51
  - bin/getsub
51
52
  - lib/osdb.rb
52
53
  - lib/osdb/language.rb
@@ -55,6 +56,7 @@ extra_rdoc_files:
55
56
  - lib/osdb/sub.rb
56
57
  files:
57
58
  - Manifest
59
+ - README.md
58
60
  - Rakefile
59
61
  - bin/getsub
60
62
  - lib/osdb.rb
@@ -79,6 +81,8 @@ rdoc_options:
79
81
  - --inline-source
80
82
  - --title
81
83
  - Osdb
84
+ - --main
85
+ - README.md
82
86
  require_paths:
83
87
  - lib
84
88
  required_ruby_version: !ruby/object:Gem::Requirement
metadata.gz.sig CHANGED
Binary file