nofxx-subtitle_it 0.6.1 → 0.6.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest.txt +4 -0
- data/bin/subtitle_it +32 -40
- data/lib/subtitle_it/formats/xml.rb +5 -5
- data/lib/subtitle_it/movie.rb +25 -0
- data/lib/subtitle_it/movie_hasher.rb +30 -0
- data/lib/subtitle_it/subtime.rb +9 -4
- data/lib/subtitle_it/version.rb +1 -1
- data/lib/subtitle_it.rb +0 -30
- data/spec/subtitle_it/formats/xml_spec.rb +15 -1
- data/subtitle_it.gemspec +2 -2
- metadata +5 -1
data/Manifest.txt
CHANGED
@@ -6,6 +6,8 @@ README.markdown
|
|
6
6
|
README.txt
|
7
7
|
Rakefile
|
8
8
|
bin/subtitle_it
|
9
|
+
blu.rsb
|
10
|
+
blua.rsb
|
9
11
|
config/hoe.rb
|
10
12
|
config/requirements.rb
|
11
13
|
lib/subtitle_it.rb
|
@@ -15,6 +17,8 @@ lib/subtitle_it/formats/srt.rb
|
|
15
17
|
lib/subtitle_it/formats/sub.rb
|
16
18
|
lib/subtitle_it/formats/xml.rb
|
17
19
|
lib/subtitle_it/formats/yml.rb
|
20
|
+
lib/subtitle_it/movie.rb
|
21
|
+
lib/subtitle_it/movie_hasher.rb
|
18
22
|
lib/subtitle_it/subline.rb
|
19
23
|
lib/subtitle_it/subtime.rb
|
20
24
|
lib/subtitle_it/subtitle.rb
|
data/bin/subtitle_it
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# SubtitleIt
|
2
3
|
#
|
3
4
|
# Created on 2008-9-4.
|
4
5
|
# Copyright (c) 2008. All rights reserved.
|
5
|
-
|
6
|
+
#
|
6
7
|
begin
|
7
8
|
require 'rubygems'
|
8
9
|
rescue LoadError
|
@@ -13,10 +14,9 @@ require 'optparse'
|
|
13
14
|
require 'subtitle_it'
|
14
15
|
|
15
16
|
include SubtitleIt
|
16
|
-
# NOTE: the option -p/--path= is given as an example, and should probably be replaced in your application.
|
17
17
|
|
18
18
|
OPTIONS = {
|
19
|
-
|
19
|
+
:force => false,
|
20
20
|
:format => nil,
|
21
21
|
:delay => nil
|
22
22
|
}
|
@@ -30,26 +30,32 @@ Usage: #{File.basename($0)} [options] file_in [file_out]
|
|
30
30
|
|
31
31
|
Options are:
|
32
32
|
-c FORMAT --convert=FORMAT Format to convert to: yml, srt or sub.
|
33
|
+
You don`t need to use this if fileout contains a extension.
|
34
|
+
|
35
|
+
-f --force Force overwrite.
|
33
36
|
|
34
37
|
-d DELAY --delay=DELAY Fix the delay of the file.
|
35
38
|
|
39
|
+
-h --help Show this.
|
40
|
+
|
41
|
+
-v --version Program version.
|
36
42
|
BANNER
|
37
43
|
opts.separator ""
|
38
|
-
|
39
|
-
# "The root path for selecting files",
|
40
|
-
# "Default: ~") { |OPTIONS[:path]| }
|
41
|
-
|
44
|
+
|
42
45
|
opts.on("-c", "--convert=FORMAT", String,
|
43
46
|
"Format to convert to") { |OPTIONS[:format]| }
|
44
47
|
|
45
48
|
opts.on("-d", "--delay=DELAY", Float,
|
46
49
|
"Delay to add/remove") { |OPTIONS[:delay]| }
|
47
50
|
|
51
|
+
opts.on("-f", "--force", "Force overwrite") { OPTIONS[:force] = true }
|
52
|
+
|
48
53
|
opts.on("-h", "--help",
|
49
54
|
"Show this help message.") { puts opts; exit }
|
50
|
-
|
55
|
+
|
56
|
+
#FIXME: I gave up... I cant acess the version var from here... missing something.
|
51
57
|
opts.on("-v", "--version",
|
52
|
-
"Show program version") {
|
58
|
+
"Show program version") { puts 'SubtitleIt v0.6.3'; exit }
|
53
59
|
|
54
60
|
opts.parse!(ARGV)
|
55
61
|
|
@@ -57,12 +63,6 @@ BANNER
|
|
57
63
|
puts opts; exit
|
58
64
|
end
|
59
65
|
end
|
60
|
-
t = Time.now
|
61
|
-
if OPTIONS[:version]
|
62
|
-
include SubtitleIt
|
63
|
-
puts a
|
64
|
-
exit
|
65
|
-
end
|
66
66
|
|
67
67
|
if ARGV.empty?
|
68
68
|
puts parser.banner
|
@@ -71,45 +71,37 @@ end
|
|
71
71
|
|
72
72
|
filein, filein_ext = ARGV[0].split('.')
|
73
73
|
fileout, fileout_ext = ARGV[1] ? ARGV[1].split('.') : [filein, filein_ext]
|
74
|
-
|
75
|
-
if File.exists?(ARGV[0])
|
74
|
+
t = Time.now
|
75
|
+
if File.exists?(ARGV[0]) && ( ARGV[1] || OPTIONS[:format] )
|
76
76
|
content = File.open(ARGV[0], 'r')
|
77
77
|
if OPTIONS[:delay]
|
78
78
|
ARGV[1] ||= ARGV[0] + "_new"
|
79
79
|
SubtitleIt.srt_delay(ARGV[0],ARGV[1])
|
80
80
|
else
|
81
|
-
include SubtitleIt
|
82
81
|
puts "Working on file #{filein}..."
|
83
82
|
sub = Subtitle.new(content, filein_ext)
|
84
83
|
format = OPTIONS[:format]
|
85
84
|
format ||= fileout_ext unless fileout_ext == filein_ext
|
86
|
-
out =
|
87
|
-
|
88
|
-
when 'sub' then sub.to_sub
|
89
|
-
when 'srt' then sub.to_srt
|
90
|
-
else
|
91
|
-
puts "Dunno what to do with this file!"
|
92
|
-
exit
|
93
|
-
end
|
85
|
+
out = sub.send :"to_#{format}"
|
86
|
+
#TODO: rescue format not found....
|
94
87
|
end
|
95
88
|
else
|
89
|
+
format = 'rsb'
|
96
90
|
out = <<GEN
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
- ['00:05:26.5', '2', 'worth killing for...']
|
91
|
+
- title: #{ARGV[0]}
|
92
|
+
- authors: FIXME
|
93
|
+
- version: FIXME
|
94
|
+
00:05:26.500 => 00:05:28.500 == worth killing for...
|
95
|
+
00:06:00.400 => 00:06:03.400 == worth dying for...
|
96
|
+
00:07:00.300 => 00:07:03.300 == worth going to the hell for...
|
104
97
|
GEN
|
105
|
-
OPTIONS[:format] = 'rsb'
|
106
98
|
end
|
107
99
|
|
108
|
-
fout = "#{fileout}.#{
|
100
|
+
fout = "#{fileout}.#{format}"
|
109
101
|
|
110
|
-
if File.
|
111
|
-
|
112
|
-
puts "Done. Total time: #{Time.now - t}"
|
102
|
+
if File.exists?(fout) && !OPTIONS[:force]
|
103
|
+
puts "File exists. #{fout}"
|
113
104
|
else
|
114
|
-
|
115
|
-
|
105
|
+
File.open(fout, 'w') {|f| f.write(out) }
|
106
|
+
puts "Done. Wrote: #{fout} in #{Time.now - t}s."
|
107
|
+
end
|
@@ -39,8 +39,8 @@ module SubtitleIt
|
|
39
39
|
def xml_lines
|
40
40
|
@lines.inject([]) do |i,l|
|
41
41
|
toff = l.text_off - l.text_on
|
42
|
-
i << "<p begin=\"#{l.text_on}\" dur=\"#{toff}\">#{l.text}</p>"
|
43
|
-
end
|
42
|
+
i << " <p begin=\"#{l.text_on}\" dur=\"#{toff}\">#{l.text}</p>"
|
43
|
+
end.join("\n")
|
44
44
|
end
|
45
45
|
|
46
46
|
def to_xml
|
@@ -48,17 +48,17 @@ module SubtitleIt
|
|
48
48
|
<?xml version="1.0" encoding="UTF-8"?>
|
49
49
|
<tt xml:lang="en" xmlns="http://www.w3.org/2006/04/ttaf1" xmlns:tts="http://www.w3.org/2006/04/ttaf1#styling">
|
50
50
|
<head>
|
51
|
-
<styling
|
52
|
-
#{@style}
|
51
|
+
<styling>#{@style + "\n" if @style}
|
53
52
|
</styling>
|
54
53
|
</head>
|
55
54
|
<body>
|
56
55
|
<div xml:lang="en">
|
57
|
-
|
56
|
+
#{xml_lines}
|
58
57
|
</div>
|
59
58
|
</body>
|
60
59
|
</tt>
|
61
60
|
XML
|
61
|
+
out.chomp
|
62
62
|
end
|
63
63
|
end
|
64
64
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# downsub - github.com/johanlunds/downsub
|
2
|
+
require 'down_sub/movie_hasher'
|
3
|
+
|
4
|
+
module SubtitleIt
|
5
|
+
class Movie
|
6
|
+
EXTS = %w(3g2 3gp 3gp2 3gpp 60d ajp asf asx avchd avi bik bix box cam dat divx dmf dv dvr-ms evo flc fli flic flv flx gvi gvp h264 m1v m2p m2ts m2v m4e m4v mjp mjpeg mjpg mkv moov mov movhd movie movx mp4 mpe mpeg mpg mpv mpv2 mxf nsv nut ogg ogm omf ps qt ram rm rmvb swf ts vfw vid video viv vivo vob vro wm wmv wmx wrap wvx wx x264 xvid)
|
7
|
+
|
8
|
+
attr_reader :filename
|
9
|
+
attr_accessor :info
|
10
|
+
|
11
|
+
def initialize(filename)
|
12
|
+
@filename = filename
|
13
|
+
@hash = nil
|
14
|
+
@info = {}
|
15
|
+
end
|
16
|
+
|
17
|
+
def hash
|
18
|
+
@hash ||= MovieHasher::compute_hash(@filename)
|
19
|
+
end
|
20
|
+
|
21
|
+
def size
|
22
|
+
File.size(@filename)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# downsub - github.com/johanlunds/downsub
|
2
|
+
module SubtitleIt
|
3
|
+
module MovieHasher
|
4
|
+
|
5
|
+
CHUNK_SIZE = 64 * 1024 # in bytes
|
6
|
+
|
7
|
+
def self.compute_hash(filename)
|
8
|
+
filesize = File.size(filename)
|
9
|
+
hash = filesize
|
10
|
+
|
11
|
+
# Read 64 kbytes, divide up into 64 bits and add each
|
12
|
+
# to hash. Do for beginning and end of file.
|
13
|
+
File.open(filename, 'rb') do |f|
|
14
|
+
# Q = unsigned long long = 64 bit
|
15
|
+
f.read(CHUNK_SIZE).unpack("Q*").each do |n|
|
16
|
+
hash = hash + n & 0xffffffffffffffff # to remain as 64 bit number
|
17
|
+
end
|
18
|
+
|
19
|
+
f.seek([0, filesize - CHUNK_SIZE].max, IO::SEEK_SET)
|
20
|
+
|
21
|
+
# And again for the end of the file
|
22
|
+
f.read(CHUNK_SIZE).unpack("Q*").each do |n|
|
23
|
+
hash = hash + n & 0xffffffffffffffff
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
sprintf("%016x", hash)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/subtitle_it/subtime.rb
CHANGED
@@ -9,6 +9,9 @@ module SubtitleIt
|
|
9
9
|
parse_subtime(sym)
|
10
10
|
end
|
11
11
|
|
12
|
+
# parses string like '00:00:00,000'
|
13
|
+
# as well as an integer, representanting
|
14
|
+
# the time in ms.
|
12
15
|
def parse_subtime(sym)
|
13
16
|
if sym.kind_of?(Numeric)
|
14
17
|
@hrs = sym / 3600000
|
@@ -33,13 +36,15 @@ module SubtitleIt
|
|
33
36
|
raise "Wrong time format"
|
34
37
|
end
|
35
38
|
end
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
+
|
40
|
+
# to_s(separator) => to_s(",") => 00:00:00,000
|
41
|
+
def to_s(sep='.')
|
42
|
+
"%02d:%02d:%02d#{sep}%03d" % [@hrs, @min, @sec, @ms]
|
39
43
|
end
|
40
44
|
|
45
|
+
# return time as a total in ms
|
41
46
|
def to_i
|
42
|
-
|
47
|
+
( @hrs * 3600 + @min * 60 + @sec ) * 1000 + @ms
|
43
48
|
end
|
44
49
|
|
45
50
|
def +(other)
|
data/lib/subtitle_it/version.rb
CHANGED
data/lib/subtitle_it.rb
CHANGED
@@ -13,34 +13,4 @@ class Numeric
|
|
13
13
|
def reduce
|
14
14
|
self / ( 10 ** Math::log10(self).to_i)
|
15
15
|
end
|
16
|
-
end
|
17
|
-
|
18
|
-
class String
|
19
|
-
def to_msec
|
20
|
-
# convert string in time format to milli sec format
|
21
|
-
# "12:23:34,567" => "12*60*60*1000 + 23*60*1000 + 34 *1000 + 567"
|
22
|
-
time_list = self.split(/:/)
|
23
|
-
sec, msec = time_list.pop().split(/,|\./)
|
24
|
-
time_list.push(sec)
|
25
|
-
p time_list if $DEBUG
|
26
|
-
msecs = msec.to_i
|
27
|
-
time_list.reverse!
|
28
|
-
time_list.each_with_index { |x,i| msecs += x.to_i * 60**i * 1000 }
|
29
|
-
p msecs if $DEBUG
|
30
|
-
msecs#.to_s
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
class Fixnum
|
35
|
-
def to_time()
|
36
|
-
# convert millisec to standard time format
|
37
|
-
# 3600 * 1000 = ,000
|
38
|
-
time = self
|
39
|
-
msec = "%.3d" % (time % 1000)
|
40
|
-
time /= 1000
|
41
|
-
time_list = []
|
42
|
-
3.times { time_list.unshift( "%.2d"% (time%60) ) ; time /= 60 }
|
43
|
-
p time_list if $DEBUG
|
44
|
-
[ time_list.join(':'),msec ].join(',')
|
45
|
-
end
|
46
16
|
end
|
@@ -40,7 +40,21 @@ describe Formats, ".xml" do
|
|
40
40
|
end
|
41
41
|
|
42
42
|
it "should equal..." do
|
43
|
-
@sub.to_xml.should eql("<?xml version=\"1.0\" encoding=\"UTF-8\"
|
43
|
+
@sub.to_xml.should eql("<?xml version=\"1.0\" encoding=\"UTF-8\"?>
|
44
|
+
<tt xml:lang=\"en\" xmlns=\"http://www.w3.org/2006/04/ttaf1\" xmlns:tts=\"http://www.w3.org/2006/04/ttaf1#styling\">
|
45
|
+
<head>
|
46
|
+
<styling>
|
47
|
+
</styling>
|
48
|
+
</head>
|
49
|
+
<body>
|
50
|
+
<div xml:lang=\"en\">
|
51
|
+
<p begin=\"00:05:26.500\" dur=\"00:00:02.000\">worth killing for...</p>
|
52
|
+
<p begin=\"00:06:00.400\" dur=\"00:00:03.000\">worth dying for...</p>
|
53
|
+
<p begin=\"00:07:00.300\" dur=\"00:00:03.000\">worth going to the hell for...</p>
|
54
|
+
<p begin=\"00:07:00.300\" dur=\"00:00:03.000\">worth going a | line...</p>
|
55
|
+
</div>
|
56
|
+
</body>
|
57
|
+
</tt>")
|
44
58
|
end
|
45
59
|
end
|
46
60
|
end
|
data/subtitle_it.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = %q{subtitle_it}
|
3
|
-
s.version = "0.6.
|
3
|
+
s.version = "0.6.3"
|
4
4
|
|
5
5
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
6
6
|
s.authors = ["Marcos Piccinini", "Warlley Rezende"]
|
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.email = ["x@nofxx.com"]
|
11
11
|
s.executables = ["subtitle_it"]
|
12
12
|
s.extra_rdoc_files = ["History.txt", "License.txt", "Manifest.txt", "README.txt", "README.markdown"]
|
13
|
-
s.files = [".autotest", "History.txt", "License.txt", "Manifest.txt", "README.markdown", "README.txt", "Rakefile", "bin/subtitle_it", "config/hoe.rb", "config/requirements.rb", "lib/subtitle_it.rb", "lib/subtitle_it/formats/ass.rb", "lib/subtitle_it/formats/rsb.rb", "lib/subtitle_it/formats/srt.rb", "lib/subtitle_it/formats/sub.rb", "lib/subtitle_it/formats/xml.rb", "lib/subtitle_it/formats/yml.rb", "lib/subtitle_it/subline.rb", "lib/subtitle_it/subtime.rb", "lib/subtitle_it/subtitle.rb", "lib/subtitle_it/version.rb", "script/console", "script/destroy", "script/generate", "script/txt2html", "setup.rb", "spec/fixtures/godfather.srt", "spec/fixtures/huge.ass", "spec/fixtures/movie.xml", "spec/fixtures/movie.yml", "spec/fixtures/pseudo.rsb", "spec/fixtures/pulpfiction.sub", "spec/fixtures/sincity.yml", "spec/spec.opts", "spec/spec_helper.rb", "spec/subtitle_it/formats/ass_spec.rb", "spec/subtitle_it/formats/rsb_spec.rb", "spec/subtitle_it/formats/srt_spec.rb", "spec/subtitle_it/formats/sub_spec.rb", "spec/subtitle_it/formats/xml_spec.rb", "spec/subtitle_it/formats/yml_spec.rb", "spec/subtitle_it/subline_spec.rb", "spec/subtitle_it/subtime_spec.rb", "spec/subtitle_it/subtitle_spec.rb", "spec/subtitle_it_spec.rb", "subtitle_it.gemspec", "tasks/deployment.rake", "tasks/environment.rake", "tasks/rspec.rake"]
|
13
|
+
s.files = [".autotest", "History.txt", "License.txt", "Manifest.txt", "README.markdown", "README.txt", "Rakefile", "bin/subtitle_it", "blu.rsb", "blua.rsb", "config/hoe.rb", "config/requirements.rb", "lib/subtitle_it.rb", "lib/subtitle_it/formats/ass.rb", "lib/subtitle_it/formats/rsb.rb", "lib/subtitle_it/formats/srt.rb", "lib/subtitle_it/formats/sub.rb", "lib/subtitle_it/formats/xml.rb", "lib/subtitle_it/formats/yml.rb", "lib/subtitle_it/movie.rb", "lib/subtitle_it/movie_hasher.rb", "lib/subtitle_it/subline.rb", "lib/subtitle_it/subtime.rb", "lib/subtitle_it/subtitle.rb", "lib/subtitle_it/version.rb", "script/console", "script/destroy", "script/generate", "script/txt2html", "setup.rb", "spec/fixtures/godfather.srt", "spec/fixtures/huge.ass", "spec/fixtures/movie.xml", "spec/fixtures/movie.yml", "spec/fixtures/pseudo.rsb", "spec/fixtures/pulpfiction.sub", "spec/fixtures/sincity.yml", "spec/spec.opts", "spec/spec_helper.rb", "spec/subtitle_it/formats/ass_spec.rb", "spec/subtitle_it/formats/rsb_spec.rb", "spec/subtitle_it/formats/srt_spec.rb", "spec/subtitle_it/formats/sub_spec.rb", "spec/subtitle_it/formats/xml_spec.rb", "spec/subtitle_it/formats/yml_spec.rb", "spec/subtitle_it/subline_spec.rb", "spec/subtitle_it/subtime_spec.rb", "spec/subtitle_it/subtitle_spec.rb", "spec/subtitle_it_spec.rb", "subtitle_it.gemspec", "tasks/deployment.rake", "tasks/environment.rake", "tasks/rspec.rake"]
|
14
14
|
s.has_rdoc = true
|
15
15
|
s.homepage = %q{http://github.com/nofxx/subtitle_it}
|
16
16
|
s.post_install_message = %q{
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nofxx-subtitle_it
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marcos Piccinini
|
@@ -53,6 +53,8 @@ files:
|
|
53
53
|
- README.txt
|
54
54
|
- Rakefile
|
55
55
|
- bin/subtitle_it
|
56
|
+
- blu.rsb
|
57
|
+
- blua.rsb
|
56
58
|
- config/hoe.rb
|
57
59
|
- config/requirements.rb
|
58
60
|
- lib/subtitle_it.rb
|
@@ -62,6 +64,8 @@ files:
|
|
62
64
|
- lib/subtitle_it/formats/sub.rb
|
63
65
|
- lib/subtitle_it/formats/xml.rb
|
64
66
|
- lib/subtitle_it/formats/yml.rb
|
67
|
+
- lib/subtitle_it/movie.rb
|
68
|
+
- lib/subtitle_it/movie_hasher.rb
|
65
69
|
- lib/subtitle_it/subline.rb
|
66
70
|
- lib/subtitle_it/subtime.rb
|
67
71
|
- lib/subtitle_it/subtitle.rb
|