rsubtitle 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -0
- data/lib/rsubtitle/smi.rb +49 -0
- data/lib/rsubtitle/version.rb +5 -0
- data/lib/rsubtitle.rb +5 -0
- metadata +70 -0
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
module Rsubtitle
|
2
|
+
|
3
|
+
class SMI
|
4
|
+
|
5
|
+
SMI_RE = %r(
|
6
|
+
^<sync\sstart=(\d+)> <p[^>]+> (?:\r?\n)? ( \ (?=\r?\n) | (?<=\n).+?(?=\r?\n) )
|
7
|
+
)xim
|
8
|
+
|
9
|
+
|
10
|
+
class << self
|
11
|
+
|
12
|
+
def parse(file)
|
13
|
+
SMI.new(file)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(file)
|
19
|
+
@body = open(file).read
|
20
|
+
lines = @body.scan(SMI_RE)
|
21
|
+
|
22
|
+
@entries = []
|
23
|
+
lines.each_with_index do |d, idx|
|
24
|
+
next if d[1] == " "
|
25
|
+
|
26
|
+
start = d[0].to_i
|
27
|
+
duration = (lines[idx+1].nil?) ? 0 : (lines[idx+1][0].to_i - start)
|
28
|
+
|
29
|
+
sub = d[1]
|
30
|
+
sub.gsub!(/<br\s*\/?>/i, "\n") # br -> \n
|
31
|
+
sub.gsub!(/<[^>]+?>/i, "") # strip tags
|
32
|
+
sub.strip!
|
33
|
+
|
34
|
+
@entries << {:start => start, :subtitle => sub, :duration => duration}
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
def size
|
40
|
+
@entries.size
|
41
|
+
end
|
42
|
+
|
43
|
+
def [](idx)
|
44
|
+
@entries[idx]
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
data/lib/rsubtitle.rb
ADDED
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rsubtitle
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Eunsub Kim
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-01-08 00:00:00 +09:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: Ruby video subtitle parser and formatter
|
22
|
+
email:
|
23
|
+
- eunsub@gmail.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
30
|
+
files:
|
31
|
+
- lib/rsubtitle/smi.rb
|
32
|
+
- lib/rsubtitle/version.rb
|
33
|
+
- lib/rsubtitle.rb
|
34
|
+
- README.md
|
35
|
+
has_rdoc: true
|
36
|
+
homepage: http://github.com/eskim/rsubtitle
|
37
|
+
licenses: []
|
38
|
+
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
segments:
|
50
|
+
- 0
|
51
|
+
version: "0"
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
segments:
|
58
|
+
- 1
|
59
|
+
- 3
|
60
|
+
- 6
|
61
|
+
version: 1.3.6
|
62
|
+
requirements: []
|
63
|
+
|
64
|
+
rubyforge_project: rsubtitle
|
65
|
+
rubygems_version: 1.3.7
|
66
|
+
signing_key:
|
67
|
+
specification_version: 3
|
68
|
+
summary: Ruby video subtitle parser and formatter
|
69
|
+
test_files: []
|
70
|
+
|