simple_captcha_audio 0.0.1.rc1
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/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +49 -0
- data/Rakefile +2 -0
- data/lib/simple_captcha_audio/audio_helpers.rb +22 -0
- data/lib/simple_captcha_audio/middleware.rb +39 -0
- data/lib/simple_captcha_audio/version.rb +3 -0
- data/lib/simple_captcha_audio/view.rb +36 -0
- data/lib/simple_captcha_audio.rb +8 -0
- data/lib/tasks/clean.rake +6 -0
- data/simple_captcha_audio.gemspec +26 -0
- metadata +127 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b8b56e94e3539b08fa2a314cea078ebc02a8acdc
|
4
|
+
data.tar.gz: 3448bfe4e1b00d213dc9b433d6794db46ac13a10
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 18c3e8bd900c72c0ed24c66c9b3598adbbfb3fe031a5a2828b5d219aedf88102f0cfe7912876d1b067402e3f6bc4e49b8813369f54b69e9fb9cfbbc069db9d6d
|
7
|
+
data.tar.gz: 640baacc3d6a11dc729e84daca026698440abb3dd7192a8cd05d9109f64cb7fd56b38b7257334ee3c0d7e3a29bf247ee891b5f9dec4a4948bcdc0e7b32711ebb
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Aditya Kapoor
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# SimpleCaptchaAudio
|
2
|
+
|
3
|
+
Simple audio support for the `simple_captcha`.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'simple_captcha_audio'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install simple_captcha_audio
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
The extension adds another parameter to the image generation URL to facilitate the generation of audio file for the same captcha.
|
24
|
+
|
25
|
+
Suppose if the URL for the generation for image is
|
26
|
+
`http://localhost:3000/simple_captcha?code=3b803d95a91435997917b24046041cc31427aea3&time=1433768850` then simply append `audio=true` to the above URL to facilitate the generation of the audio file.
|
27
|
+
|
28
|
+
So visiting
|
29
|
+
`http://localhost:3000/simple_captcha?code=3b803d95a91435997917b24046041cc31427aea3&time=1433768850&audio=true` would generate the audio file.
|
30
|
+
|
31
|
+
## Requirements
|
32
|
+
* Ruby >= 1.9.3
|
33
|
+
* Rails >= 3.2
|
34
|
+
* You need to install `espeak`, `lame` and `sox` system libraries which would help you in the text to speech conversion and exporting the audio to the `mp3` format. `sox` is used for multiple audio files in a single consolidated mp3 file.
|
35
|
+
|
36
|
+
You might need to install the above libraries on a Mac-System:
|
37
|
+
|
38
|
+
```
|
39
|
+
brew install espeak lame
|
40
|
+
brew install flac sox chromaprint
|
41
|
+
```
|
42
|
+
|
43
|
+
## Contributing
|
44
|
+
|
45
|
+
1. Fork it ( https://github.com/[my-github-username]/simple_captcha_audio/fork )
|
46
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
47
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
48
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
49
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'espeak'
|
2
|
+
require 'sox'
|
3
|
+
|
4
|
+
module SimpleCaptcha
|
5
|
+
module AudioHelpers
|
6
|
+
include ESpeak
|
7
|
+
|
8
|
+
TMP_FILES_PATH = 'tmp/simple_captcha'
|
9
|
+
|
10
|
+
def generate_simple_captcha_audio(simple_captcha_key)
|
11
|
+
captcha_value = Utils::simple_captcha_value(simple_captcha_key)
|
12
|
+
filenames = []
|
13
|
+
captcha_value.each_char do |char|
|
14
|
+
file_name = TMP_FILES_PATH + '/audios/' + "simple-captcha-audio-#{ char }-#{ simple_captcha_key }.mp3"
|
15
|
+
Speech.new(char).save(file_name)
|
16
|
+
filenames << file_name
|
17
|
+
end
|
18
|
+
Sox::Combiner.new(filenames, combine: :concatenate).write(TMP_FILES_PATH + '/audios/' + "#{ captcha_value }.mp3")
|
19
|
+
File.read(TMP_FILES_PATH + '/audios/' + "#{ captcha_value }.mp3")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module SimpleCaptcha
|
2
|
+
class Middleware
|
3
|
+
include SimpleCaptcha::AudioHelpers
|
4
|
+
|
5
|
+
def call(env) # :nodoc:
|
6
|
+
if env["REQUEST_METHOD"] == "GET" && captcha_path?(env['PATH_INFO'])
|
7
|
+
request = Rack::Request.new(env)
|
8
|
+
if request.params.present? && request.params['code'].present?
|
9
|
+
if request.params['audio'] && request.params['audio'].eql?('true')
|
10
|
+
make_audio(env)
|
11
|
+
else
|
12
|
+
make_image(env)
|
13
|
+
end
|
14
|
+
else
|
15
|
+
refresh_code(env)
|
16
|
+
end
|
17
|
+
else
|
18
|
+
@app.call(env)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
protected
|
23
|
+
def make_audio(env)
|
24
|
+
request = Rack::Request.new(env)
|
25
|
+
code = request.params["code"]
|
26
|
+
body = []
|
27
|
+
|
28
|
+
if Utils::simple_captcha_value(code)
|
29
|
+
#status, headers, body = @app.call(env)
|
30
|
+
#status = 200
|
31
|
+
#body = generate_simple_captcha_audio(code)
|
32
|
+
#headers['Content-Type'] = 'audio/mpeg3'
|
33
|
+
send_data(generate_simple_captcha_audio(code), type: 'audio/mpeg3', disposition: 'inline', filename: 'simple_captcha_audio.mp3', stream: 'true', buffer_size: '4096')
|
34
|
+
else
|
35
|
+
[status, headers, body]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module SimpleCaptcha
|
2
|
+
module ViewHelper
|
3
|
+
# TODO: Devise some way to use super here..
|
4
|
+
alias_method :__simple_captcha_options__, :simple_captcha_options
|
5
|
+
|
6
|
+
def simple_captcha_options(options = {})
|
7
|
+
super_options = __simple_captcha_options__(options)
|
8
|
+
|
9
|
+
key = super_options[:field_value]
|
10
|
+
|
11
|
+
super_options.merge({
|
12
|
+
audio: simple_captcha_audio(key, options)
|
13
|
+
})
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
def simple_captcha_audio(simple_captcha_key, options = {})
|
18
|
+
url = simple_captcha_audio_url simple_captcha_key, options: options
|
19
|
+
id = simple_captcha_audio_id(options)
|
20
|
+
tag('audio', :src => url, :id => id, controls: true)
|
21
|
+
end
|
22
|
+
|
23
|
+
def simple_captcha_audio_url(simple_captcha_key, options = {})
|
24
|
+
defaults = {}
|
25
|
+
defaults[:time] = options[:time] || Time.now.to_i
|
26
|
+
|
27
|
+
query = defaults.to_query
|
28
|
+
path = "/simple_captcha?code=#{simple_captcha_key}&#{query}&audio=true"
|
29
|
+
build_url(options, path)
|
30
|
+
end
|
31
|
+
|
32
|
+
def simple_captcha_audio_id(options={})
|
33
|
+
"simple_captcha-audio-#{options[:field_value][0..10]}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'simple_captcha_audio/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "simple_captcha_audio"
|
8
|
+
spec.version = SimpleCaptchaAudio::VERSION
|
9
|
+
spec.authors = ["Aditya Kapoor"]
|
10
|
+
spec.email = ["adityakapoor.mait@gmail.com"]
|
11
|
+
spec.summary = "Simple Audio Extension to Simple Captcha"
|
12
|
+
spec.description = ""
|
13
|
+
spec.homepage = "https://github.com/aditya-kapoor/simple-captcha-audio"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", '~> 1.6'
|
22
|
+
spec.add_development_dependency "rake", '~> 10.0'
|
23
|
+
spec.add_dependency "simple_captcha2", '~> 0.3.4'
|
24
|
+
spec.add_dependency "espeak-ruby", '~> 1.0.2'
|
25
|
+
spec.add_dependency "ruby-sox", '~> 0.0.3'
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simple_captcha_audio
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1.rc1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Aditya Kapoor
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-06-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: simple_captcha2
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.3.4
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.3.4
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: espeak-ruby
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.0.2
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.0.2
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: ruby-sox
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.0.3
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.0.3
|
83
|
+
description: ''
|
84
|
+
email:
|
85
|
+
- adityakapoor.mait@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- Gemfile
|
92
|
+
- LICENSE.txt
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- lib/simple_captcha_audio.rb
|
96
|
+
- lib/simple_captcha_audio/audio_helpers.rb
|
97
|
+
- lib/simple_captcha_audio/middleware.rb
|
98
|
+
- lib/simple_captcha_audio/version.rb
|
99
|
+
- lib/simple_captcha_audio/view.rb
|
100
|
+
- lib/tasks/clean.rake
|
101
|
+
- simple_captcha_audio.gemspec
|
102
|
+
homepage: https://github.com/aditya-kapoor/simple-captcha-audio
|
103
|
+
licenses:
|
104
|
+
- MIT
|
105
|
+
metadata: {}
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">"
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: 1.3.1
|
120
|
+
requirements: []
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 2.2.2
|
123
|
+
signing_key:
|
124
|
+
specification_version: 4
|
125
|
+
summary: Simple Audio Extension to Simple Captcha
|
126
|
+
test_files: []
|
127
|
+
has_rdoc:
|