google-translate-tts 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: acccb4852f21633d76dc1c7ec296dd4c22dc230593fb32dd42a582e318e38419
4
- data.tar.gz: 2ad2550f7f3356d4c2a148cdea981b4d20c357755fe7867c4ab4c2632404bb63
3
+ metadata.gz: 5c781e0a3c33b2142ce4ee2db0bd5b1230bf6532d583f2114872aaf2f08d1ec3
4
+ data.tar.gz: 5b68e757794b9627b79c36fea66f5aefa05bbe37cb46b43b56152cdaeddf4118
5
5
  SHA512:
6
- metadata.gz: 3d8a71bf2308a8be2b117f44a3c58c07009291c945b67f9d2af2144a621c290125e27f61ee2389419d32261df0398d21350e518263d18452999fa1d3f98eec72
7
- data.tar.gz: 5ae06fb097b3a892fd655b8b383ae6bbf522e8a0676223630451f7d7082c1f483b202228df1cca762714414be7abd7179e86d87d1afb3bcab640772ef1510124
6
+ metadata.gz: ae6167c7cb6bf4e4b785769e68d391cc123a12fd8e93648567fca12ff90efb37a434a6ed760c647345c5972f2d3b7d0bd74947f9f04f9ec4184ee2050d9d96c4
7
+ data.tar.gz: 9dbc15c51cabc23fb0d488f35abfffcdb51b686efe3643760ed8abbd954eefce43bc3f4c29ce28b5238ba7fa8348a4ece59eb3db6fb375487d040b800bff9747
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/Gemfile CHANGED
@@ -2,13 +2,11 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- # Specify your gem's dependencies in google-translate-tts.gemspec
6
5
  gemspec
7
6
 
8
7
  gem "rake", "~> 13.0"
9
8
 
10
- gem "minitest", "~> 5.0"
11
-
12
- gem "rubocop", "~> 1.21"
13
-
14
- gem "byebug"
9
+ group :development, :test do
10
+ gem "byebug"
11
+ gem "rspec", "~> 3.11"
12
+ end
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- google-translate-tts (0.1.0)
4
+ google-translate-tts (0.2.0)
5
5
  faraday
6
6
 
7
7
  GEM
@@ -9,11 +9,11 @@ GEM
9
9
  specs:
10
10
  ast (2.4.2)
11
11
  byebug (11.1.3)
12
+ diff-lcs (1.5.0)
12
13
  faraday (2.3.0)
13
14
  faraday-net_http (~> 2.0)
14
15
  ruby2_keywords (>= 0.0.4)
15
- faraday-net_http (2.0.2)
16
- minitest (5.16.0)
16
+ faraday-net_http (2.0.3)
17
17
  parallel (1.22.1)
18
18
  parser (3.1.2.0)
19
19
  ast (~> 2.4.1)
@@ -21,6 +21,19 @@ GEM
21
21
  rake (13.0.6)
22
22
  regexp_parser (2.5.0)
23
23
  rexml (3.2.5)
24
+ rspec (3.11.0)
25
+ rspec-core (~> 3.11.0)
26
+ rspec-expectations (~> 3.11.0)
27
+ rspec-mocks (~> 3.11.0)
28
+ rspec-core (3.11.0)
29
+ rspec-support (~> 3.11.0)
30
+ rspec-expectations (3.11.1)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.11.0)
33
+ rspec-mocks (3.11.1)
34
+ diff-lcs (>= 1.2.0, < 2.0)
35
+ rspec-support (~> 3.11.0)
36
+ rspec-support (3.11.1)
24
37
  rubocop (1.30.1)
25
38
  parallel (~> 1.10)
26
39
  parser (>= 3.1.0.0)
@@ -32,6 +45,8 @@ GEM
32
45
  unicode-display_width (>= 1.4.0, < 3.0)
33
46
  rubocop-ast (1.18.0)
34
47
  parser (>= 3.1.1.0)
48
+ rubocop-rspec (2.11.1)
49
+ rubocop (~> 1.19)
35
50
  ruby-progressbar (1.11.0)
