subtitle_it 1.9.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +5 -0
  3. data/Gemfile +3 -0
  4. data/{README.rdoc → README.md} +22 -18
  5. data/Rakefile +13 -18
  6. data/bin/subtitle_it +4 -8
  7. data/lib/subtitle_it/bin.rb +50 -58
  8. data/lib/subtitle_it/fixes.rb +3 -4
  9. data/lib/subtitle_it/formats/ass.rb +5 -6
  10. data/lib/subtitle_it/formats/mpl.rb +9 -9
  11. data/lib/subtitle_it/formats/rsb.rb +9 -9
  12. data/lib/subtitle_it/formats/srt.rb +17 -14
  13. data/lib/subtitle_it/formats/sub.rb +7 -7
  14. data/lib/subtitle_it/formats/xml.rb +13 -12
  15. data/lib/subtitle_it/formats/yml.rb +5 -5
  16. data/lib/subtitle_it/generator.rb +2 -2
  17. data/lib/subtitle_it/languages.rb +52 -53
  18. data/lib/subtitle_it/movie.rb +26 -6
  19. data/lib/subtitle_it/platform_endl.rb +7 -5
  20. data/lib/subtitle_it/subdown.rb +30 -33
  21. data/lib/subtitle_it/subline.rb +5 -5
  22. data/lib/subtitle_it/substyle.rb +3 -9
  23. data/lib/subtitle_it/subtime.rb +19 -10
  24. data/lib/subtitle_it/subtitle.rb +20 -28
  25. data/lib/subtitle_it/version.rb +1 -7
  26. data/lib/subtitle_it.rb +7 -7
  27. data/spec/fixtures/movie.xml +2 -2
  28. data/spec/spec_helper.rb +6 -6
  29. data/spec/subtitle_it/bin_spec.rb +110 -98
  30. data/spec/subtitle_it/formats/ass_spec.rb +2 -3
  31. data/spec/subtitle_it/formats/mpl_spec.rb +26 -28
  32. data/spec/subtitle_it/formats/rsb_spec.rb +29 -30
  33. data/spec/subtitle_it/formats/srt_spec.rb +27 -30
  34. data/spec/subtitle_it/formats/sub_spec.rb +19 -21
  35. data/spec/subtitle_it/formats/xml_spec.rb +21 -21
  36. data/spec/subtitle_it/formats/yml_spec.rb +14 -15
  37. data/spec/subtitle_it/movie_spec.rb +24 -15
  38. data/spec/subtitle_it/subdown_spec.rb +58 -65
  39. data/spec/subtitle_it/subline_spec.rb +17 -18
  40. data/spec/subtitle_it/subtime_spec.rb +43 -44
  41. data/spec/subtitle_it/subtitle_spec.rb +28 -29
  42. data/spec/subtitle_it_spec.rb +4 -5
  43. data/subtitle_it.gemspec +25 -98
  44. metadata +121 -67
  45. data/.rspec +0 -2
  46. data/config/hoe.rb +0 -73
  47. data/config/requirements.rb +0 -15
  48. data/lib/subtitle_it/movie_hasher.rb +0 -30
  49. data/script/console +0 -10
  50. data/script/destroy +0 -14
  51. data/script/generate +0 -14
  52. data/script/txt2html +0 -82
  53. data/spec/subtitle_it/movie_hasher_spec.rb +0 -13
  54. data/tasks/deployment.rake +0 -34
  55. data/tasks/environment.rake +0 -7
  56. data/tasks/rspec.rake +0 -21
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5e89ad4165e8f6502df504f903bea91ab440fa6c
4
+ data.tar.gz: 9f771d45a07d6720aecd20edd763eadc766ef179
5
+ SHA512:
6
+ metadata.gz: 4ca034e01f764d55552192df5a5036418699696d7d8b1246ef2ccf345abb83f8866f3c2fc354a0053baf18bf98727e126f7e350b93cdc970800e1282a068c68f
7
+ data.tar.gz: f8596dd83734c9271881dac335f93dfe19b3a574e146f42db828c8950b05e9aa4032c44639ac53a33914b41116124caeda67c5950e5b4db8e3fc9aed2edfdd9a
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ .DS_Store
2
+ doc
3
+ *~
4
+ pkg/*
5
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -1,14 +1,14 @@
1
- __ __
2
- / ) / , / /
3
- ----\--------------/__--_/_------_/_---/----__-----/---_/_-
4
- \ / / / ) / / / / /___) / /
5
- _(____/___(___(__(___/_(_ __/___(_ __/___(___ _ _/_ __(_ __
1
+ __ __
2
+ / ) / , / /
3
+ ----\--------------/__--_/_------_/_---/----__-----/---_/_-
4
+ \ / / / ) / / / / /___) / /
5
+ _(____/___(___(__(___/_(_ __/___(_ __/___(___ _ _/_ __(_ __
6
6
 
7
7
 
8
8
  Ruby tool to download, create, convert and fix subtitles.
9
9
 
10
10
 
11
- == FEATURES
11
+ # FEATURES
12
12
 
13
13
  * Automatic Download on the terminal
14
14
  * To and from: SRT, SUB, XML(TT), YML, MPL2, RSB and ASS.
@@ -16,7 +16,7 @@ Ruby tool to download, create, convert and fix subtitles.
16
16
  * Compatibility with "sube" (http://github.com/vic/sube)
17
17
 
18
18
 
19
- == SYNOPSIS
19
+ # SYNOPSIS
20
20
 
21
21
  Download subtitle:
22
22
 
@@ -26,8 +26,11 @@ This will search all languages for the video. You can filter:
26
26
 
27
27
  subtitle_it -l Eng Cool-Video.avi
28
28
 
29
+ You can use -c option. It convert subtitles to given format:
29
30
 
30
- Bash tool:
31
+ subtitle_it -l Eng -c srt Cool-Video.avi
32
+
33
+ ## Bash tool
31
34
 
32
35
  Convert a srt to sub:
33
36
  subtitle_it in.srt out.sub
@@ -41,26 +44,27 @@ Create a template
41
44
  subtitle_it unexistent.file
42
45
 
43
46
 
44
- == INSTALL
47
+ # INSTALL
45
48
 
46
- gem sources add http://gems.github.com
47
- sudo gem install nofxx-subtitle_it
49
+ gem install subtitle_it
48
50
 
49
51
 
50
- == THE "Ruby Subtitle" Format - RSB
52
+ ## THE "Ruby Subtitle" Format - RSB
51
53
 
52
54
  It`s just a easy way, proof of concept to edit subtitles.
53
55
  Here is what it looks like:
54
56
 
57
+ ```
55
58
  00:32 => 00:33 == Nice police work! | Thank you!
56
59
  00:35 => 3 == Nice job!
57
60
 
58
61
  MM:SS => MM:SS or N == TEXT | NEWLINE
62
+ ```
59
63
 
60
64
  Create a template to check it out.
61
65
 
62
66
 
63
- == Automatic Download
67
+ ## Automatic Download
64
68
 
65
69
  * OpenSubtitles.org - WORK SubtitleIt Agent
66
70
  * addic7ed.com - EVIL NOAPI
@@ -70,7 +74,7 @@ Create a template to check it out.
70
74
  *NOAPI = Mechanize playground...
71
75
 
72
76
 
73
- == DEV
77
+ ## DEV
74
78
 
75
79
  To run tests:
76
80
 
@@ -80,7 +84,7 @@ Documentation => doc
80
84
  Subtitle examples => spec/fixtures
81
85
 
82
86
 
83
- == SUBTITLE EDITORS
87
+ ## SUBTITLE EDITORS
84
88
 
85
89
  Try those nice editors too, if SubtitleIt does not fit your need:
86
90
 
@@ -89,20 +93,20 @@ Jubler: http://www.jubler.org/
89
93
  Aegisub: http://www.malakith.net/aegiwiki/Main_Page
90
94
 
91
95
 
92
- == THANKS
96
+ ## THANKS
93
97
 
94
98
  * Johanlunds - Opensubtitle.org code (to be used as a gem soon).
95
99
  * Marcin (tiraeth) Chwedziak - Sub format first implementation.
96
100
 
97
101
 
98
- == TODO
102
+ ## TODO
99
103
 
100
104
  Please visit:
101
105
 
102
106
  * http://github.com/nofxx/subtitle_it
103
107
  * Support http://www.podnapisi.net/
104
108
 
105
- == LICENSE:
109
+ ## LICENSE:
106
110
 
107
111
  (The MIT License)
108
112
 
data/Rakefile CHANGED
@@ -1,21 +1,16 @@
1
- require 'rubygems'
2
- require 'rake'
1
+ #!/usr/bin/env rake
2
+ require 'bundler/gem_tasks'
3
3
 
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "subtitle_it"
8
- gem.summary = "Download, edit and create subtitles."
9
- gem.description = "Download, edit and create subtitles. Supports various formats."
10
- gem.email = "x@nofxx.com"
11
- gem.homepage = "http://github.com/nofxx/subtitle_it"
12
- gem.authors = ["Marcos Piccinini"]
13
- gem.add_development_dependency "rspec", ">= 1.2.9"
14
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
- end
16
- Jeweler::GemcutterTasks.new
17
- rescue LoadError
18
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
4
+ require 'rspec/core'
5
+ require 'rspec/core/rake_task'
6
+ RSpec::Core::RakeTask.new(:spec) do |spec|
7
+ spec.pattern = FileList['spec/**/*_spec.rb']
19
8
  end
