warlley-subtitle_it 0.6.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +19 -0
- data/History.txt +30 -0
- data/License.txt +20 -0
- data/Manifest.txt +53 -0
- data/README.markdown +41 -0
- data/README.txt +84 -0
- data/Rakefile +4 -0
- data/bin/subtitle_it +107 -0
- data/config/hoe.rb +73 -0
- data/config/requirements.rb +15 -0
- data/lib/subtitle_it/formats/ass.rb +14 -0
- data/lib/subtitle_it/formats/rsb.rb +33 -0
- data/lib/subtitle_it/formats/srt.rb +34 -0
- data/lib/subtitle_it/formats/sub.rb +31 -0
- data/lib/subtitle_it/formats/xml.rb +64 -0
- data/lib/subtitle_it/formats/yml.rb +20 -0
- data/lib/subtitle_it/movie.rb +25 -0
- data/lib/subtitle_it/movie_hasher.rb +30 -0
- data/lib/subtitle_it/subline.rb +25 -0
- data/lib/subtitle_it/subtime.rb +63 -0
- data/lib/subtitle_it/subtitle.rb +32 -0
- data/lib/subtitle_it/version.rb +9 -0
- data/lib/subtitle_it.rb +16 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +82 -0
- data/setup.rb +1585 -0
- data/spec/fixtures/godfather.srt +2487 -0
- data/spec/fixtures/huge.ass +22 -0
- data/spec/fixtures/movie.xml +28 -0
- data/spec/fixtures/movie.yml +163 -0
- data/spec/fixtures/pseudo.rsb +6 -0
- data/spec/fixtures/pulpfiction.sub +2025 -0
- data/spec/fixtures/sincity.yml +12 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +33 -0
- data/spec/subtitle_it/formats/ass_spec.rb +5 -0
- data/spec/subtitle_it/formats/rsb_spec.rb +42 -0
- data/spec/subtitle_it/formats/srt_spec.rb +42 -0
- data/spec/subtitle_it/formats/sub_spec.rb +46 -0
- data/spec/subtitle_it/formats/xml_spec.rb +60 -0
- data/spec/subtitle_it/formats/yml_spec.rb +20 -0
- data/spec/subtitle_it/subline_spec.rb +30 -0
- data/spec/subtitle_it/subtime_spec.rb +76 -0
- data/spec/subtitle_it/subtitle_spec.rb +1 -0
- data/spec/subtitle_it_spec.rb +11 -0
- data/subtitle_it.gemspec +41 -0
- data/tasks/deployment.rake +34 -0
- data/tasks/environment.rake +7 -0
- data/tasks/rspec.rake +21 -0
- metadata +132 -0
@@ -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
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# SubtitleIt
|
2
|
+
# Holds a subtitle`s line.
|
3
|
+
module SubtitleIt
|
4
|
+
class Subline
|
5
|
+
attr_accessor :text_on, :text_off, :text
|
6
|
+
# text_on/off may be:
|
7
|
+
# HH:MM:SS,MMM
|
8
|
+
# MM:SS
|
9
|
+
# S
|
10
|
+
# text lines should be separated by |
|
11
|
+
def initialize(text_on, text_off, text)
|
12
|
+
@text_on, @text_off = filter(text_on, text_off)
|
13
|
+
# ugly FIXME: when pseudo uses time => 3
|
14
|
+
# need to add seconds from the first sub
|
15
|
+
@text_off += @text_on if @text_off < @text_on
|
16
|
+
@text = text
|
17
|
+
end
|
18
|
+
|
19
|
+
def filter(*args)
|
20
|
+
args.map do |arg|
|
21
|
+
Subtime.new(arg)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# SubtitleIt
|
2
|
+
# Time class
|
3
|
+
module SubtitleIt
|
4
|
+
class Subtime
|
5
|
+
attr_accessor :hrs, :min, :sec, :ms
|
6
|
+
|
7
|
+
def initialize(sym)
|
8
|
+
@hrs = @min = @sec = @ms = 0
|
9
|
+
parse_subtime(sym)
|
10
|
+
end
|
11
|
+
|
12
|
+
# parses string like '00:00:00,000'
|
13
|
+
# as well as an integer, representanting
|
14
|
+
# the time in ms.
|
15
|
+
def parse_subtime(sym)
|
16
|
+
if sym.kind_of?(Numeric)
|
17
|
+
@hrs = sym / 3600000
|
18
|
+
@min = sym / 60000 % 600
|
19
|
+
@sec = sym / 1000 % 60
|
20
|
+
@ms = sym % 1000
|
21
|
+
return
|
22
|
+
end
|
23
|
+
v = sym.split(/\.|\,/)
|
24
|
+
if ms = v[1]
|
25
|
+
@ms = (("0.%d" % ms.to_i).to_f * 1000).to_i
|
26
|
+
end
|
27
|
+
v = v[0].split(/:/).map { |s| s.to_i }
|
28
|
+
case v.size
|
29
|
+
when 1
|
30
|
+
@sec = v.first
|
31
|
+
when 2
|
32
|
+
@min, @sec = v
|
33
|
+
when 3
|
34
|
+
@hrs, @min, @sec = v
|
35
|
+
else
|
36
|
+
raise "Wrong time format"
|
37
|
+
end
|
38
|
+
end
|
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]
|
43
|
+
end
|
44
|
+
|
45
|
+
# return time as a total in ms
|
46
|
+
def to_i
|
47
|
+
( @hrs * 3600 + @min * 60 + @sec ) * 1000 + @ms
|
48
|
+
end
|
49
|
+
|
50
|
+
def +(other)
|
51
|
+
Subtime.new(self.to_i + other.to_i)
|
52
|
+
end
|
53
|
+
|
54
|
+
def -(other)
|
55
|
+
Subtime.new(self.to_i - other.to_i)
|
56
|
+
end
|
57
|
+
|
58
|
+
def <=>(other)
|
59
|
+
self.to_i <=> other.to_i
|
60
|
+
end
|
61
|
+
include Comparable
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'subtitle_it/formats/srt'
|
2
|
+
require 'subtitle_it/formats/sub'
|
3
|
+
require 'subtitle_it/formats/yml'
|
4
|
+
require 'subtitle_it/formats/rsb'
|
5
|
+
require 'subtitle_it/formats/xml'
|
6
|
+
|
7
|
+
module SubtitleIt
|
8
|
+
include Formats
|
9
|
+
|
10
|
+
class Subtitle
|
11
|
+
attr_reader :raw, :format, :lines, :style
|
12
|
+
EXTS = %w(srt sub smi txt ssa ass mpl xml yml rsb)
|
13
|
+
|
14
|
+
def initialize(dump, format, style=nil, fps=23.976)
|
15
|
+
raise unless format =~ /^srt$|^sub|yml|txt|rsb|xml|ass/
|
16
|
+
@raw = dump.kind_of?(String) ? dump : dump.read
|
17
|
+
@format = format
|
18
|
+
@style = style
|
19
|
+
@fps = fps
|
20
|
+
parse!
|
21
|
+
end
|
22
|
+
|
23
|
+
def parse!
|
24
|
+
self.lines = send :"parse_#{@format}"
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
def lines=(lines)
|
29
|
+
@lines = lines
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/subtitle_it.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
require 'rubygems'
|
4
|
+
require 'subtitle_it/version'
|
5
|
+
require 'subtitle_it/subtime'
|
6
|
+
require 'subtitle_it/subline'
|
7
|
+
require 'subtitle_it/subtitle'
|
8
|
+
|
9
|
+
module SubtitleIt
|
10
|
+
end
|
11
|
+
|
12
|
+
class Numeric
|
13
|
+
def reduce
|
14
|
+
self / ( 10 ** Math::log10(self).to_i)
|
15
|
+
end
|
16
|
+
end
|
data/script/console
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# File: script/console
|
3
|
+
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
4
|
+
|
5
|
+
libs = " -r irb/completion"
|
6
|
+
# Perhaps use a console_lib to store any extra methods I may want available in the cosole
|
7
|
+
# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
|
8
|
+
libs << " -r #{File.dirname(__FILE__) + '/../lib/subtitle_it.rb'}"
|
9
|
+
puts "Loading subtitle_it gem"
|
10
|
+
exec "#{irb} #{libs} --simple-prompt"
|
data/script/destroy
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/destroy'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/generate'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Generate.new.run(ARGV)
|
data/script/txt2html
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
GEM_NAME = 'subtitle_it' # what ppl will type to install your gem
|
4
|
+
RUBYFORGE_PROJECT = 'subtitle_it'
|
5
|
+
|
6
|
+
require 'rubygems'
|
7
|
+
begin
|
8
|
+
require 'newgem'
|
9
|
+
require 'rubyforge'
|
10
|
+
rescue LoadError
|
11
|
+
puts "\n\nGenerating the website requires the newgem RubyGem"
|
12
|
+
puts "Install: gem install newgem\n\n"
|
13
|
+
exit(1)
|
14
|
+
end
|
15
|
+
require 'redcloth'
|
16
|
+
require 'syntax/convertors/html'
|
17
|
+
require 'erb'
|
18
|
+
require File.dirname(__FILE__) + "/../lib/#{GEM_NAME}/version.rb"
|
19
|
+
|
20
|
+
version = SubtitleIt::VERSION::STRING
|
21
|
+
download = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
|
22
|
+
|
23
|
+
def rubyforge_project_id
|
24
|
+
RubyForge.new.autoconfig["group_ids"][RUBYFORGE_PROJECT]
|
25
|
+
end
|
26
|
+
|
27
|
+
class Fixnum
|
28
|
+
def ordinal
|
29
|
+
# teens
|
30
|
+
return 'th' if (10..19).include?(self % 100)
|
31
|
+
# others
|
32
|
+
case self % 10
|
33
|
+
when 1: return 'st'
|
34
|
+
when 2: return 'nd'
|
35
|
+
when 3: return 'rd'
|
36
|
+
else return 'th'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class Time
|
42
|
+
def pretty
|
43
|
+
return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def convert_syntax(syntax, source)
|
48
|
+
return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
|
49
|
+
end
|
50
|
+
|
51
|
+
if ARGV.length >= 1
|
52
|
+
src, template = ARGV
|
53
|
+
template ||= File.join(File.dirname(__FILE__), '/../website/template.html.erb')
|
54
|
+
else
|
55
|
+
puts("Usage: #{File.split($0).last} source.txt [template.html.erb] > output.html")
|
56
|
+
exit!
|
57
|
+
end
|
58
|
+
|
59
|
+
template = ERB.new(File.open(template).read)
|
60
|
+
|
61
|
+
title = nil
|
62
|
+
body = nil
|
63
|
+
File.open(src) do |fsrc|
|
64
|
+
title_text = fsrc.readline
|
65
|
+
body_text_template = fsrc.read
|
66
|
+
body_text = ERB.new(body_text_template).result(binding)
|
67
|
+
syntax_items = []
|
68
|
+
body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</\1>!m){
|
69
|
+
ident = syntax_items.length
|
70
|
+
element, syntax, source = $1, $2, $3
|
71
|
+
syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
|
72
|
+
"syntax-temp-#{ident}"
|
73
|
+
}
|
74
|
+
title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
|
75
|
+
body = RedCloth.new(body_text).to_html
|
76
|
+
body.gsub!(%r!(?:<pre><code>)?syntax-temp-(\d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
|
77
|
+
end
|
78
|
+
stat = File.stat(src)
|
79
|
+
created = stat.ctime
|
80
|
+
modified = stat.mtime
|
81
|
+
|
82
|
+
$stdout << template.result(binding)
|