36
51
  ruby2_keywords (0.0.5)
37
52
  unicode-display_width (2.1.0)
@@ -42,9 +57,10 @@ PLATFORMS
42
57
  DEPENDENCIES
43
58
  byebug
44
59
  google-translate-tts!
45
- minitest (~> 5.0)
46
60
  rake (~> 13.0)
61
+ rspec (~> 3.11)
47
62
  rubocop (~> 1.21)
63
+ rubocop-rspec (~> 2.11)
48
64
 
49
65
  BUNDLED WITH
50
66
  2.3.12
data/Rakefile CHANGED
@@ -1,16 +1,21 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "bundler/gem_tasks"
4
- require "rake/testtask"
5
4
 
6
- Rake::TestTask.new(:test) do |t|
7
- t.libs << "test"
8
- t.libs << "lib"
9
- t.test_files = FileList["test/**/test_*.rb"]
5
+ # rspec
6
+ begin
7
+ require "rspec/core/rake_task"
8
+ RSpec::Core::RakeTask.new(:spec)
9
+ rescue LoadError
10
+ warn "Need to install rspec: $ gem install rspec"
10
11
  end
11
12
 
12
- require "rubocop/rake_task"
13
-
14
- RuboCop::RakeTask.new
13
+ # rubocop
14
+ begin
15
+ require "rubocop/rake_task"
16
+ RuboCop::RakeTask.new
17
+ rescue LoadError
18
+ warn "Need to install rubocop: $ gem install rubocop rubocop-rspec"
19
+ end
15
20
 
16
- task default: %i[test rubocop]
21
+ task default: %i[spec rubocop]
@@ -27,6 +27,6 @@ Gem::Specification.new do |spec|
27
27
 
28
28
  spec.add_dependency "faraday"
29
29
 
30
- # For more information and examples about making a new gem, check out our
31
- # guide at: https://bundler.io/guides/creating_gem.html
30
+ spec.add_development_dependency "rubocop", "~> 1.21"
31
+ spec.add_development_dependency "rubocop-rspec", "~> 2.11"
32
32
  end
@@ -1,9 +1,20 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GoogleTranslateTts
2
4
  module Constanting
3
- BASE_URL = ENV.fetch("TTS_BASE_URL", "http://translate.google.com")
5
+ BASE_URL =
6
+ ENV.fetch("TTS_BASE_URL", "http://translate.google.com")
7
+
8
+ TTS_TMP_DIR =
9
+ ENV.fetch("TTS_TMP_DIR", File.expand_path("~/.tmp/tts_tmp", __dir__))
10
+
4
11
  REFERER = BASE_URL
5
- USER_AGENT = ENV.fetch("TTS_UA", "Mozilla/5.0 (X11; CrOS x86_64 14767.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.9999.0 Safari/537.36")
6
12
 
7
- TTS_TMP_DIR = ENV.fetch('TTS_TMP_DIR', File.expand_path('~/.tmp/tts_tmp', __FILE__))
13
+ USER_AGENT =
14
+ ENV
15
+ .fetch(
16
+ "TTS_UA",
17
+ "Mozilla/5.0 (X11; CrOS x86_64 14767.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.9999.0 Safari/537.36"
18
+ )
8
19
  end
9
20
  end
@@ -1,3 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "tempfile"
4
+ require "securerandom"
5
+
1
6
  module GoogleTranslateTts
2
7
  module Fileable
3
8
  def self.included(base)
@@ -14,7 +19,7 @@ module GoogleTranslateTts
14
19
  end
15
20
 
16
21
  def setup_temp_dir!
17
- FileUtils.mkdir_p(self::TTS_TMP_DIR) unless Dir.exists? self::TTS_TMP_DIR
22
+ FileUtils.mkdir_p(self::TTS_TMP_DIR) unless Dir.exist? self::TTS_TMP_DIR
18
23
  end
19
24
  end
20
25
  end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "cgi"
