Skip to content

Commit

Permalink
add dst format support
Browse files Browse the repository at this point in the history
  • Loading branch information
fazibear committed May 8, 2015
1 parent f4613e7 commit 06dd561
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
13 changes: 8 additions & 5 deletions lib/subtitle_it/bin.rb
Expand Up @@ -14,7 +14,7 @@ def run!(file, format)
end

class Subdownloader
def run!(movie,lang=nil)
def run!(movie,lang=nil, dst_format=nil)
@movie = Movie.new(movie)
@down = Subdown.new
@down.log_in!
Expand All @@ -31,15 +31,18 @@ def run!(movie,lang=nil)
choose = choose.map { |c| res[c.to_i-1] }
STDOUT.puts "Downloading #{choose.length} subtitle#{'s' if choose.length > 1}..."
choose.each do |sub|
down_a_sub(sub, sub.format)
down_a_sub(sub, sub.format, dst_format)
end
@down.log_out!
end

def down_a_sub(sub, format)
def down_a_sub(sub, format, dst_format)
dst_format ||= format
dump = @down.download_subtitle(sub)
sub = Subtitle.new({ :dump => dump, :format => format })
dump = sub.send :"to_#{dst_format}" if format != dst_format
movie_name = @movie.filename[0..-4]
Bin::write_out(movie_name + format, dump)
Bin::write_out(movie_name + dst_format, dump)
end

def print_option(r, index)
Expand Down Expand Up @@ -83,7 +86,7 @@ def Bin.run! argv, lang=nil, format=nil, force=false, delay=nil
@format = @file_out_ext
end
if MOVIE_EXTS.include? @file_in_ext
Subdownloader.new.run!(argv[0], lang)
Subdownloader.new.run!(@file_in, lang, @format)
elsif SUB_EXTS.include? @file_in_ext
Subwork.new.run!(@file_in, @format)
else
Expand Down
8 changes: 4 additions & 4 deletions lib/subtitle_it/formats/srt.rb
Expand Up @@ -8,15 +8,15 @@
#
# Where N is the sub index number
#
module Formats
module Formats
include PlatformEndLine
def parse_srt
endl = endline( @raw )
@raw.split( endl*2 ).inject([]) do |final,line|
line = line.split(endl)
line.delete_at(0)
time_on,time_off = line[0].split('-->').map { |t| t.strip }
line.delete_at(0)
line.delete_at(0)
text = line.join("|")
final << Subline.new(time_on, time_off, text)
end
Expand All @@ -28,10 +28,10 @@ def to_srt
@lines.each_with_index do |l,i|
out << "#{i+1}"
out << "%s --> %s" % [l.time_on.to_s(','), l.time_off.to_s(',')]
out << l.text.gsub("|", endl) + endl
out << (l.text ? l.text.gsub("|", endl) + endl : ' ' + endl)
end
out.join( endl )
end
end
end

#looks like subrip accepts some styling:
Expand Down

0 comments on commit 06dd561

Please sign in to comment.