20
9
 
21
- task :default => :build
10
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
11
+ spec.pattern = 'spec/**/*_spec.rb'
12
+ spec.rcov = true
13
+ end
14
+
15
+ task default: :spec
16
+
data/bin/subtitle_it CHANGED
@@ -5,12 +5,8 @@
5
5
  # Copyleft (c) 2008. MIT License.
6
6
  #
7
7
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
8
- begin
9
- require 'rubygems'
10
- rescue LoadError
11
- # no rubygems to load, so we fail silently
12
- end
13
8
 
9
+ require 'colorize'
14
10
  require 'optparse'
15
11
  require 'subtitle_it'
16
12
 
@@ -43,10 +39,10 @@ BANNER
43
39
  end
44
40
 
45
41
  opts.on("-c", "--convert=FORMAT", String,
46
- "Format to convert to") { |of| OPTIONS[:format] = of }
42
+ "Format to convert to") { |o| OPTIONS[:format] = o }
47
43
 
48
44
  opts.on("-d", "--delay=DELAY", Float,
49
- "Delay to add/remove") { |od| OPTIONS[:delay] = od }
45
+ "Delay to add/remove") { |o| OPTIONS[:delay] = o }
50
46
 
51
47
  opts.on("-f", "--force", "Force overwrite") { OPTIONS[:force] = true }
