subtitle 0.2.5 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/subtitle.rb +28 -0
  3. data/lib/vtt.rb +2 -2
  4. metadata +4 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5c9fde23f9d4f30c168b454b3f9d32de58e44dbcd5ff371d501db7f1ef1c4a52
4
- data.tar.gz: 3aa9a15df33803178103cca45dad2fee31c43de74313e4bf3e4cf114ec59dc11
3
+ metadata.gz: 99d9960e9d5fb5daa7ddc87e76db91c654ce68453a13fd9124611e7589cc7fe5
4
+ data.tar.gz: '090e594747871afd7e3e423dab00154313d5b77423664a300f499df07dd895c0'
5
5
  SHA512:
6
- metadata.gz: 8d3367daf891ffdaacfa63747db38f3e8386f2c57b96bd80d72805a735bfb6d69dc11a6770cb4fd82e2b5933cd934dfe716e2a5c0eeee274e50ef437fbaa242e
7
- data.tar.gz: 1b5a20c5ae3c0bec2fe974d79c49075a906d0b75e8ab8eb3321daa539d5ee81ed3616cb8ecad5c1314cbd526ef112cd8e20fe4ca91ced3ba7288bdd6037b7b8d
6
+ metadata.gz: 1545c3120f496fe10228473f45f5bb3a78135fd603d15eed6eee7a2aa85fc281f53f4fc5f612c3ab4d710baa9388abd6528c8f5aff52f3fb3bfe424e61c05e2c
7
+ data.tar.gz: 38fc75d66ea829a7596d5a7235fd6d7f43d256a3dbb1b8ae136926b92ca83b7cbf041c290cf4e506e032d987e73b9a56761cfb89596d6131aafc5d5f87453732
data/lib/subtitle.rb CHANGED
@@ -33,6 +33,34 @@ class Subtitle
33
33
  outfile
34
34
  end
35
35
 
36
+ def type
37
+ type = nil
38
+ ccfile = File.open(@cc_file, 'r:UTF-8', &:read)
39
+ ccfile.each_line do | line |
40
+ if line =~ /^(\d\d:)\d\d:\d\d[,]\d\d\d.*-->.*(\d\d:)\d\d:\d\d[,]\d\d\d/
41
+ type = "srt"
42
+ elsif line =~ /(^(\d\d:)\d\d:\d\d[.]\d\d\d.*-->.*(\d\d:)\d\d:\d\d[.]\d\d\d)|(^WEBVTT$)/
43
+ type = "vtt"
44
+ elsif line =~ /(^\d\d:\d\d:\d\d:\d\d\t(([0-9a-fA-F]{4})\s)*)+|(^Scenarist_SCC V(\d.\d)$)/
45
+ type = "scc"
46
+ end
47
+ end
48
+ unless type
49
+ doc = File.open(@cc_file) { |f| Nokogiri::XML(f) }
50
+ namespace = doc.namespaces["xmlns"]
51
+ if doc.errors.empty?
52
+ if doc.xpath('/*').first.name == 'tt' && !doc.css('/tt/head').nil? && !doc.css('/tt/body').nil?
53
+ if namespace =~ /\/ttaf1/
54
+ type = "dfxp"
55
+ elsif namespace =~ /\/ttml/
56
+ type = "ttml"
57
+ end
58
+ end
59
+ end
60
+ end
61
+ type
62
+ end
63
+
36
64
  private
37
65
 
38
66
  def get_translator(options)
data/lib/vtt.rb CHANGED
@@ -25,7 +25,7 @@ class VTT
25
25
  text_collection = false
26
26
  text_sample = ""
27
27
  ccfile.each_line do | line |
28
- if line =~ /^[\d\d:]?\d\d:\d\d[,.]\d\d\d.*-->.*[\d\d:]?\d\d:\d\d[,.]\d\d\d/
28
+ if line =~ /^((\d\d:)+\d\d[.,]\d\d\d)\s-->\s((\d\d:)+\d\d[.,]\d\d\d)/
29
29
  text_collection = true
30
30
  outfile.puts line
31
31
  elsif line.strip.empty? && !text_sample.empty?
@@ -98,7 +98,7 @@ class VTT
98
98
  text_collection = false
99
99
  text_sample = ""
100
100
  ccfile.each_line do |line|
101
- if line =~ /^[\d\d:]?\d\d:\d\d[,.]\d\d\d.*-->.*[\d\d:]?\d\d:\d\d[,.]\d\d\d/
101
+ if line =~ /^((\d\d:)+\d\d[.,]\d\d\d)\s-->\s((\d\d:)+\d\d[.,]\d\d\d)/
102
102
  text_collection = true
103
103
  elsif line.strip.empty?
104
104
  text_collection = false
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: subtitle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maheshwaran G
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-11-07 00:00:00.000000000 Z
12
+ date: 2019-11-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -107,7 +107,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
107
  - !ruby/object:Gem::Version
108
108
  version: '0'
109
109
  requirements: []
110
- rubygems_version: 3.0.3
110
+ rubyforge_project:
111
+ rubygems_version: 2.7.3
111
112
  signing_key:
112
113
  specification_version: 4
113
114
  summary: Subtitle gem helps you to detect language and translate closed caption to