subtitle 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/scc.rb +77 -0
  3. metadata +5 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e0908e0ca690672bf633eb1c212c5470aa7316f0e46fb5e224f60e1d17e3b6ee
4
- data.tar.gz: 47aebdc5c91dd5ef4a93f3699f3c62042dbaeed01fb31b7ec23c386cc8dfe5ef
3
+ metadata.gz: aba6a9f70a40bf96fd797a6a68816ca2e3070f93573d26dbbb1df4b12a47d691
4
+ data.tar.gz: 1f61c3bb5a4ec42ca6fe694c9e1bac4d805d21d7f057b6f45a4c51ac0671e287
5
5
  SHA512:
6
- metadata.gz: 45fa0b25384d0547ae54bd84f3acd9cfb06d393616e23aea3a986532a141d94ab9f65c3d215b7688c5e964537fd632d5acca949f53e1ec91634ee9f70d9ca61e
7
- data.tar.gz: 155b11f1511aeb00d91ba59ea78cf8a432a603ae0f90bcf624828f227eb8abd92e8f162da3b0aae0b5334e75b83d1a18e8bbea71a1abf051866815b7c99f1cdb
6
+ metadata.gz: e996202bdd3ee2c8860b51aa6c5e414b9eea4735355c5b8f9d58f90ce67105fb1fafd781ae3e7375215ae8d364c9dfd0caa6dc3d73fd9f0257bb2748b945badc
7
+ data.tar.gz: 5bfdf76e39dfc65a4ef5e5e288b74aa3e098fe358c402214300710b7b614d8c444053ed7dcdc3e012327d6c7b33d6d91db8701e06c39d6232dfdde42197d3e17
data/lib/scc.rb ADDED
@@ -0,0 +1,77 @@
1
+ require 'aws-sdk-translate'
2
+ require 'aws-sdk-comprehend'
3
+
4
+ class SCC
5
+
6
+ def initialize(awskey, awssecret)
7
+ @translate = Aws::Translate::Client.new(:access_key_id => "#{awskey}", :secret_access_key => "#{awssecret}")
8
+ @comp = Aws::Comprehend::Client.new(:access_key_id => "#{awskey}", :secret_access_key => "#{awssecret}")
9
+ end
10
+
11
+ def get_text(srt_file, num_chars)
12
+ ccfile = File.open(srt_file, 'r:UTF-8', &:read)
13
+ text_sample = ""
14
+ ccfile.each_line do | line |
15
+ if line =~ /^\d\d:\d\d:\d\d:\d\d\s/
16
+ scc_text_code = line.gsub(/^\d\d:\d\d:\d\d:\d\d\s/, '')
17
+ text_sample << decode(scc_text_code)
18
+ if text_sample.length > (num_chars+1)
19
+ break
20
+ end
21
+ end
22
+ end
23
+ return text_sample[0,num_chars]
24
+ end
25
+
26
+ def decode(scc_code_text)
27
+ hex_codes = scc_code_text.gsub(/\s/,'').scan(/.{2}/)
28
+ decoded_text = ""
29
+ skip_next = false
30
+ skip_count = 0
31
+ hex_codes.each do | code |
32
+ if ["94", "91", "92", "97", "15", "16", "10", "13"].include?(code)
33
+ skip_next = true
34
+ skip_count = skip_count +1
35
+ next
36
+ end
37
+ if skip_count == 1 && skip_next
38
+ skip_next = false
39
+ skip_count = 0
40
+ next
41
+ end
42
+ dec_val = code.to_i(16) & 0x7F
43
+ decoded_text << dec_val.chr
44
+ end
45
+ decoded_text
46
+ end
47
+
48
+ def encode(free_text)
49
+ encoded_str = ""
50
+ count = 0
51
+ free_text.each_byte do |char|
52
+ count += 1
53
+ binval = char.to_s(2).count("1") % 2 == 0 ? (char.to_i | 128 ).to_s(2) : char.to_s(2)
54
+ encode_char = binval.to_i(2).to_s(16)
55
+ if ((count > 0) && (count % 2 == 0))
56
+ encoded_str << encode_char << " "
57
+ else
58
+ encoded_str << encode_char
59
+ end
60
+ end
61
+ encoded_str
62
+ end
63
+
64
+ def detect_lang(scc_file)
65
+ lang = nil
66
+ begin
67
+ sample_text = get_text(scc_file, 100)
68
+ response = @comp.detect_dominant_language( {
69
+ text: "#{sample_text}"
70
+ })
71
+ lang = response[:languages][0][:language_code] rescue nil
72
+ rescue => error
73
+ puts "Error while detecting the language!!"
74
+ end
75
+ lang
76
+ end
77
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: subtitle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maheshwaran G
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-17 00:00:00.000000000 Z
11
+ date: 2019-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -59,6 +59,7 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
+ - lib/scc.rb
62
63
  - lib/srt.rb
63
64
  - lib/subtitle.rb
64
65
  - lib/vtt.rb
@@ -87,5 +88,6 @@ rubyforge_project:
87
88
  rubygems_version: 2.7.3
88
89
  signing_key:
89
90
  specification_version: 4
90
- summary: subtitle gem to detect and translate closed caption
91
+ summary: subtitle helps you to detect language and translate closed caption to required
92
+ language
91
93
  test_files: []