52
48
 
@@ -54,7 +50,7 @@ BANNER
54
50
  "Show this help message.") { puts opts; exit }
55
51
 
56
52
  opts.on("-v", "--version",
57
- "Show program version") { puts "SubtitleIt v#{SubtitleIt::VERSION::STRING}"; exit }
53
+ "Show program version") { puts "SubtitleIt v#{SubtitleIt::VERSION}"; exit }
58
54
 
59
55
  opts.parse!(ARGV)
60
56
 
@@ -1,58 +1,65 @@
1
1
  # SubtitleIt
2
2
  # Command line tool
3
3
  module SubtitleIt
4
-
5
4
  class Subwork
6
5
  def run!(file, format)
7
- raise unless format
6
+ fail unless format
8
7
  content = File.open(file, 'r')
9
- STDOUT.puts "Working on file #{file}..."
10
- sub = Subtitle.new({ :dump => content, :format => Bin.get_extension(file) })
8
+ puts "Working on file #{file}..."
9
+ sub = Subtitle.new(dump: content, format: Bin.get_extension(file))
11
10
  dump = sub.send :"to_#{format}"
12
- Bin::write_out(Bin.swap_extension(file, format), dump)
11
+ Bin.write_out(Bin.swap_extension(file, format), dump)
13
12
  end
14
13
  end
15
14
 
16
15
  class Subdownloader
17
- def run!(movie,lang=nil)
16
+ def run!(movie, lang = nil, dst_format = nil)
18
17
  @movie = Movie.new(movie)
