osdb 0.0.4 → 0.0.5

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/README.md CHANGED
@@ -22,6 +22,10 @@ You just have to execute `getsub` with some video files in arguments:
22
22
 
23
23
  $ getsub somemovie.avi othermovie.mkv
24
24
 
25
+ Or specify a directory to search recursively:
26
+
27
+ $ getsub -d ~/Movies
28
+
25
29
  For options details just run:
26
30
 
27
31
  $ getsub --help
data/Rakefile CHANGED
@@ -10,7 +10,7 @@ end
10
10
  begin
11
11
  require 'echoe'
12
12
 
13
- Echoe.new('osdb', '0.0.4') do |p|
13
+ Echoe.new('osdb', '0.0.5') 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"
data/bin/getsub CHANGED
@@ -1,19 +1,19 @@
1
- #!/usr/bin/ruby
1
+ #!/usr/bin/env ruby
2
2
 
3
3
  require 'optparse'
4
4
  require 'uri'
5
5
  require 'rubygems'
6
- require "osdb"
6
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'osdb'))
7
7
 
8
8
  def env_lang
9
9
  OSDb::Language.from_locale(ENV['LANG'])
10
10
  end
11
11
 
12
- @options = {:language => env_lang.to_iso639_2b, :force => false }
12
+ @options = {:language => env_lang.to_iso639_2b, :force => false, :dir => nil }
13
13
  @parser ||= OptionParser.new do |opts|
14
14
  opts.banner = "Automatically download subs for your video files using opensubtitle.org"
15
15
  opts.separator ""
16
- opts.separator "Usage: getsub [options] VIDEO_FILE [VIDEO_FILE ...]"
16
+ opts.separator "Usage: getsub [options] DIRECTORY | VIDEO_FILE [VIDEO_FILE ...]"
17
17
  opts.separator ""
18
18
  opts.separator "Main options:"
19
19
 
@@ -21,24 +21,13 @@ end
21
21
  @options[:language] = language
22
22
  end
23
23
 
24
- opts.on("-f", "--force", "Download sub even if video already has one") { @options[:force] = true }
25
- end
26
- @parser.parse!
27
-
28
-
29
- class OSDb::Movie
30
-
31
- def has_sub?
32
- exist = false
33
- %w(.srt .sub).each{ |ext| exist ||= File.exist?(path.gsub(File.extname(path), ext)) }
34
- exist
35
- end
36
-
37
- def sub_path(format)
38
- path.gsub(File.extname(path), ".#{format}")
24
+ opts.on("-d", "--directory DIRECTORY", "Specify a directory to search recursively for movies") do |dir|
25
+ @options[:dir] = dir
39
26
  end
40
27
 
28
+ opts.on("-f", "--force", "Download sub even if video already has one") { @options[:force] = true }
41
29
  end
30
+ @parser.parse!
42
31
 
43
32
  def curl_available?
44
33
  %x{ curl --version 2> /dev/null > /dev/null }
@@ -53,9 +42,9 @@ end
53
42
  def download!(url, local_path)
54
43
  puts "* download #{url} to #{local_path}"
55
44
  if curl_available?
56
- %x{ curl '#{url}' | gunzip > '#{local_path}' }
45
+ %x{ curl -s '#{url}' | gunzip > "#{local_path}" }
57
46
  elsif wget_available?
58
- %x{ wget -O - '#{url}' | gunzip > '#{local_path}'}
47
+ %x{ wget -O -quiet - '#{url}' | gunzip > "#{local_path}"}
59
48
  else
60
49
  puts "Can't found any curl or wget please install one of them or manualy download your sub"
61
50
  puts url
@@ -90,7 +79,12 @@ def select_sub(subs)
90
79
  selected_movie_subs.max
91
80
  end
92
81
 
93
- movies = ARGV.map{ |path| OSDb::Movie.new(path) }
82
+ def arg_files
83
+ return ARGV unless @options[:dir]
84
+ Dir.glob(File.join(@options[:dir], '**', "*.{#{OSDb::Movie::EXTENSIONS.join(',')}}"))
85
+ end
86
+
87
+ movies = arg_files.map{ |path| OSDb::Movie.new(path) }
94
88
  movies.reject!(&:has_sub?) unless @options[:force]
95
89
 
96
90
  server = OSDb::Server.new(
@@ -108,14 +102,19 @@ if movies.empty?
108
102
  end
109
103
 
110
104
  movies.each do |movie|
111
- puts "* search subs for: #{movie.path}"
112
- subs = server.search_subtitles(:moviehash => movie.hash, :moviebytesize => movie.size, :sublanguageid => @options[:language])
113
- if subs.any?
114
- sub = select_sub(subs)
115
- sub_path = movie.sub_path(sub.format)
116
- download!(sub.url, sub_path)
117
- else
118
- puts "* no sub found"
105
+ begin
106
+ puts "* search subs for: #{movie.path}"
107
+ subs = server.search_subtitles(:moviehash => movie.hash, :moviebytesize => movie.size, :sublanguageid => @options[:language])
108
+ if subs.any?
109
+ sub = select_sub(subs)
110
+ sub_path = movie.sub_path(sub.format)
111
+ download!(sub.url, sub_path)
112
+ else
113
+ puts "* no sub found"
114
+ end
115
+ puts
116
+ rescue Exception => e
117
+ puts "#{e.class.name}: #{e.message}:"
118
+ puts e.backtrace
119
119
  end
120
- puts
121
120
  end
data/lib/osdb/movie.rb CHANGED
@@ -1,11 +1,23 @@
1
1
  module OSDb
2
2
  class Movie
3
3
 
4
+ EXTENSIONS = %w(avi mpg m4v mkv mov ogv)
5
+
4
6
  attr_reader :path
5
7
 
6
8
  def initialize(path)
7
9
  @path = path
8
10
  end
11
+
12
+ def has_sub?
13
+ exist = false
14
+ %w(.srt .sub).each{ |ext| exist ||= File.exist?(path.gsub(File.extname(path), ext)) }
15
+ exist
16
+ end
17
+
18
+ def sub_path(format)
19
+ path.gsub(File.extname(path), ".#{format}")
20
+ end
9
21
 
10
22
  def hash
11
23
  @hash ||= self.class.compute_hash(path)
data/osdb.gemspec CHANGED
@@ -2,12 +2,12 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{osdb}
5
- s.version = "0.0.4"
5
+ s.version = "0.0.5"
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-10-30}
10
+ s.date = %q{2010-12-03}
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}
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: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 5
10
+ version: 0.0.5
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-10-30 00:00:00 +02:00
39
+ date: 2010-12-03 00:00:00 +01:00
40
40
  default_executable:
41
41
  dependencies: []
42
42
 
metadata.gz.sig CHANGED
Binary file