pirate-autosub 0.2.4 → 0.3
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/Rakefile +1 -1
- data/autosub.gemspec +4 -7
- data/bin/autosub +4 -1
- data/lib/episode.rb +1 -1
- data/lib/inspector.rb +29 -8
- data/lib/sites/podnapisi.rb +101 -0
- data/lib/sites/seriessub.rb +8 -1
- data/lib/sites/tvsubtitle.rb +15 -4
- metadata +10 -12
data/Rakefile
CHANGED
@@ -3,7 +3,7 @@ require 'rubygems'
|
|
3
3
|
require 'rake'
|
4
4
|
require 'echoe'
|
5
5
|
|
6
|
-
Echoe.new('autosub', '0.
|
6
|
+
Echoe.new('autosub', '0.3') do |p|
|
7
7
|
p.description = "Ruby tool to automatically download subtitles (srt) inside your TV Shows folder"
|
8
8
|
p.url = "http://github.com/pirate/autosub"
|
9
9
|
p.author = "Pirate"
|
data/autosub.gemspec
CHANGED
@@ -2,17 +2,17 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{autosub}
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "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 = ["Pirate"]
|
9
|
-
s.date = %q{2009-
|
9
|
+
s.date = %q{2009-03-15}
|
10
10
|
s.default_executable = %q{autosub}
|
11
11
|
s.description = %q{Ruby tool to automatically download subtitles (srt) inside your TV Shows folder}
|
12
12
|
s.email = %q{pirate.2061@gmail.com}
|
13
13
|
s.executables = ["autosub"]
|
14
|
-
s.extra_rdoc_files = ["bin/autosub", "lib/episode.rb", "lib/inspector.rb", "lib/sites/seriessub.rb", "lib/sites/tvsubtitle.rb", "README.markdown"]
|
15
|
-
s.files = ["asset/failure.png", "asset/srt.png", "autosub.gemspec", "bin/autosub", "lib/episode.rb", "lib/inspector.rb", "lib/sites/seriessub.rb", "lib/sites/tvsubtitle.rb", "Rakefile", "README.markdown"
|
14
|
+
s.extra_rdoc_files = ["bin/autosub", "lib/episode.rb", "lib/inspector.rb", "lib/sites/podnapisi.rb", "lib/sites/seriessub.rb", "lib/sites/tvsubtitle.rb", "README.markdown"]
|
15
|
+
s.files = ["asset/failure.png", "asset/srt.png", "autosub.gemspec", "bin/autosub", "lib/episode.rb", "lib/inspector.rb", "lib/sites/podnapisi.rb", "lib/sites/seriessub.rb", "lib/sites/tvsubtitle.rb", "Manifest", "Rakefile", "README.markdown"]
|
16
16
|
s.has_rdoc = true
|
17
17
|
s.homepage = %q{http://github.com/pirate/autosub}
|
18
18
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Autosub", "--main", "README.markdown"]
|
@@ -31,14 +31,12 @@ Gem::Specification.new do |s|
|
|
31
31
|
s.add_runtime_dependency(%q<optiflag>, [">= 0"])
|
32
32
|
s.add_runtime_dependency(%q<simple-rss>, [">= 0"])
|
33
33
|
s.add_runtime_dependency(%q<mechanize>, [">= 0"])
|
34
|
-
s.add_development_dependency(%q<echoe>, [">= 0"])
|
35
34
|
else
|
36
35
|
s.add_dependency(%q<hpricot>, [">= 0"])
|
37
36
|
s.add_dependency(%q<rubyzip>, [">= 0"])
|
38
37
|
s.add_dependency(%q<optiflag>, [">= 0"])
|
39
38
|
s.add_dependency(%q<simple-rss>, [">= 0"])
|
40
39
|
s.add_dependency(%q<mechanize>, [">= 0"])
|
41
|
-
s.add_dependency(%q<echoe>, [">= 0"])
|
42
40
|
end
|
43
41
|
else
|
44
42
|
s.add_dependency(%q<hpricot>, [">= 0"])
|
@@ -46,6 +44,5 @@ Gem::Specification.new do |s|
|
|
46
44
|
s.add_dependency(%q<optiflag>, [">= 0"])
|
47
45
|
s.add_dependency(%q<simple-rss>, [">= 0"])
|
48
46
|
s.add_dependency(%q<mechanize>, [">= 0"])
|
49
|
-
s.add_dependency(%q<echoe>, [">= 0"])
|
50
47
|
end
|
51
48
|
end
|
data/bin/autosub
CHANGED
@@ -11,12 +11,15 @@ module AutoSub extend OptiFlagSet
|
|
11
11
|
description "Language(s) you want for your subtitles, default: fr,en
|
12
12
|
(Order is important to define if a srt is needed)"
|
13
13
|
end
|
14
|
+
optional_flag "log" do
|
15
|
+
description "path for log file"
|
16
|
+
end
|
14
17
|
|
15
18
|
and_process!
|
16
19
|
end
|
17
20
|
|
18
21
|
begin
|
19
|
-
inspector = Inspector.new(ARGV.flags.p, ARGV.flags.lang)
|
22
|
+
inspector = Inspector.new(ARGV.flags.p, :lang => ARGV.flags.lang, :log_path => ARGV.flags.log)
|
20
23
|
rescue => e
|
21
24
|
p e.to_s
|
22
25
|
Inspector.growl("AutoSub Error!", 'look into the console log', 'failure.png')
|
data/lib/episode.rb
CHANGED
data/lib/inspector.rb
CHANGED
@@ -1,15 +1,23 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), '..', 'lib', 'episode')
|
2
2
|
require File.join(File.dirname(__FILE__), '..', 'lib', 'sites', 'seriessub')
|
3
3
|
require File.join(File.dirname(__FILE__), '..', 'lib', 'sites', 'tvsubtitle')
|
4
|
+
require File.join(File.dirname(__FILE__), '..', 'lib', 'sites', 'podnapisi')
|
5
|
+
require 'logger'
|
4
6
|
|
5
7
|
class Inspector
|
6
8
|
|
7
|
-
attr_accessor :tv_shows, :episodes, :langs
|
9
|
+
attr_accessor :tv_shows, :episodes, :langs, :log
|
8
10
|
|
9
|
-
def initialize(path ,
|
10
|
-
@path =
|
11
|
-
@langs =
|
12
|
-
|
11
|
+
def initialize(path , options = {})
|
12
|
+
@path = Pathname.new(path).realpath.to_s
|
13
|
+
@langs = options[:lang] ? options[:lang].split(',') : ['fr','en']
|
14
|
+
|
15
|
+
# Initialize Logger
|
16
|
+
@log = Logger.new(options[:log_path] || "#{@path}/_autosub_.log" )
|
17
|
+
@log.datetime_format = "%Y-%m-%d %H:%M:%S "
|
18
|
+
log.info "Begin searching for '#{langs.join(',')}' subtitles..."
|
19
|
+
|
20
|
+
$stdout.print "--- Searching for '#{langs.join(',')}' subtitles ---\n"
|
13
21
|
@tv_shows = [] # {:name => ..., :path => ...}
|
14
22
|
initialize_tv_shows
|
15
23
|
$stdout.print "Found #{@tv_shows.size} TV Show(s) in #{@path}\n"
|
@@ -20,8 +28,21 @@ class Inspector
|
|
20
28
|
$stdout.print "Found #{@episodes.select { |e| e.need_srt?(@langs) }.size} episode(s) who need(s) srt\n"
|
21
29
|
|
22
30
|
# Find new srt
|
23
|
-
|
24
|
-
|
31
|
+
begin
|
32
|
+
Podnapisi.new(self)
|
33
|
+
rescue => e
|
34
|
+
log.fatal "Problem with Podnapisi: #{e}"
|
35
|
+
end
|
36
|
+
begin
|
37
|
+
TVSubtitle.new(self)
|
38
|
+
rescue => e
|
39
|
+
log.fatal "Problem with TVSubtitle: #{e}"
|
40
|
+
end
|
41
|
+
begin
|
42
|
+
SeriesSub.new(self)
|
43
|
+
rescue => e
|
44
|
+
log.fatal "Problem with SeriesSub: #{e}"
|
45
|
+
end
|
25
46
|
end
|
26
47
|
|
27
48
|
def growl_episode(episode, lang)
|
@@ -61,7 +82,7 @@ private
|
|
61
82
|
end
|
62
83
|
|
63
84
|
def clean_dir(dir)
|
64
|
-
dir.select { |e| !["..", ".", ".DS_Store", ".com.apple.timemachine.supported", "Icon\r"].include?(e) }
|
85
|
+
dir.select { |e| !["..", ".", ".DS_Store", ".com.apple.timemachine.supported", "Icon\r", "autosub.log", "_autosub_.log"].include?(e) }
|
65
86
|
end
|
66
87
|
|
67
88
|
def lang_name(lang)
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'hpricot'
|
2
|
+
require 'open-uri'
|
3
|
+
require 'zip/zip'
|
4
|
+
require 'cgi'
|
5
|
+
|
6
|
+
# http://www.podnapisi.net/ | http://www.sub-titles.net/
|
7
|
+
class Podnapisi
|
8
|
+
|
9
|
+
def initialize(inspector)
|
10
|
+
@inspector = inspector
|
11
|
+
episodes = @inspector.episodes.select { |e| e.need_srt?(@inspector.langs) }
|
12
|
+
|
13
|
+
$stdout.print "------------------------------------------\n"
|
14
|
+
$stdout.print "Start srt searching from www.podnapisi.net\n"
|
15
|
+
$stdout.print "------------------------------------------\n"
|
16
|
+
episodes.each do |e|
|
17
|
+
@inspector.langs.each do |l|
|
18
|
+
unless e.srt.include?(l)
|
19
|
+
$stdout.print "#{e.episode_name_with_format} [#{l}]: "
|
20
|
+
if get_srt(e, l)
|
21
|
+
@inspector.log.info "#{e.episode_name_with_format} [#{l}] // Podnapisi // #{@srt_name}"
|
22
|
+
$stdout.print "FOUND\n"
|
23
|
+
e.srt << l
|
24
|
+
@inspector.growl_episode(e, l)
|
25
|
+
break
|
26
|
+
else
|
27
|
+
$stdout.print "NOT FOUND\n"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def get_srt(episode, lang)
|
37
|
+
found = false
|
38
|
+
doc = Hpricot(open(url(episode, lang)))
|
39
|
+
doc.search("table.list tr").each do |el|
|
40
|
+
if !found && have_srt_format?(el) && !hearing_impaired?(el) && url = open(download_url(el))
|
41
|
+
Tempfile.open("tv.zip") do |tempfile|
|
42
|
+
tempfile.write(open(url).read) # download the zip
|
43
|
+
tempfile.close # tempfile need to be closed for unzip it
|
44
|
+
Zip::ZipFile.open(tempfile.path) do |zip_file|
|
45
|
+
zip_file.each do |f|
|
46
|
+
if f.size > 5000
|
47
|
+
@srt_name = f.name
|
48
|
+
zip_file.extract(f, episode.srt_filename(lang))
|
49
|
+
found = true
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
rescue => e
|
57
|
+
@inspector.log.fatal "Podnapisi // #{episode.episode_name_with_format} [#{lang}] // #{e}"
|
58
|
+
found = false
|
59
|
+
else
|
60
|
+
found
|
61
|
+
end
|
62
|
+
|
63
|
+
def url(episode, lang)
|
64
|
+
"http://simple.podnapisi.net/ppodnapisi/search?tbsl=3&asdp=1&sK=#{tv_show(episode)}&sJ=#{lang_num(lang)}&sO=desc&sS=time&submit=Search&sTS=#{episode.season}&sTE=#{episode.number}&sY=&sR=#{format(episode)}&sT=1"
|
65
|
+
end
|
66
|
+
|
67
|
+
def tv_show(episode)
|
68
|
+
CGI.escape(episode.tv_show)
|
69
|
+
end
|
70
|
+
|
71
|
+
def format(episode)
|
72
|
+
case episode.format
|
73
|
+
when 'hd'
|
74
|
+
"720"
|
75
|
+
when 'sd'
|
76
|
+
""
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def lang_num(lang)
|
81
|
+
case lang
|
82
|
+
when 'fr'
|
83
|
+
8
|
84
|
+
when 'en'
|
85
|
+
2
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def have_srt_format?(el)
|
90
|
+
!el.search("td[text()*='SubRip']").empty?
|
91
|
+
end
|
92
|
+
|
93
|
+
def hearing_impaired?(el)
|
94
|
+
!el.search("img[@title='Subtitle is for hearing impaired']").empty?
|
95
|
+
end
|
96
|
+
|
97
|
+
def download_url(el)
|
98
|
+
"http://simple.podnapisi.net#{el.search("a[text()*='download subtitle']").first[:href]}"
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
data/lib/sites/seriessub.rb
CHANGED
@@ -17,6 +17,7 @@ class SeriesSub
|
|
17
17
|
unless e.srt.include?(l)
|
18
18
|
$stdout.print "#{e.episode_name_with_format} [#{l}]: "
|
19
19
|
if get_srt(e, l)
|
20
|
+
inspector.log.info "#{e.episode_name_with_format} [#{l}] // SeriesSub // #{@srt_name}"
|
20
21
|
$stdout.print "FOUND\n"
|
21
22
|
e.srt << l
|
22
23
|
@inspector.growl_episode(e, l)
|
@@ -43,7 +44,8 @@ private
|
|
43
44
|
tempfile.close # tempfile need to be closed for unzip it
|
44
45
|
Zip::ZipFile.open(tempfile.path) do |zip_file|
|
45
46
|
zip_file.each do |f|
|
46
|
-
if good_episode?(episode, f.name) && f.name.include?(lang_version(lang)) && episode.good_format?(f.name) && no_tag?(f.name)
|
47
|
+
if f.size > 5000 && good_episode?(episode, f.name) && f.name.include?(lang_version(lang)) && episode.good_format?(f.name) && no_tag?(f.name)
|
48
|
+
@srt_name = f.name
|
47
49
|
zip_file.extract(f, episode.srt_filename(lang))
|
48
50
|
found = true
|
49
51
|
end
|
@@ -51,6 +53,7 @@ private
|
|
51
53
|
end
|
52
54
|
end
|
53
55
|
elsif episode.good_format?(text) && no_tag?(text) # just a single srt file
|
56
|
+
@srt_name = text
|
54
57
|
Tempfile.open("tv.srt") do |tempfile|
|
55
58
|
tempfile.write(open(el[:href]).read) # download the zip
|
56
59
|
tempfile.close
|
@@ -60,6 +63,10 @@ private
|
|
60
63
|
end
|
61
64
|
end
|
62
65
|
end
|
66
|
+
rescue => e
|
67
|
+
@inspector.log.fatal "SeriesSub // #{episode.episode_name_with_format} [#{lang}] // #{e}"
|
68
|
+
found = false
|
69
|
+
else
|
63
70
|
found
|
64
71
|
end
|
65
72
|
|
data/lib/sites/tvsubtitle.rb
CHANGED
@@ -12,15 +12,16 @@ class TVSubtitle
|
|
12
12
|
episodes = @inspector.episodes.select { |e| e.need_srt?(@inspector.langs) }
|
13
13
|
|
14
14
|
$stdout.print "--------------------------------------------\n"
|
15
|
-
$stdout.print "Searching
|
15
|
+
$stdout.print "Searching for srt in www.tvsubtitles.net RSS\n"
|
16
16
|
$stdout.print "--------------------------------------------\n"
|
17
17
|
@inspector.langs.each do |l|
|
18
18
|
rss(l).items.each do |item|
|
19
19
|
episodes.each do |e|
|
20
|
-
unless e.srt.include?(l)
|
20
|
+
unless e.srt.include?(l)
|
21
21
|
if episode_title(e, l) == item_title(item)
|
22
|
-
$stdout.print "FOUND: #{e.episode_name_with_format} [#{l}]\n"
|
23
22
|
download_srt(item, e, l)
|
23
|
+
inspector.log.info "#{e.episode_name_with_format} [#{l}] // TVSubtitle // #{@srt_name}"
|
24
|
+
$stdout.print "FOUND: #{e.episode_name_with_format} [#{l}]\n"
|
24
25
|
e.srt << l
|
25
26
|
@inspector.growl_episode(e, l)
|
26
27
|
end
|
@@ -33,6 +34,7 @@ class TVSubtitle
|
|
33
34
|
private
|
34
35
|
|
35
36
|
def download_srt(item, episode, lang)
|
37
|
+
found = false
|
36
38
|
agent = WWW::Mechanize.new
|
37
39
|
id = item_id(item)
|
38
40
|
Tempfile.open("srt") do |tempfile|
|
@@ -41,10 +43,19 @@ private
|
|
41
43
|
tempfile.close
|
42
44
|
Zip::ZipFile.open(tempfile.path) do |zip_file|
|
43
45
|
zip_file.each do |f|
|
44
|
-
|
46
|
+
if f.size > 5000
|
47
|
+
@srt_name = f.name
|
48
|
+
zip_file.extract(f, episode.srt_filename(lang))
|
49
|
+
found = true
|
50
|
+
end
|
45
51
|
end
|
46
52
|
end
|
47
53
|
end
|
54
|
+
rescue => e
|
55
|
+
@inspector.log.fatal "TVSubtitle // #{episode.episode_name_with_format} [#{lang}] // #{e}"
|
56
|
+
found = false
|
57
|
+
else
|
58
|
+
found
|
48
59
|
end
|
49
60
|
|
50
61
|
def rss(lang)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pirate-autosub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: "0.3"
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pirate
|
@@ -9,11 +9,12 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-03-15 00:00:00 -07:00
|
13
13
|
default_executable: autosub
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: hpricot
|
17
|
+
type: :runtime
|
17
18
|
version_requirement:
|
18
19
|
version_requirements: !ruby/object:Gem::Requirement
|
19
20
|
requirements:
|
@@ -23,6 +24,7 @@ dependencies:
|
|
23
24
|
version:
|
24
25
|
- !ruby/object:Gem::Dependency
|
25
26
|
name: rubyzip
|
27
|
+
type: :runtime
|
26
28
|
version_requirement:
|
27
29
|
version_requirements: !ruby/object:Gem::Requirement
|
28
30
|
requirements:
|
@@ -32,6 +34,7 @@ dependencies:
|
|
32
34
|
version:
|
33
35
|
- !ruby/object:Gem::Dependency
|
34
36
|
name: optiflag
|
37
|
+
type: :runtime
|
35
38
|
version_requirement:
|
36
39
|
version_requirements: !ruby/object:Gem::Requirement
|
37
40
|
requirements:
|
@@ -41,6 +44,7 @@ dependencies:
|
|
41
44
|
version:
|
42
45
|
- !ruby/object:Gem::Dependency
|
43
46
|
name: simple-rss
|
47
|
+
type: :runtime
|
44
48
|
version_requirement:
|
45
49
|
version_requirements: !ruby/object:Gem::Requirement
|
46
50
|
requirements:
|
@@ -50,15 +54,7 @@ dependencies:
|
|
50
54
|
version:
|
51
55
|
- !ruby/object:Gem::Dependency
|
52
56
|
name: mechanize
|
53
|
-
|
54
|
-
version_requirements: !ruby/object:Gem::Requirement
|
55
|
-
requirements:
|
56
|
-
- - ">="
|
57
|
-
- !ruby/object:Gem::Version
|
58
|
-
version: "0"
|
59
|
-
version:
|
60
|
-
- !ruby/object:Gem::Dependency
|
61
|
-
name: echoe
|
57
|
+
type: :runtime
|
62
58
|
version_requirement:
|
63
59
|
version_requirements: !ruby/object:Gem::Requirement
|
64
60
|
requirements:
|
@@ -76,6 +72,7 @@ extra_rdoc_files:
|
|
76
72
|
- bin/autosub
|
77
73
|
- lib/episode.rb
|
78
74
|
- lib/inspector.rb
|
75
|
+
- lib/sites/podnapisi.rb
|
79
76
|
- lib/sites/seriessub.rb
|
80
77
|
- lib/sites/tvsubtitle.rb
|
81
78
|
- README.markdown
|
@@ -86,11 +83,12 @@ files:
|
|
86
83
|
- bin/autosub
|
87
84
|
- lib/episode.rb
|
88
85
|
- lib/inspector.rb
|
86
|
+
- lib/sites/podnapisi.rb
|
89
87
|
- lib/sites/seriessub.rb
|
90
88
|
- lib/sites/tvsubtitle.rb
|
89
|
+
- Manifest
|
91
90
|
- Rakefile
|
92
91
|
- README.markdown
|
93
|
-
- Manifest
|
94
92
|
has_rdoc: true
|
95
93
|
homepage: http://github.com/pirate/autosub
|
96
94
|
post_install_message:
|