19
18
  @down = Subdown.new
20
19
  @down.log_in!
21
- res = @down.search_subtitles(@movie, OPTIONS[:lang])
20
+ res = @down.search_subtitles(@movie, lang).sort
22
21
  if res.length == 0
23
- STDOUT.puts "No results found."
22
+ puts 'No results found.'
24
23
  return
25
24
  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: "
25
+ puts 'You can choose multiple ones separated with spaces '\
26
+ 'or a range separated with a hifen.'
27
+ puts "Found #{res.size.to_s.yellow} result#{'s' if res.size > 1}:\n"
28
+ res.each_with_index { |r, i| puts print_option(r.info, i) }
29
+ STDOUT.print "Choose (1-#{res.size}): "
30
30
  choose = parse_input(STDIN.gets.chomp)
31
- choose = choose.map { |c| res[c.to_i-1] }
32
- STDOUT.puts "Downloading #{choose.length} subtitle#{'s' if choose.length > 1}..."
31
+ choose = choose.map { |c| res[c.to_i - 1] }
32
+ puts "Downloading #{choose.size} subtitle#{'s' if choose.size > 1}..."
33
33
  choose.each do |sub|
34
- down_a_sub(sub, sub.format)
34
+ down_a_sub(sub, dst_format)
35
35
  end
36
36
  @down.log_out!
37
37
  end
38
38
 
39
- def down_a_sub(sub, format)
39
+ def down_a_sub(sub, dst_format)
40
+ dst_format ||= sub.format
40
41
  dump = @down.download_subtitle(sub)
41
- movie_name = @movie.filename[0..-4]
42
- Bin::write_out(movie_name + format, dump)
42
+ if sub.format != dst_format
43
+ subt = Subtitle.new(dump: dump, format: dst_format)
44
+ dump = subt.send :"to_#{dst_format}"
45
+ end
46
+ fname = @movie.filename[0..-4] + sub.info['SubLanguageID']
47
+ Bin.write_out("#{fname}.#{dst_format}", dump)
43
48
  end
44
49
 
45
50
  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"
51
+ date = Date.parse(r['SubAddDate'])
52
+ " #{(index + 1).to_s.yellow}. #{r['LanguageName'][0,3].green}"\
53
+ " | #{r['SubFormat'].upcase.blue} | #{r['MovieName'].cyan}"\
54
+ " / #{r['MovieYear'].cyan} | #{r['SubRating'].yellow}"\
55
+ " | FPS #{r['MovieFPS']} | #{r['SubSumCD']} CDs | #{date}"
49
56
  end
50
57
 
51
58
  def parse_input(input)
52
- choose = input.split(" ").map do |c|
59
+ choose = input.split(' ').map do |c|
53
60
  if c =~ /-/
54
- numbers = c.split("-").map { |d| d.to_i }
55
- new_range = (numbers[0]..numbers[1]).to_a
61
+ numbers = c.split('-').map(&:to_i)
62
+ (numbers[0]..numbers[1]).to_a
56
63
  else
57
64
  c.to_i
58
65
  end
@@ -62,18 +69,13 @@ module SubtitleIt
62
69
  end
63
70
 
64
71
  class Bin
65
-
66
-
67
- def Bin.run! argv, lang=nil, format=nil, force=false, delay=nil
68
- raise unless argv
72
+ def self.run!(argv, lang = nil, format = nil, force = false, _delay = nil)
73
+ fail unless argv
69
74
  @force = force
70
75
  @format = format
71
76
 
72
- unless File.exists?(argv[0])
73
- # TODO generate_rsb
74
- return
75
- end
76
-
77
+ # TODO: generate_rsb
78
+ return unless File.exist?(argv[0])
77
79
 
78
80
  @file_in = argv[0]
79
81
  @file_in_ext = Bin.get_extension(@file_in)
@@ -82,50 +84,40 @@ module SubtitleIt
82
84
  @file_out_ext = Bin.get_extension(@file_out)
83
85
  @format = @file_out_ext
84
86
  end
87
+
85
88
  if MOVIE_EXTS.include? @file_in_ext
