deepl-srt 0.1.3 → 0.1.4
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 +4 -4
- data/CHANGELOG.md +2 -1
- data/Gemfile.lock +1 -1
- data/deepl-srt.gemspec +1 -1
- data/examples/{example.srt → example.input.srt} +0 -0
- data/examples/example.output.tmp +15 -0
- data/exe/deepl_srt +22 -0
- data/lib/deepl_srt.rb +3 -4
- data/lib/deepl_srt/deepl_request.rb +1 -1
- data/lib/deepl_srt/srt_translate.rb +16 -8
- data/lib/deepl_srt/version.rb +1 -1
- metadata +6 -5
- data/exe/deepl_srt.rb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 041c6c0d7cc8a119bca0fca2c85773c1c33bf585c8be7abd44bd90dbfa682392
|
4
|
+
data.tar.gz: 3d54618cf8d7e56d93c4ad19680c13942365609917b5334a87eb5c91392c2f8f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce490c98abfd551bb2d1f39cd0fb6d46d38674f34d5d26de298834737db2ea6c9960671982a0b98a1ea70e0c3057085faf920661caea0de9809f473dec6e0abf
|
7
|
+
data.tar.gz: a3d699287177dd5ed8127953e0b9f745efa8d262dc756071067cc6941ff983d57ea243e9f5b3663fb60beb6a4eb3c5126d026fb74e51fb7956c04f5b398a7fee
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/deepl-srt.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.email = ['lukasz@fuszara.pl']
|
10
10
|
|
11
11
|
spec.summary = 'Subtitles translator with DeepL engine'
|
12
|
-
spec.description = 'deepl_srt [api_key] [target_lang] [
|
12
|
+
spec.description = 'deepl_srt [api_key] [target_lang] [input_path] [result_path] [form_line]'
|
13
13
|
spec.homepage = 'https://github.com/lfuszara1/srt-deepl'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
spec.required_ruby_version = Gem::Requirement.new('>= 2.4.0')
|
File without changes
|
@@ -0,0 +1,15 @@
|
|
1
|
+
1
|
2
|
+
00:00:00,498 --> 00:00:02,827
|
3
|
+
- Oto, co najbardziej lubię w
|
4
|
+
jedzeniu i diecie.
|
5
|
+
|
6
|
+
2
|
7
|
+
00:00:02,827 --> 00:00:06,383
|
8
|
+
Wszyscy jemy kilka razy dziennie i
|
9
|
+
jesteśmy całkowicie odpowiedzialni za to
|
10
|
+
|
11
|
+
3
|
12
|
+
00:00:06,383 --> 00:00:09,427
|
13
|
+
co trafia na nasz talerz, a
|
14
|
+
co z niego schodzi.
|
15
|
+
|
data/exe/deepl_srt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'deepl_srt'
|
5
|
+
|
6
|
+
input_params = ARGV
|
7
|
+
|
8
|
+
if input_params.empty?
|
9
|
+
puts 'deepl_srt [api_key] [target_lang] [input_path] [result_path] [form_line]'
|
10
|
+
else
|
11
|
+
api_key = input_params[0]
|
12
|
+
target_lang = input_params[1]
|
13
|
+
input_path = input_params[2]
|
14
|
+
result_path = input_params[3]
|
15
|
+
if input_params[4].nil?
|
16
|
+
from_line = 0
|
17
|
+
else
|
18
|
+
from_line = input_params[4]
|
19
|
+
end
|
20
|
+
|
21
|
+
DeeplSrt.deepl_srt(api_key, target_lang, input_path, result_path, from_line)
|
22
|
+
end
|
data/lib/deepl_srt.rb
CHANGED
@@ -7,9 +7,8 @@ require_relative './deepl_srt/srt_translate'
|
|
7
7
|
module DeeplSrt
|
8
8
|
class Error < StandardError; end
|
9
9
|
|
10
|
-
def self.deepl_srt(api_key,
|
11
|
-
srt_translate = SrtTranslate.new(api_key,
|
12
|
-
|
13
|
-
File.open(result_path, 'w') { |file| file.write(result) }
|
10
|
+
def self.deepl_srt(api_key, target_lang, input_path, result_path, from_line)
|
11
|
+
srt_translate = SrtTranslate.new(api_key, target_lang, input_path, result_path)
|
12
|
+
srt_translate.parse(from_line)
|
14
13
|
end
|
15
14
|
end
|
@@ -1,21 +1,25 @@
|
|
1
1
|
# frozen_string_literal: false
|
2
2
|
|
3
|
+
require 'fileutils'
|
3
4
|
require 'json'
|
4
5
|
require 'srt'
|
5
6
|
require_relative './deepl_request'
|
6
7
|
|
7
8
|
# Class to translate subtitles
|
8
9
|
class SrtTranslate
|
9
|
-
def initialize(api_key,
|
10
|
-
@file = SRT::File.parse(File.new(
|
10
|
+
def initialize(api_key, target_lang, input_path, result_path)
|
11
|
+
@file = SRT::File.parse(File.new(input_path))
|
11
12
|
@deepl_request = DeeplRequest.new(api_key)
|
12
13
|
@target_lang = target_lang
|
14
|
+
FileUtils.rm(result_path) if File.exist?(result_path)
|
15
|
+
FileUtils.touch(result_path)
|
16
|
+
@result_path = result_path
|
13
17
|
end
|
14
18
|
|
15
|
-
def parse
|
19
|
+
def parse(from_line)
|
16
20
|
@new_content = ''
|
17
|
-
@file.lines.each_with_index do |line, index|
|
18
|
-
@new_content << parse_part(line, index)
|
21
|
+
@file.lines.drop(from_line.to_i).each_with_index do |line, index|
|
22
|
+
@new_content << parse_part(line, index + from_line.to_i)
|
19
23
|
end
|
20
24
|
@new_content
|
21
25
|
end
|
@@ -24,20 +28,24 @@ class SrtTranslate
|
|
24
28
|
|
25
29
|
def parse_part(line, index)
|
26
30
|
str = ''
|
27
|
-
str << "#{index}\n"
|
31
|
+
str << "#{index + 1}\n"
|
28
32
|
str << "#{line.time_str}\n"
|
29
33
|
json = translate(line.text.join('\n'))
|
30
34
|
result = shorter(JSON.parse(json)['translations'][0]['text'])
|
31
35
|
str << "#{result}\n\n"
|
32
|
-
str
|
36
|
+
save_line(str)
|
33
37
|
end
|
34
38
|
|
35
39
|
def translate(text)
|
36
|
-
@deepl_request.request(
|
40
|
+
@deepl_request.request(@target_lang, text).body
|
37
41
|
end
|
38
42
|
|
39
43
|
def shorter(line)
|
40
44
|
short = line.split.each_slice(6).map { |a| a.join ' ' }
|
41
45
|
short.join("\n")
|
42
46
|
end
|
47
|
+
|
48
|
+
def save_line(line)
|
49
|
+
File.open(@result_path, 'a+') { |file| file.write(line) }
|
50
|
+
end
|
43
51
|
end
|
data/lib/deepl_srt/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deepl-srt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Łukasz Fuszara
|
@@ -10,11 +10,11 @@ bindir: exe
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2021-05-28 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description: deepl_srt [api_key] [target_lang] [
|
13
|
+
description: deepl_srt [api_key] [target_lang] [input_path] [result_path] [form_line]
|
14
14
|
email:
|
15
15
|
- lukasz@fuszara.pl
|
16
16
|
executables:
|
17
|
-
- deepl_srt
|
17
|
+
- deepl_srt
|
18
18
|
extensions: []
|
19
19
|
extra_rdoc_files: []
|
20
20
|
files:
|
@@ -32,8 +32,9 @@ files:
|
|
32
32
|
- bin/console
|
33
33
|
- bin/setup
|
34
34
|
- deepl-srt.gemspec
|
35
|
-
- examples/example.srt
|
36
|
-
-
|
35
|
+
- examples/example.input.srt
|
36
|
+
- examples/example.output.tmp
|
37
|
+
- exe/deepl_srt
|
37
38
|
- lib/deepl_srt.rb
|
38
39
|
- lib/deepl_srt/deepl_request.rb
|
39
40
|
- lib/deepl_srt/srt_translate.rb
|
data/exe/deepl_srt.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
require 'deepl_srt'
|
5
|
-
|
6
|
-
input_params = ARGV
|
7
|
-
|
8
|
-
if input_params.empty?
|
9
|
-
puts 'deepl_srt [api_key] [target_lang] [input path] [result_path]'
|
10
|
-
else
|
11
|
-
api_key = input_params[0]
|
12
|
-
target_lang = input_params[1]
|
13
|
-
path = input_params[2]
|
14
|
-
result_path = input_params[3]
|
15
|
-
|
16
|
-
DeeplSrt.deepl_srt(api_key, path, target_lang, result_path)
|
17
|
-
end
|