subtitle_it 0.7.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. data/.autotest +19 -0
  2. data/History.txt +53 -0
  3. data/License.txt +20 -0
  4. data/Manifest.txt +68 -0
  5. data/README.markdown +41 -0
  6. data/README.txt +102 -0
  7. data/Rakefile +4 -0
  8. data/bin/subtitle_it +66 -0
  9. data/config/hoe.rb +73 -0
  10. data/config/requirements.rb +15 -0
  11. data/lib/subtitle_it/bin.rb +132 -0
  12. data/lib/subtitle_it/fixes.rb +12 -0
  13. data/lib/subtitle_it/formats/ass.rb +13 -0
  14. data/lib/subtitle_it/formats/mpl.rb +29 -0
  15. data/lib/subtitle_it/formats/rsb.rb +37 -0
  16. data/lib/subtitle_it/formats/srt.rb +45 -0
  17. data/lib/subtitle_it/formats/sub.rb +49 -0
  18. data/lib/subtitle_it/formats/xml.rb +65 -0
  19. data/lib/subtitle_it/formats/yml.rb +18 -0
  20. data/lib/subtitle_it/generator.rb +15 -0
  21. data/lib/subtitle_it/languages.rb +60 -0
  22. data/lib/subtitle_it/movie.rb +24 -0
  23. data/lib/subtitle_it/movie_hasher.rb +30 -0
  24. data/lib/subtitle_it/platform_endl.rb +9 -0
  25. data/lib/subtitle_it/subdown.rb +107 -0
  26. data/lib/subtitle_it/subline.rb +25 -0
  27. data/lib/subtitle_it/substyle.rb +11 -0
  28. data/lib/subtitle_it/subtime.rb +41 -0
  29. data/lib/subtitle_it/subtitle.rb +76 -0
  30. data/lib/subtitle_it/version.rb +9 -0
  31. data/lib/subtitle_it.rb +22 -0
  32. data/script/console +10 -0
  33. data/script/destroy +14 -0
  34. data/script/generate +14 -0
  35. data/script/txt2html +82 -0
  36. data/setup.rb +1585 -0
  37. data/spec/fixtures/godfather.srt +2487 -0
  38. data/spec/fixtures/huge.ass +22 -0
  39. data/spec/fixtures/movie.xml +28 -0
  40. data/spec/fixtures/movie.yml +163 -0
  41. data/spec/fixtures/pseudo.rsb +6 -0
  42. data/spec/fixtures/pulpfiction.sub +2025 -0
  43. data/spec/fixtures/puplfiction.mpl +12 -0
  44. data/spec/fixtures/sincity.yml +12 -0
  45. data/spec/spec.opts +1 -0
  46. data/spec/spec_helper.rb +71 -0
  47. data/spec/subtitle_it/bin_spec.rb +142 -0
  48. data/spec/subtitle_it/fixes_spec.rb +0 -0
  49. data/spec/subtitle_it/formats/ass_spec.rb +5 -0
  50. data/spec/subtitle_it/formats/mpl_spec.rb +45 -0
  51. data/spec/subtitle_it/formats/rsb_spec.rb +42 -0
  52. data/spec/subtitle_it/formats/srt_spec.rb +57 -0
  53. data/spec/subtitle_it/formats/sub_spec.rb +49 -0
  54. data/spec/subtitle_it/formats/xml_spec.rb +60 -0
  55. data/spec/subtitle_it/formats/yml_spec.rb +20 -0
  56. data/spec/subtitle_it/generator_spec.rb +0 -0
  57. data/spec/subtitle_it/movie_hasher_spec.rb +13 -0
  58. data/spec/subtitle_it/movie_spec.rb +25 -0
  59. data/spec/subtitle_it/subdown_spec.rb +94 -0
  60. data/spec/subtitle_it/subline_spec.rb +30 -0
  61. data/spec/subtitle_it/substyle_spec.rb +1 -0
  62. data/spec/subtitle_it/subtime_spec.rb +73 -0
  63. data/spec/subtitle_it/subtitle_spec.rb +40 -0
  64. data/spec/subtitle_it_spec.rb +11 -0
  65. data/subtitle_it.gemspec +41 -0
  66. data/tasks/deployment.rake +34 -0
  67. data/tasks/environment.rake +7 -0
  68. data/tasks/rspec.rake +21 -0
  69. metadata +152 -0