86
- Subdownloader.new.run!(argv[0], lang)
89
+ Subdownloader.new.run!(@file_in, lang, @format)
87
90
  elsif SUB_EXTS.include? @file_in_ext
88
91
  Subwork.new.run!(@file_in, @format)
89
92
  else
90
- raise "Unknown file."
93
+ fail "Unknown file type '#{@file_in_ext}'."
91
94
  end
92
-
93
- rescue Exception => e
94
- puts e.message
95
- exit 1
96
95
  end
97
96
 
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
97
+ def self.get_extension(file)
98
+ fail unless file =~ /\./
99
+ file.split('.').last
108
100
  end
109
101
 
110
- def Bin.swap_extension(file,extension)
102
+ def self.swap_extension(file, extension)
111
103
  f = file.dup
112
104
  f[-3..-1] = extension
113
105
  f
114
106
  end
115
107
 
116
- def Bin.print_languages
117
- STDOUT.puts "CODE | LANGUAGE"
108
+ def self.print_languages
109
+ puts 'CODE | LANGUAGE'
118
110
  LANGS.each do |l|
119
- STDOUT.puts " #{l[0]} | #{l[1]}"
111
+ puts " #{l[0]} | #{l[1]}"
120
112
  end
121
113
  end
122
114
 
123
- def Bin.write_out(filename,dump)
124
- if File.exists?(filename) && !@force
125
- STDOUT.puts "File exists. #{filename}"
115
+ def self.write_out(filename, dump)
116
+ if File.exist?(filename) && !@force
117
+ puts "File exist: #{filename}".red
126
118
  else
127
- File.open(filename, 'w') {|f| f.write(dump) }
128
- STDOUT.puts "Done. Wrote: #{filename}."
119
+ File.open(filename, 'w') { |f| f.write(dump) }
120
+ puts "Done: #{filename}".yellow
129
121
  end
130
122
  end
131
123
  end
@@ -2,11 +2,10 @@ module SubtitleIt
2
2
  # class TimeFix
3
3
  # def fix_delay
4
4
  # argv[1] ||= argv[0] + "_new"
5
- # SubtitleIt.srt_delay(argv[0],argv[1])
5
+ # SubtitleIt.srt_delay(argv[0], argv[1])
6
6
  # end
7
7
  # end
8
- #
8
+ #
9
9
  # class CdCountFix
10
- #end
11
-
10
+ # end
12
11
  end
@@ -1,13 +1,12 @@
1
1
  # SubtitleIt
2
2
  # ASS - http://en.wikipedia.org/wiki/SubStation_Alpha
3
3
  # http://www.malakith.net/aegiwiki/ASS
4
- #TODO ass!
5
- module Formats
4
+ # TODO: ass!
5
+ module Formats
6
6
  def parse_ass
7
-
8
7
  end
9
-
10
- #not mine!
8
+
9
+ # not mine!
11
10
  def to_ass
12
- end
11
+ end
13
12
  end
@@ -5,25 +5,25 @@
5
5
  #
6
6
  # Where N is sec * 10
7
7
  #
8
- module Formats
8
+ module Formats
9
9
  include PlatformEndLine
10
10
  def parse_mpl
11
- @raw.to_a.inject([]) do |i,l|
11
+ @raw.to_a.inject([]) do |i, l|
12
12
  line_data = l.scan(/^\[([0-9]{1,})\]\[([0-9]{1,})\](.+)$/)
13
13
  line_data = line_data.at 0
14
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 }
15
+ time_on, time_off = [time_on.to_i, time_off.to_i].map { |t| t.to_i * 1000 }
16
16
  i << Subline.new(time_on, time_off, text.chomp)
17
17
  end
18
18
  end
19
-
19
+
20
20
  def to_mpl
21
- endl = endline( @raw )
21
+ endl = endline(@raw)
22
22
  line_ary = []
23
23
  @lines.each do |l|
24
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]
25
+ line_ary << '[%d][%d]%s' % [start, stop, l.text]
26
26
  end
27
- return line_ary.join( endl ) + endl
28
- end
29
- end
27
+ line_ary.join(endl) + endl
28
+ end
29
+ end
@@ -15,23 +15,23 @@ module Formats
15
15
  @title = inn.delete_at(0).split(':')[1]