4
+ require "fileutils"
5
+
6
+ module GoogleTranslateTts
7
+ module Utils
8
+ def self.included(base)
9
+ base.extend(ClassMethods)
10
+ end
11
+
12
+ module ClassMethods
13
+ protected
14
+
15
+ def copy_file(source, destination)
16
+ FileUtils.cp(source, destination)
17
+ end
18
+
19
+ def url_encode(value)
20
+ CGI.escape(value)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GoogleTranslateTts
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
@@ -1,50 +1,50 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "cgi"
4
3
  require "faraday"
5
- require "fileutils"
6
- require "securerandom"
7
- require "tempfile"
8
4
 
9
5
  require_relative "google_translate_tts/constanting"
10
6
  require_relative "google_translate_tts/fileable"
7
+ require_relative "google_translate_tts/utils"
11
8
  require_relative "google_translate_tts/version"
12
9
 
13
10
  module GoogleTranslateTts
14
11
  include Constanting
15
12
  include Fileable
13
+ include Utils
16
14
 
17
15
  class << self
18
16
  def fetch(phrase, **options)
19
17
  with_temp_file do |file|
20
- lang = options.fetch(:lang, "en_US")
21
- filename = options.fetch(:file, "file")
18
+ lang, filename = options.values_at(:lang, :file)
19
+ filename ||= options.fetch(:file, "file")
22
20
 
23
- response = Faraday.get(tts_resource_url(q: phrase, tl: lang))
21
+ response = Faraday.get(translate_tts_url(q: phrase, tl: lang))
24
22
 
25
23
  file.write(response.body)
26
24
 
27
- FileUtils.cp(file.path, "#{filename}.mp3")
25
+ copy_file(file.path, "#{filename}.mp3")
28
26
  end
29
27
  end
30
28
 
31
29
  private
32
30
 
33
- def tts_resource_url(**params)
31
+ def translate_tts_url(**params)
34
32
  "#{self::BASE_URL}/translate_tts?#{build_params(**params)}"
35
33
  end
36
34
 
37
- def build_params(**kwargs)
38
- kwargs[:tl] ||= 'en'
35
+ def default_params
36
+ { ie: "UTF-8", client: "tw-ob", q: "", tl: "en_US" }
37
+ end
39
38
 
40
- params = {
41
- ie: 'UTF-8',
42
- client: 'tw-ob',
43
- q: "",
44
- }.merge(**kwargs)
39
+ def build_params(**custom_params)
40
+ custom_params[:tl] ||= "en"
41
+ params_encode(default_params.merge(**custom_params))
42
+ end
45
43
 
46
- # params.map { |(key, value)| pp [key, value] }
47
- params.map { |(key, value)| "#{key}=#{CGI.escape(value)}" }.join("&")
44
+ def params_encode(params)
45
+ params
46
+ .map { |(key, value)| "#{key}=#{url_encode(value)}" }
47
+ .join("&")
48
48
  end
49
49
  end
50
50
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-translate-tts
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Vinciguerra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-16 00:00:00.000000000 Z
11
+ date: 2022-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -24,6 +24,34 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubocop
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.21'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.21'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop-rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.11'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.11'
27
55
  description: Simple Google Translate text to speech
28
56
  email:
29
57
  - daniel.vinciguerra@bivee.com.br
@@ -31,6 +59,7 @@ executables: []
31
59
  extensions: []
32
60
  extra_rdoc_files: []
33
61
  files:
62
+ - ".rspec"
34
63
  - ".rubocop.yml"
35
64
  - CHANGELOG.md
36
65
  - CODE_OF_CONDUCT.md
@@ -43,6 +72,7 @@ files:
43
72
  - lib/google_translate_tts.rb
44
73
  - lib/google_translate_tts/constanting.rb
45
74
  - lib/google_translate_tts/fileable.rb
75
+ - lib/google_translate_tts/utils.rb
46
76
  - lib/google_translate_tts/version.rb
47
77
  - play.rb
48
78
  homepage: https://github.com/dvinciguerra/google-translate-tts