suby 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/suby.rb +17 -17
- data/lib/suby/downloader.rb +7 -11
- data/lib/suby/downloader/addic7ed.rb +0 -2
- data/lib/suby/downloader/tvsubtitles.rb +0 -2
- data/lib/suby/filename_parser.rb +1 -1
- data/suby.gemspec +3 -2
- metadata +20 -11
- data/lib/suby/downloader_error.rb +0 -4
- data/lib/suby/not_found_error.rb +0 -4
data/lib/suby.rb
CHANGED
@@ -1,25 +1,26 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
require 'epath'
|
2
|
+
require 'zip/zip'
|
3
|
+
|
3
4
|
require_relative 'suby/filename_parser'
|
4
5
|
require_relative 'suby/downloader'
|
5
6
|
require_relative 'suby/interface'
|
6
7
|
|
7
|
-
gem 'rubyzip2'
|
8
|
-
require 'zip'
|
9
|
-
|
10
8
|
module Suby
|
11
|
-
|
12
|
-
|
9
|
+
NotFoundError = Class.new StandardError
|
10
|
+
DownloaderError = Class.new StandardError
|
11
|
+
|
12
|
+
SUB_EXTENSIONS = %w[srt sub]
|
13
|
+
TEMP_ARCHIVE = Path('__archive__')
|
13
14
|
|
14
15
|
class << self
|
15
16
|
include Interface
|
16
17
|
|
17
18
|
def download_subtitles(files, options = {})
|
18
19
|
files.each { |file|
|
19
|
-
|
20
|
+
file = Path(file)
|
21
|
+
next if file.directory? or SUB_EXTENSIONS.include?(file.ext)
|
20
22
|
next puts "Skipping: #{file}" if SUB_EXTENSIONS.any? { |ext|
|
21
|
-
|
22
|
-
File.exist? st and File.size(st) > 0
|
23
|
+
f = file.sub_ext(ext) and f.exist? and !f.empty?
|
23
24
|
}
|
24
25
|
download_subtitles_for_file(file, options)
|
25
26
|
}
|
@@ -56,23 +57,22 @@ module Suby
|
|
56
57
|
end
|
57
58
|
end
|
58
59
|
|
59
|
-
def extract_sub_from_archive(archive, format,
|
60
|
+
def extract_sub_from_archive(archive, format, file)
|
60
61
|
case format
|
61
62
|
when :zip
|
62
|
-
Zip::ZipFile.open(archive) { |zip|
|
63
|
+
Zip::ZipFile.open(archive.to_s) { |zip|
|
63
64
|
sub = zip.entries.find { |entry|
|
64
|
-
entry.to_s =~
|
65
|
+
entry.to_s =~ /\.#{Regexp.union SUB_EXTENSIONS}$/
|
65
66
|
}
|
66
67
|
raise "no subtitles in #{archive}" unless sub
|
67
|
-
name =
|
68
|
-
sub.extract(name)
|
68
|
+
name = file.sub_ext(Path(sub).ext)
|
69
|
+
sub.extract(name.to_s)
|
69
70
|
}
|
70
71
|
else
|
71
72
|
raise "unknown archive type (#{archive})"
|
72
73
|
end
|
73
74
|
ensure
|
74
|
-
|
75
|
-
File.unlink archive if File.exist? archive
|
75
|
+
archive.unlink if archive.exist?
|
76
76
|
end
|
77
77
|
end
|
78
78
|
end
|
data/lib/suby/downloader.rb
CHANGED
@@ -5,7 +5,7 @@ require 'nokogiri'
|
|
5
5
|
module Suby
|
6
6
|
class Downloader
|
7
7
|
DOWNLOADERS = []
|
8
|
-
def self.
|
8
|
+
def self.inherited(downloader)
|
9
9
|
DOWNLOADERS << downloader
|
10
10
|
end
|
11
11
|
|
@@ -85,28 +85,24 @@ module Suby
|
|
85
85
|
format = self.class::FORMAT
|
86
86
|
case format
|
87
87
|
when :file
|
88
|
-
|
88
|
+
sub_name(contents).write contents
|
89
89
|
when :zip
|
90
|
-
|
91
|
-
Suby.extract_sub_from_archive(
|
90
|
+
TEMP_ARCHIVE.write contents
|
91
|
+
Suby.extract_sub_from_archive(TEMP_ARCHIVE, format, file)
|
92
92
|
else
|
93
93
|
raise "unknown subtitles format: #{format}"
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
97
|
-
def basename
|
98
|
-
File.basename(file, File.extname(file))
|
99
|
-
end
|
100
|
-
|
101
97
|
def sub_name(contents)
|
102
|
-
|
98
|
+
file.sub_ext sub_extension(contents)
|
103
99
|
end
|
104
100
|
|
105
101
|
def sub_extension(contents)
|
106
102
|
if contents[0..10] =~ /1\r?\n/
|
107
|
-
'
|
103
|
+
'srt'
|
108
104
|
else
|
109
|
-
'
|
105
|
+
'sub'
|
110
106
|
end
|
111
107
|
end
|
112
108
|
end
|
data/lib/suby/filename_parser.rb
CHANGED
data/suby.gemspec
CHANGED
@@ -10,9 +10,10 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.executables = ['suby']
|
11
11
|
|
12
12
|
s.required_ruby_version = '>= 1.9.2'
|
13
|
+
s.add_dependency 'epath', '>= 0.1.0'
|
13
14
|
s.add_dependency 'nokogiri'
|
14
|
-
s.add_dependency '
|
15
|
+
s.add_dependency 'rubyzip'
|
15
16
|
s.add_dependency 'term-ansicolor'
|
16
17
|
|
17
|
-
s.version = '0.1.
|
18
|
+
s.version = '0.1.4'
|
18
19
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: suby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,22 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-04-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: epath
|
16
|
+
requirement: &2152477380 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.1.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2152477380
|
14
25
|
- !ruby/object:Gem::Dependency
|
15
26
|
name: nokogiri
|
16
|
-
requirement: &
|
27
|
+
requirement: &2152476880 !ruby/object:Gem::Requirement
|
17
28
|
none: false
|
18
29
|
requirements:
|
19
30
|
- - ! '>='
|
@@ -21,10 +32,10 @@ dependencies:
|
|
21
32
|
version: '0'
|
22
33
|
type: :runtime
|
23
34
|
prerelease: false
|
24
|
-
version_requirements: *
|
35
|
+
version_requirements: *2152476880
|
25
36
|
- !ruby/object:Gem::Dependency
|
26
|
-
name:
|
27
|
-
requirement: &
|
37
|
+
name: rubyzip
|
38
|
+
requirement: &2152476000 !ruby/object:Gem::Requirement
|
28
39
|
none: false
|
29
40
|
requirements:
|
30
41
|
- - ! '>='
|
@@ -32,10 +43,10 @@ dependencies:
|
|
32
43
|
version: '0'
|
33
44
|
type: :runtime
|
34
45
|
prerelease: false
|
35
|
-
version_requirements: *
|
46
|
+
version_requirements: *2152476000
|
36
47
|
- !ruby/object:Gem::Dependency
|
37
48
|
name: term-ansicolor
|
38
|
-
requirement: &
|
49
|
+
requirement: &2152475540 !ruby/object:Gem::Requirement
|
39
50
|
none: false
|
40
51
|
requirements:
|
41
52
|
- - ! '>='
|
@@ -43,7 +54,7 @@ dependencies:
|
|
43
54
|
version: '0'
|
44
55
|
type: :runtime
|
45
56
|
prerelease: false
|
46
|
-
version_requirements: *
|
57
|
+
version_requirements: *2152475540
|
47
58
|
description: Find and download subtitles
|
48
59
|
email: eregontp@gmail.com
|
49
60
|
executables:
|
@@ -55,10 +66,8 @@ files:
|
|
55
66
|
- lib/suby/downloader/addic7ed.rb
|
56
67
|
- lib/suby/downloader/tvsubtitles.rb
|
57
68
|
- lib/suby/downloader.rb
|
58
|
-
- lib/suby/downloader_error.rb
|
59
69
|
- lib/suby/filename_parser.rb
|
60
70
|
- lib/suby/interface.rb
|
61
|
-
- lib/suby/not_found_error.rb
|
62
71
|
- lib/suby.rb
|
63
72
|
- .gitignore
|
64
73
|
- README.md
|
data/lib/suby/not_found_error.rb
DELETED