16
16
  @authors = inn.delete_at(0).split(':')[1]
17
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
18
+ inn.inject([]) do |final, line|
19
+ time_on, time_off = line.split('=>').map(&:strip)
20
+ text = line.split('==')[1] # .strip
21
21
  final << Subline.new(time_on, time_off, text ? text.strip : nil)
22
22
  end
23
23
  end
24
24
 
25
25
  def to_rsb
26
- endl = endline( @raw )
26
+ endl = endline(@raw)
27
27
  out = ["- title: #{@title}", "- authors: #{@authors}", "- version: #{@version}"]
28
28
  @lines.each do |l|
29
- out << "%s => %s == %s" % [l.time_on.to_s, l.time_off.to_s, l.text]
29
+ out << '%s => %s == %s' % [l.time_on.to_s, l.time_off.to_s, l.text]
30
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|
31
+ out.join(endl) + endl
32
+ # out = "- title: #{@title}\n- authors: #{@authors}\n- version: #{@version}\n"
33
+ # out << @lines.inject([]) do |i,l|
34
34
  # i << "%s => %s == %s" % [l.time_on.to_s, l.time_off.to_s, l.text]
35
- #end.join("\n")
35
+ # end.join("\n")
36
36
  end
37
37
  end
@@ -8,33 +8,36 @@
8
8
  #
9
9
  # Where N is the sub index number
10
10
  #
11
- module Formats
11
+ module Formats
12
12
  include PlatformEndLine
13
+
14
+ def endl
15
+ endline(@raw)
16
+ end
17
+
13
18
  def parse_srt
14
- endl = endline( @raw )
15
- @raw.split( endl*2 ).inject([]) do |final,line|
19
+ @raw.split(endl * 2).inject([]) do |final, line|
16
20
  line = line.split(endl)
17
21
  line.delete_at(0)
18
- time_on,time_off = line[0].split('-->').map { |t| t.strip }
19
- line.delete_at(0)
20
- text = line.join("|")
22
+ time_on, time_off = line[0].split('-->').map(&:strip)
23
+ line.delete_at(0)
24
+ text = line.join('|')
21
25
  final << Subline.new(time_on, time_off, text)
22
26
  end
23
27
  end
24
28
 
25
29
  def to_srt
26
- endl = endline( @raw )
27
30
  out = []
28
- @lines.each_with_index do |l,i|
29
- out << "#{i+1}"
30
- out << "%s --> %s" % [l.time_on.to_s(','), l.time_off.to_s(',')]
31
- out << l.text.gsub("|", endl) + endl
31
+ @lines.each_with_index do |l, i|
32
+ out << "#{i + 1}"
33
+ out << '%s --> %s' % [l.time_on.to_s(','), l.time_off.to_s(',')]
34
+ out << (l.text ? l.text.gsub('|', endl) : ' ') + endl
32
35
  end
33
- out.join( endl )
34
- end
36
+ out.join(endl)
37
+ end
35
38
  end
36
39
 
37
- #looks like subrip accepts some styling:
40
+ # looks like subrip accepts some styling:
38
41
  # sdict.add(new StyledFormat(ITALIC, "i", true));
39
42
  # sdict.add(new StyledFormat(ITALIC, "/i", false));
40
43
  # sdict.add(new StyledFormat(BOLD, "b", true));
@@ -1,6 +1,6 @@
1
1
  # SubtitleIt
2
2
  # MPSub, MicroDVD or VOBSub format
3
- #TODO: tricky.. detect which format we got.
3
+ # TODO: tricky.. detect which format we got.
4
4
  #
5
5
  # {1025}{1115}You always say that.|The same thing every time.
6
6
  # {1118}{1177}"l'm throug h, never again,|too dangerous."
@@ -17,14 +17,14 @@
17
17
  #
18
18
  module Formats
19
19
  include PlatformEndLine
20
- #between our formats, what changes can be reduced to a value
20
+ # between our formats, what changes can be reduced to a value
21
21
  def ratio
22
- 1
22
+ 1
23
23
  end
24
24
 
25
25
  def parse_sub
