srt_parser 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/srt_parser.rb +40 -0
- metadata +64 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c5442cc1533eb2e3bdc56fd6728cb3ef514307d6
|
4
|
+
data.tar.gz: c2f9a0b3f192a13bc688375616f11818e77d97f8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0a295c6eb4d054df31522c9229527d3d001c05a3e586c1658634be1d04ad3598b77bc8db7fcbe58e2bc8410e599c09197e139084659a8fc048440bfbac9b6b17
|
7
|
+
data.tar.gz: 042d4ac91ee9b5a816d68e5930e9f64257ceef44f726f8cd97e6a611123e3f936f4e1387827e46bb8f1ed6b7b82cba5901638330e7beed166656cfa882577b33
|
data/lib/srt_parser.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'srt'
|
2
|
+
require 'srt_parser'
|
3
|
+
|
4
|
+
module SRTParser
|
5
|
+
class Parser
|
6
|
+
def self.parse(file, duration)
|
7
|
+
srt_file = SRT::File.parse(file)
|
8
|
+
# An array of contiguous blocks of subtitled times.
|
9
|
+
times = []
|
10
|
+
|
11
|
+
srt_file.lines.each do |line|
|
12
|
+
if times.last and line.start_time <= times.last[1]
|
13
|
+
if line.end_time > times.last[1]
|
14
|
+
times.last[1] = line.end_time
|
15
|
+
end
|
16
|
+
else
|
17
|
+
times.push([ line.start_time, line.end_time ])
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
Subtitle.new(duration, times)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class Subtitle
|
26
|
+
def initialize(duration, intervals)
|
27
|
+
@duration = duration
|
28
|
+
@intervals = intervals
|
29
|
+
end
|
30
|
+
|
31
|
+
def coverage
|
32
|
+
covered = 0
|
33
|
+
@intervals.each do |interval|
|
34
|
+
covered += interval[1] - interval[0]
|
35
|
+
end
|
36
|
+
|
37
|
+
covered / @duration
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: srt_parser
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Darren Zhao
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: srt
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.1'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.1.2
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.1'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.1.2
|
33
|
+
description: A simple gem to parse how much of a video an SRT file covers.
|
34
|
+
email: darryqueen@berkeley.edu
|
35
|
+
executables: []
|
36
|
+
extensions: []
|
37
|
+
extra_rdoc_files: []
|
38
|
+
files:
|
39
|
+
- lib/srt_parser.rb
|
40
|
+
homepage: http://rubygems.org/gems/srt_parser
|
41
|
+
licenses:
|
42
|
+
- MIT
|
43
|
+
metadata: {}
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
requirements: []
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 2.2.2
|
61
|
+
signing_key:
|
62
|
+
specification_version: 4
|
63
|
+
summary: SRT cover parser.
|
64
|
+
test_files: []
|