data/.autotest ADDED
@@ -0,0 +1,19 @@
1
+ # #
2
+ # SMS AUTOTEST
3
+ #
4
+ #require 'autotest/growl'
5
+ #require 'autotest/html_report'
6
+ # require 'autotest/kdenotify'
7
+ require 'autotest/menu'
8
+ #require 'autotest/pretty'
9
+ require 'autotest/redgreen'
10
+ # require 'autotest/snarl'
11
+ require 'autotest/timestamp'
12
+
13
+
14
+ class Autotest
15
+ Autotest.add_hook :initialize do |at|
16
+ %w{.svn .hg .git .DS_store}.each {|exception|at.add_exception(exception)}
17
+ end
18
+ end
19
+
data/History.txt ADDED
@@ -0,0 +1,53 @@
1
+ == 0.1.0 2008-09-04
2
+
3
+ * 1 major enhancement:
4
+ * Support yml
5
+
6
+ == 0.2.0 2008-09-07
7
+
8
+ * 1 major enhancement:
9
+ * Support sub
10
+
11
+ == 0.3.0 2008-09-07
12
+
13
+ * 2 major enhancement:
14
+ * Support srt
15
+ * subtitle_it tool
16
+
17
+ == 0.4.0 2008-09-07
18
+
19
+ * 1 major enhancement:
20
+ * Adds yml generator
21
+
22
+ == 0.5.1 2008-09-08
23
+
24
+ * 1 major enhancement:
25
+ * Adds rsb support
26
+
27
+ == 0.6.1 2008-09-09
28
+
29
+ * 1 major enhancement:
30
+ * Adds xml tt support
31
+
32
+ == 0.7.0 2008-09-10
33
+
34
+ * 3 major enhancements:
35
+ * Adds download opensubtitles support
36
+ * Fixes various bugs (and adds another ones)
37
+ * Adds MPL2 support
38
+
39
+ == 0.7.5 2008-09-13
40
+
41
+ * 2 major enhancement
42
+ * Support multiple file downloads
43
+ * subtitle_it worker code rewritten
44
+
45
+ == 0.7.6 2008-09-17
46
+
47
+ * 1 major enhancement:
48
+ * Fixes a bug (platform dependent end-of-line)
49
+
50
+ == 0.7.7 2008-09-20
51
+
52
+ * 1 major enhancement:
53
+ * Add language search (subtitle_it -l <code> <movie>)
data/License.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Marcos Piccinini, Warlley Rezende, Marcin (tiraeth) Chwedziak
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Manifest.txt ADDED
@@ -0,0 +1,68 @@
1
+ .autotest
2
+ History.txt
3
+ License.txt
4
+ Manifest.txt
5
+ README.markdown
6
+ README.txt
7
+ Rakefile
8
+ bin/subtitle_it
9
+ config/hoe.rb
10
+ config/requirements.rb
11
+ lib/subtitle_it.rb
12
+ lib/subtitle_it/bin.rb
13
+ lib/subtitle_it/fixes.rb
14
+ lib/subtitle_it/formats/ass.rb
15
+ lib/subtitle_it/formats/mpl.rb
16
+ lib/subtitle_it/formats/rsb.rb
17
+ lib/subtitle_it/formats/srt.rb
18
+ lib/subtitle_it/formats/sub.rb
19
+ lib/subtitle_it/formats/xml.rb
20
+ lib/subtitle_it/formats/yml.rb
21
+ lib/subtitle_it/generator.rb
22
+ lib/subtitle_it/languages.rb
23
+ lib/subtitle_it/movie.rb
24
+ lib/subtitle_it/movie_hasher.rb
25
+ lib/subtitle_it/platform_endl.rb
26
+ lib/subtitle_it/subdown.rb
27
+ lib/subtitle_it/subline.rb
28
+ lib/subtitle_it/substyle.rb
29
+ lib/subtitle_it/subtime.rb
30
+ lib/subtitle_it/subtitle.rb
31
+ lib/subtitle_it/version.rb
32
+ script/console
33
+ script/destroy
34
+ script/generate
35
+ script/txt2html
36
+ setup.rb
37
+ spec/fixtures/godfather.srt
38
+ spec/fixtures/huge.ass
39
+ spec/fixtures/movie.xml
40
+ spec/fixtures/movie.yml
41
+ spec/fixtures/pseudo.rsb
42
+ spec/fixtures/pulpfiction.sub
43
+ spec/fixtures/puplfiction.mpl
44
+ spec/fixtures/sincity.yml
45
+ spec/spec.opts
46
+ spec/spec_helper.rb
47
+ spec/subtitle_it/bin_spec.rb
48
+ spec/subtitle_it/fixes_spec.rb
49
+ spec/subtitle_it/formats/ass_spec.rb
50
+ spec/subtitle_it/formats/mpl_spec.rb
51
+ spec/subtitle_it/formats/rsb_spec.rb
52
+ spec/subtitle_it/formats/srt_spec.rb
53
+ spec/subtitle_it/formats/sub_spec.rb
54
+ spec/subtitle_it/formats/xml_spec.rb
55
+ spec/subtitle_it/formats/yml_spec.rb
56
+ spec/subtitle_it/generator_spec.rb
57
+ spec/subtitle_it/movie_hasher_spec.rb
58
+ spec/subtitle_it/movie_spec.rb
59
+ spec/subtitle_it/subdown_spec.rb
60
+ spec/subtitle_it/subline_spec.rb
61
+ spec/subtitle_it/substyle_spec.rb
62
+ spec/subtitle_it/subtime_spec.rb
63
+ spec/subtitle_it/subtitle_spec.rb
64
+ spec/subtitle_it_spec.rb
65
+ subtitle_it.gemspec
66
+ tasks/deployment.rake
67
+ tasks/environment.rake
68
+ tasks/rspec.rake
data/README.markdown ADDED
@@ -0,0 +1,41 @@
1
+ h1. Subtitle It
2
+
3
+ Ruby tool to work with subtitle files.
4
+
5
+ h1. FEATURES:
6
+
7
+ * Converts to and from: SRT, SUB, XML(TT), YML, MPL2, RSB and ASS.
8
+ * Fixes delays. (SrtResync)
9
+
10
+ h2. TODO:
11
+
12
+ * Compatibility with "sube" (http://github.com/vic/sube)
13
+ * Download subtitles. (http://github.com/johanlunds/downsub/tree)
14
+
15
+ h1. SYNOPSIS:
16
+
17
+ Bash tool:
18
+
19
+ Convert a srt to sub:
20
+ subtitle_it in.srt out.sub
21
+
22
+ Add a delay of 1 minute:
23
+ subtitle_it -d 60 in.srt
24
+
25
+ Create a template
26
+ subtitle_it unexistent.file
27
+
28
+
29
+ h1. INSTALL:
30
+
31
+ sudo gem install SubtitleIt
32
+
33
+
34
+ h1. THE "Ruby Subtitle" Format - RSB
35
+
36
+ It`s just a easy way, proof of concept to edit subtitles. Here is what it looks like:
37
+
38
+ 00:32 => 00:33 == Nice police work! | Thank you!
39
+ MM:SS => N == TEXT | NEWLINE
40
+
41
+ Create a template to check it out.
data/README.txt ADDED
@@ -0,0 +1,102 @@
1
+ = Subtitle It
2
+
3
+ Ruby tool to download, create, convert and fix subtitles.
4
+
5
+
6
+ == FEATURES:
7
+
8
+ * To and from: SRT, SUB, XML(TT), YML, MPL2, RSB and ASS.
9
+ * Download from opensubtitles.org
10
+ * Fixes delays. (SrtResync)
11
+
12
+
13
+ == TODO:
14
+
15
+ * Support styles
16
+ * Compatibility with "sube" (http://github.com/vic/sube)
17
+ * Fix delays
18
+ * Convert 1 to 2 CD`s and versa-vice
19
+ * ASS Format (Yes, for the funny of it...)
20
+
21
+
22
+ == REQUIREMENTS:
23
+
24
+ * hpricot
25
+
26
+
27
+ == SYNOPSIS:
28
+
29
+ Bash tool:
30
+
31
+ Convert a srt to sub:
32
+ subtitle_it in.srt out.sub
33
+ or
34
+ subtitle_it -c sub in.srt
35
+
36
+ Add a delay of 1 minute:
37
+ subtitle_it -d 60 in.srt
38
+
39
+ Create a template
40
+ subtitle_it unexistent.file
41
+
42
+
43
+ == INSTALL:
44
+
45
+ gem sources add http://gems.github.com
46
+ sudo gem install nofxx-subtitle_it
47
+
48
+
49
+ == THE "Ruby Subtitle" Format - RSB
50
+
51
+ It`s just a easy way, proof of concept to edit subtitles. Here is what it looks like:
52
+
53
+ 00:32 => 00:33 == Nice police work! | Thank you!
54
+ MM:SS => N == TEXT | NEWLINE
55
+
56
+ Create a template to check it out.
57
+
58
+
59
+ == DEV:
60
+
61
+ To run tests:
62
+
63
+ rake spec or autotest
64
+
65
+ Documentation => doc
66
+ Subtitle examples => spec/fixtures
67
+
68
+
69
+ == SUBTITLE EDITORS:
70
+
71
+ Try those nice editors too, if SubtitleIt does not fit your need:
72
+
73
+ Jubler: http://www.jubler.org/
74
+
75
+ Aegisub: http://www.malakith.net/aegiwiki/Main_Page
76
+
77
+
78
+ == LICENSE:
79
+
80
+ (The MIT License)
81
+
82
+ Copyright (c) 2008 Marcos Piccinini, Johanlunds, Warlley Rezende
83
+
84
+
85
+ Permission is hereby granted, free of charge, to any person obtaining
86
+ a copy of this software and associated documentation files (the
87
+ 'Software'), to deal in the Software without restriction, including
88
+ without limitation the rights to use, copy, modify, merge, publish,
89
+ distribute, sublicense, and/or sell copies of the Software, and to
90
+ permit persons to whom the Software is furnished to do so, subject to
91
+ the following conditions:
92
+
93
+ The above copyright notice and this permission notice shall be
94
+ included in all copies or substantial portions of the Software.
95
+
96
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
97
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
98
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
99
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
100
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
101
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
102
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ require 'config/requirements'
2
+ require 'config/hoe' # setup Hoe + all gem configuration
3
+
4
+ Dir['tasks/**/*.rake'].each { |rake| load rake }
data/bin/subtitle_it ADDED
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env ruby
2
+ # SubtitleIt
3
+ #
4
+ # Created on 2008-9-4.
5
+ # Copyright (c) 2008. All rights reserved.
6
+ #
7
+ begin
8
+ require 'rubygems'
9
+ rescue LoadError
10
+ # no rubygems to load, so we fail silently
11
+ end
12
+
13
+ require 'optparse'
14
+ require 'subtitle_it'
15
+
16
+ include SubtitleIt
17
+
18
+ OPTIONS = {
19
+ :force => false,
20
+ :format => nil,
21
+ :delay => nil
22
+ }
23
+ MANDATORY_OPTIONS = %w( )
24
+
25
+ parser = OptionParser.new do |opts|
26
+ opts.banner = <<BANNER
27
+ SubtitleIt - Download, convert and create subtitles.
28
+
29
+ Usage: #{File.basename($0)} [options] movie or file_in [file_out]
30
+
31
+ Options are:
32
+
33
+ BANNER
34
+ opts.separator ""
35
+
36
+ opts.on("-l", "--language=LANGUAGE", String,
37
+ "Language to search subtitles for, try it empty to see the supported ones.") { |OPTIONS[:lang]| }
38
+
39
+ opts.on("-c", "--convert=FORMAT", String,
40
+ "Format to convert to") { |OPTIONS[:format]| }
41
+
42
+ opts.on("-d", "--delay=DELAY", Float,
43
+ "Delay to add/remove") { |OPTIONS[:delay]| }
44
+
45
+ opts.on("-f", "--force", "Force overwrite") { OPTIONS[:force] = true }
46
+
47
+ opts.on("-h", "--help",
48
+ "Show this help message.") { puts opts; exit }
49
+
50
+ opts.on("-v", "--version",
51
+ "Show program version") { puts "SubtitleIt v#{SubtitleIt::VERSION::STRING}"; exit }
52
+
53
+ opts.parse!(ARGV)
54
+
55
+ if MANDATORY_OPTIONS && MANDATORY_OPTIONS.find { |option| OPTIONS[option.to_sym].nil? }
56
+ puts opts; exit
57
+ end
58
+ end
59
+
60
+ if ARGV.empty?
61
+ puts parser.banner
62
+ exit
63
+ else
64
+ SubtitleIt::Bin.run! ARGV, OPTIONS[:lang], OPTIONS[:format], OPTIONS[:force], OPTIONS[:delay]
65
+ end
66
+
data/config/hoe.rb ADDED
@@ -0,0 +1,73 @@
1
+ require 'subtitle_it/version'
2
+
3
+ AUTHOR = 'FIXME full name' # can also be an array of Authors
4
+ EMAIL = "FIXME email"
5
+ DESCRIPTION = "description of gem"
6
+ GEM_NAME = 'subtitle_it' # what ppl will type to install your gem
7
+ RUBYFORGE_PROJECT = 'subtitle_it' # The unix name for your project
8
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
9
+ DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
10
+ EXTRA_DEPENDENCIES = [
11
+ # ['activesupport', '>= 1.3.1']
12
+ ] # An array of rubygem dependencies [name, version]
13
+
14
+ @config_file = "~/.rubyforge/user-config.yml"
15
+ @config = nil
16
+ RUBYFORGE_USERNAME = "unknown"
17
+ def rubyforge_username
18
+ unless @config
19
+ begin
20
+ @config = YAML.load(File.read(File.expand_path(@config_file)))
21
+ rescue
22
+ puts <<-EOS
23
+ ERROR: No rubyforge config file found: #{@config_file}
24
+ Run 'rubyforge setup' to prepare your env for access to Rubyforge
25
+ - See http://newgem.rubyforge.org/rubyforge.html for more details
26
+ EOS
27
+ exit
28
+ end
29
+ end
30
+ RUBYFORGE_USERNAME.replace @config["username"]
31
+ end
32
+
33
+
34
+ REV = nil
35
+ # UNCOMMENT IF REQUIRED:
36
+ # REV = YAML.load(`svn info`)['Revision']
37
+ VERS = SubtitleIt::VERSION::STRING + (REV ? ".#{REV}" : "")
38
+ RDOC_OPTS = ['--quiet', '--title', 'subtitle_it documentation',
39
+ "--opname", "index.html",
40
+ "--line-numbers",
41
+ "--main", "README",
42
+ "--inline-source"]
43
+
44
+ class Hoe
45
+ def extra_deps
46
+ @extra_deps.reject! { |x| Array(x).first == 'hoe' }
47
+ @extra_deps
48
+ end
49
+ end
50
+
51
+ # Generate all the Rake tasks
52
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
53
+ $hoe = Hoe.new(GEM_NAME, VERS) do |p|
54
+ p.developer(AUTHOR, EMAIL)
55
+ p.description = DESCRIPTION
56
+ p.summary = DESCRIPTION
57
+ p.url = HOMEPATH
58
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
59
+ p.test_globs = ["test/**/test_*.rb"]
60
+ p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
61
+
62
+ # == Optional
63
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
64
+ #p.extra_deps = EXTRA_DEPENDENCIES
65
+
66
+ #p.spec_extras = {} # A hash of extra values to set in the gemspec.
67
+ end
68
+
69
+ CHANGES = $hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
70
+ PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
71
+ $hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
72
+ $hoe.rsync_args = '-av --delete --ignore-errors'
73
+ $hoe.spec.post_install_message = File.open(File.dirname(__FILE__) + "/../PostInstall.txt").read rescue ""
@@ -0,0 +1,15 @@
1
+ require 'fileutils'
2
+ include FileUtils
3
+
4
+ require 'rubygems'
5
+ %w[rake hoe newgem rubigen].each do |req_gem|
6
+ begin
7
+ require req_gem
8
+ rescue LoadError
9
+ puts "This Rakefile requires the '#{req_gem}' RubyGem."
10
+ puts "Installation: gem install #{req_gem} -y"
11
+ exit
12
+ end
13
+ end
14
+
15
+ $:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
@@ -0,0 +1,132 @@
1
+ # SubtitleIt
2
+ # Command line tool
3
+ module SubtitleIt
4
+
5
+ class Subwork
6
+ def run!(file, format)
7
+ raise unless format
8
+ content = File.open(file, 'r')
9
+ STDOUT.puts "Working on file #{file}..."
10
+ sub = Subtitle.new({ :dump => content, :format => Bin.get_extension(file) })
11
+ dump = sub.send :"to_#{format}"
12
+ Bin::write_out(Bin.swap_extension(file, format), dump)
13
+ end
14
+ end
15
+
16
+ class Subdownloader
17
+ def run!(movie,lang=nil)
18
+ @movie = Movie.new(movie)
19
+ @down = Subdown.new
20
+ @down.log_in!
21
+ res = @down.search_subtitles(@movie, lang)
22
+ if res.length == 0
23
+ STDOUT.puts "No results found."
24
+ return
25
+ end
26
+ STDOUT.puts "Found #{res.length} result#{"s" if res.length > 1}. Choose one:\n"
27
+ res.sort.each_with_index { |r,i| STDOUT.puts print_option(r,i) }
28
+ STDOUT.puts "You can choose multiple ones, separated with spaces or a range separated with hifen."
29
+ STDOUT.printf "Choose: "
30
+ choose = parse_input(STDIN.gets.chomp)
31
+ choose = choose.map { |c| res[c.to_i-1] }
32
+ STDOUT.puts "Downloading #{choose.length} subtitles..."
33
+ choose.each do |sub|
34
+ down_a_sub(sub, sub.format)
35
+ end
36
+ @down.log_out!
37
+ end
38
+
39
+ def down_a_sub(sub, format)
40
+ dump = @down.download_subtitle(sub)
41
+ movie_name = @movie.filename[0..-4]
42
+ Bin::write_out(movie_name + format, dump)
43
+ end
44
+
45
+ def print_option(r, index)
46
+ c = "#{index+1}) #{r.info["MovieName"]} / #{r.info["MovieYear"]} | #{r.info["SubFileName"]} | Movie score: #{r.info["MovieImdbRating"]}\n"
47
+ c << " Lang: #{r.info["SubLanguageID"].capitalize} | Format: #{r.info["SubFormat"].upcase} | Downloads: #{r.info["SubDownloadsCnt"]} | Rating: #{r.info["SubRating"]} | CDs: #{r.info["SubSumCD"]}\n"
48
+ c << " Comments: #{r.info["SubAuthorComment"]} \n\n"
49
+ end
50
+
51
+ def parse_input(input)
52
+ choose = input.split(" ").map do |c|
53
+ if c =~ /-/
54
+ numbers = c.split("-").map { |d| d.to_i }
55
+ new_range = (numbers[0]..numbers[1]).to_a
56
+ else
57
+ c.to_i
58
+ end
59
+ end
60
+ choose.flatten.uniq
61
+ end
62
+ end
63
+
64
+ class Bin
65
+
66
+
67
+ def Bin.run! argv, lang=nil, format=nil, force=false, delay=nil
68
+ raise unless argv
69
+ @force = force
70
+ @format = format
71
+
72
+ unless File.exists?(argv[0])
73
+ # TODO generate_rsb
74
+ return
75
+ end
76
+
77
+
78
+ @file_in = argv[0]
79
+ @file_in_ext = Bin.get_extension(@file_in)
80
+ if argv[1]
81
+ @file_out = argv[1]
82
+ @file_out_ext = Bin.get_extension(@file_out)
83
+ @format = @file_out_ext
84
+ end
85
+ if MOVIE_EXTS.include? @file_in_ext
86
+ Subdownloader.new.run!(argv[0], lang)
87
+ elsif SUB_EXTS.include? @file_in_ext
88
+ Subwork.new.run!(@file_in, @format)
89
+ else
90
+ raise "Unknown file."
91
+ end
92
+
93
+ rescue Exception => e
94
+ puts e.message
95
+ exit 1
96
+ end
97
+
98
+ def Bin.get_extension(file)
99
+ raise unless file =~ /\./
100
+ file.split(".").last
101
+ end
102
+
103
+ def Bin.get_enc_platform(filename)
104
+ raise unless File.exist?(filename)
105
+ File.open(filename, 'r') do |fd|
106
+ fd.gets =~ /\r\n/ ? "WIN" : "UNIX"
107
+ end
108
+ end
109
+
110
+ def Bin.swap_extension(file,extension)
111
+ f = file.dup
112
+ f[-3..-1] = extension
113
+ f
114
+ end
115
+
116
+ def Bin.print_languages
117
+ STDOUT.puts "CODE | LANGUAGE"
118
+ LANGS.each do |l|
119
+ STDOUT.puts " #{l[0]} | #{l[1]}"
120
+ end
121
+ end
122
+
123
+ def Bin.write_out(filename,dump)
124
+ if File.exists?(filename) && !@force
125
+ STDOUT.puts "File exists. #{filename}"
126
+ else
127
+ File.open(filename, 'w') {|f| f.write(dump) }
128
+ STDOUT.puts "Done. Wrote: #{filename}."
129
+ end
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,12 @@
1
+ module SubtitleIt
2
+ # class TimeFix
3
+ # def fix_delay
4
+ # argv[1] ||= argv[0] + "_new"
5
+ # SubtitleIt.srt_delay(argv[0],argv[1])
6
+ # end
7
+ # end
8
+ #
9
+ # class CdCountFix
10
+ #end
11
+
12
+ end
@@ -0,0 +1,13 @@
1
+ # SubtitleIt
2
+ # ASS - http://en.wikipedia.org/wiki/SubStation_Alpha
3
+ # http://www.malakith.net/aegiwiki/ASS
4
+ #
5
+ module Formats
6
+ def parse_ass
7
+
8
+ end
9
+
10
+ #not mine!
11
+ def to_ass
12
+ end
13
+ end
@@ -0,0 +1,29 @@
1
+ # SubtitleIt
2
+ # MPL2 - extension .txt
3
+ #
4
+ # [1025][1115]You always say that.|The same thing every time.
5
+ #
6
+ # Where N is sec * 10
7
+ #
8
+ module Formats
9
+ include PlatformEndLine
10
+ def parse_mpl
11
+ @raw.to_a.inject([]) do |i,l|
12
+ line_data = l.scan(/^\[([0-9]{1,})\]\[([0-9]{1,})\](.+)$/)
13
+ line_data = line_data.at 0
14
+ time_on, time_off, text = line_data
15
+ time_on, time_off = [time_on.to_i, time_off.to_i].map { |t| t.to_i * 1000 }
16
+ i << Subline.new(time_on, time_off, text.chomp)
17
+ end
18
+ end
19
+
20
+ def to_mpl
21
+ endl = endline( @raw )
22
+ line_ary = []
23
+ @lines.each do |l|
24
+ start, stop = [l.time_on, l.time_off].map { |val| val.to_i / 100 }
25
+ line_ary << "[%d][%d]%s" % [start, stop, l.text]
26
+ end
27
+ return line_ary.join( endl ) + endl
28
+ end
29
+ end
@@ -0,0 +1,37 @@
1
+ # SubtitleIt
2
+ # RSB - Ruby Subtitle
3
+ #
4
+ # 00:32 => 00:33
5
+ # Nice police work! | Thank you!
6
+ # 00:53 => N == Howdy ho!
7
+ # MM:SS => N == TEXT | NEWLINE
8
+ #
9
+ # Where N is the seconds to last.
10
+ #
11
+ module Formats
12
+ include PlatformEndLine
13
+ def parse_rsb
14
+ inn = @raw.to_a
15
+ @title = inn.delete_at(0).split(':')[1]
16
+ @authors = inn.delete_at(0).split(':')[1]
17
+ @version = inn.delete_at(0).split(':')[1]
18
+ inn.inject([]) do |final,line|
19
+ time_on,time_off = line.split('=>').map { |t| t.strip }
20
+ text = line.split('==')[1].strip
21
+ final << Subline.new(time_on, time_off, text)
22
+ end
23
+ end
24
+
25
+ def to_rsb
26
+ endl = endline( @raw )
27
+ out = ["- title: #{@title}", "- authors: #{@authors}", "- version: #{@version}"]
28
+ @lines.each do |l|
29
+ out << "%s => %s == %s" % [l.time_on.to_s, l.time_off.to_s, l.text]
30
+ end
31
+ return out.join( endl ) + endl
32
+ #out = "- title: #{@title}\n- authors: #{@authors}\n- version: #{@version}\n"
33
+ #out << @lines.inject([]) do |i,l|
34
+ # i << "%s => %s == %s" % [l.time_on.to_s, l.time_off.to_s, l.text]
35
+ #end.join("\n")
36
+ end
37
+ end