26
26
  # FIXME: 1.8 and 1.9 way of working
27
- @raw.send(@raw.respond_to?(:lines) ? :lines : :to_a).reduce([]) do |i,l|
27
+ @raw.send(@raw.respond_to?(:lines) ? :lines : :to_a).reduce([]) do |i, l|
28
28
  line_data = l.scan(/^\{([0-9]{1,})\}\{([0-9]{1,})\}(.+)$/)
29
29
  line_data = line_data.at 0
30
30
  time_on, time_off, text = line_data
@@ -36,12 +36,12 @@ module Formats
36
36
  end
37
37
 
38
38
  def to_sub
39
- endl = endline( @raw )
39
+ endl = endline(@raw)
40
40
  line_ary = []
41
41
  @lines.each do |l|
42
- line_ary << "{%d}{%d}%s" % [parse_time(l.time_on), parse_time(l.time_off), l.text]
42
+ line_ary << '{%d}{%d}%s' % [parse_time(l.time_on), parse_time(l.time_off), l.text]
43
43
  end
44
- return line_ary.join( endl ) + endl
44
+ line_ary.join(endl) + endl
45
45
  end
46
46
 
47
47
  def parse_time(n)
@@ -18,34 +18,35 @@
18
18
  # <p begin="00:00:29.02" dur="00:00:01.30" style="1">as <span tts:color="#ccc333">easy</span> as drawing on paper.</p>
19
19
  # </div>
20
20
  # </body>
21
- #</tt>
22
- require 'hpricot'
21
+ # </tt>
22
+ require 'nokogiri'
23
+
23
24
  module Formats
24
25
  include PlatformEndLine
25
26
 
26
27
  def parse_xml
27
28
  final = []
28
- doc = Hpricot.XML(@raw)
29
- (doc/'tt'/'p').each do |line|
30
- time_on, time_off = ['begin', 'dur'].map { |str| line[str.to_sym] }
31
- text = line.innerHTML
32
- final << Subline.new(time_on,time_off,text)
29
+ doc = Nokogiri::XML.parse(@raw)
30
+ (doc / 'tt' / 'p').each do |line|
31
+ time_on, time_off = %w(begin dur).map { |str| line[str.to_sym] }
32
+ text = line.inner_html
33
+ final << Subline.new(time_on, time_off, text)
33
34
  end
34
- return final
35
+ final
35
36
  end
36
37
 
37
38
  def xml_lines
38
- endl = endline( @raw )
39
+ endl = endline(@raw)
39
40
  line_ary = []
40
41
  @lines.each do |l|
41
42
  toff = l.time_off - l.time_on
42
43
  line_ary << " <p begin=\"#{l.time_on}\" dur=\"#{toff}\">#{l.text}</p>"
43
44
  end
44
- return line_ary.join( endl )
45
+ line_ary.join(endl)
45
46
  end
46
47
 
47
48
  def to_xml
48
- endl = endline( @raw )
49
+ endl = endline(@raw)
49
50
  out = <<XML
50
51
  <?xml version="1.0" encoding="UTF-8"?>
51
52
  <tt xml:lang="en" xmlns="http://www.w3.org/2006/10/ttaf1" xmlns:tts="http://www.w3.org/2006/10/ttaf1#styling">
@@ -60,6 +61,6 @@ module Formats
60
61
  </body>
61
62
  </tt>
62
63
  XML
63
- out.chomp
64
+ out.chomp
64
65
  end
65
66
  end
@@ -1,18 +1,18 @@
1
1
  # SubtitleIt
2
2
  # YML Dump
3
3
  #
4
- require 'yaml'
5
- module Formats
4
+
5
+ module Formats
6
6
  def parse_yml
7
- @yaml = YAML::load(@raw)
7
+ @yaml = YAML.load(@raw)
8
8
  header = @yaml.delete('header')
9
9
  @title = header['title']
10
10
  @author = header['authors']
11
11
  @version = header['version']
12
12
  @yaml['lines'].map { |l| Subline.new(l[0], l[1], l[2]) }
13
13
  end
14
-
14
+
15
15
  def to_yml
16
16
  YAML.dump(self)
17
- end
17
+ end
18
18
  end