auphonic 0.1.0

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.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in auphonic.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Phil Hofmann
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,75 @@
1
+ # Auphonic (Ruby Gem)
2
+
3
+ A ruby wrapper and CLI for the Auphonic API.
4
+
5
+ * https://auphonic.com/api-docs/
6
+
7
+ Happily engineered while working on [VoiceRepublic](http://voicerepublic.com).
8
+
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ gem 'auphonic'
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install auphonic
23
+
24
+
25
+ ## Setup
26
+
27
+ Create a file with your credentials
28
+
29
+ echo "login: yourlogin\npasswd: secret" > ~/.auphonic
30
+
31
+
32
+ ## Usage (as CLI)
33
+
34
+ ### create, upload, start, wait, download
35
+
36
+ Creates a production based on the first (!) preset it will find,
37
+ uploads the file to it, starts the production, waits for the processing
38
+ to finish, and downloads all output files.
39
+
40
+ auphonic process <audiofile>
41
+
42
+
43
+ ## Usage (as library)
44
+
45
+ ### Query data
46
+
47
+ Auphonic::Preset.all
48
+ Auphonic::Production.all
49
+ Auphonic::Service.all
50
+ Auphonic::Info::ServiceType.all
51
+ Auphonic::Info::Algorithm.all
52
+ Auphonic::Info::OutputFile.all
53
+ Auphonic::Info::ProductionStatus.all
54
+
55
+ These queries returns arrays of data entities. All data entities have
56
+ an accessor data which holds the hash returned by the API.
57
+
58
+ ### Example
59
+
60
+ preset = Preset.all.first
61
+ production = preset.new_production
62
+ production.save
63
+ production.upload 'somefile.wav'
64
+ production.start
65
+ sleep 10 until production.reload.status == 'Done'
66
+ production.download
67
+
68
+
69
+ ## Contributing
70
+
71
+ 1. Fork it
72
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
73
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
74
+ 4. Push to the branch (`git push origin my-new-feature`)
75
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/auphonic.gemspec ADDED
@@ -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 'auphonic/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "auphonic"
8
+ spec.version = Auphonic::VERSION
9
+ spec.authors = ["Phil Hofmann"]
10
+ spec.email = ["phil@branch14.org"]
11
+ spec.description = %q{A ruby wrapper and CLI for the Auphonic API.}
12
+ spec.summary = %q{A ruby wrapper and CLI for the Auphonic API.}
13
+ spec.homepage = "https://github.com/branch14/auphonic"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
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_dependency "faraday"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ # spec.add_development_dependency "rspec"
26
+ end
data/bin/auphonic ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path('../../lib/auphonic', __FILE__)
4
+
5
+ Auphonic::Exec.run(ARGV)
data/lib/auphonic.rb ADDED
@@ -0,0 +1,13 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+
3
+ require "auphonic/version"
4
+ require "auphonic/exec"
5
+ require "auphonic/endpoint"
6
+ require "auphonic/base"
7
+ require "auphonic/production"
8
+ require "auphonic/preset"
9
+ require "auphonic/service"
10
+ require "auphonic/info"
11
+
12
+ module Auphonic
13
+ end
@@ -0,0 +1,17 @@
1
+ module Auphonic
2
+ class Base < Struct.new(:data)
3
+
4
+ class << self
5
+ def all
6
+ method = self.name.downcase.gsub('::', '_').sub('auphonic_', '') + 's'
7
+ raise 'Please do not call base directly' if method == 'bases'
8
+ Endpoint.instance.send(method).map { |data| new(data) }
9
+ end
10
+ end
11
+
12
+ def uuid
13
+ data['uuid']
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,113 @@
1
+ require 'singleton'
2
+ require 'faraday'
3
+ require 'yaml'
4
+ require 'ostruct'
5
+ require 'json'
6
+
7
+ module Auphonic
8
+ class Endpoint
9
+
10
+ include Singleton
11
+
12
+ URL = 'https://auphonic.com'
13
+
14
+ def initialize
15
+ @connection ||= Faraday.new(:url => URL) do |faraday|
16
+ faraday.request :multipart
17
+ #faraday.response :logger
18
+ faraday.adapter Faraday.default_adapter
19
+ end
20
+ config = OpenStruct.new(YAML.load(File.read(File.expand_path("~/.auphonic"))))
21
+ credentials = [ config.login, config.passwd ]
22
+ @connection.basic_auth(*credentials)
23
+ end
24
+
25
+ def productions
26
+ get('/api/productions.json')['data']
27
+ end
28
+
29
+ def presets
30
+ get('/api/presets.json')['data']
31
+ end
32
+
33
+ def services
34
+ get('/api/services.json')['data']
35
+ end
36
+
37
+ def info_servicetypes
38
+ get('/api/info/service_types.json')['data']
39
+ end
40
+
41
+ def info_algorithms
42
+ get('/api/info/algorithms.json')['data']
43
+ end
44
+
45
+ def info_outputfiles
46
+ get('/api/info/output_files.json')['data']
47
+ end
48
+
49
+ def info_productionsstatuss # sic
50
+ get('/api/info/production_status.json')['data']
51
+ end
52
+
53
+ def load_production(uuid)
54
+ get("/api/production/#{uuid}.json")['data']
55
+ end
56
+
57
+ def create_production(data)
58
+ url = '/api/productions.json'
59
+ response = @connection.post do |req|
60
+ req.url url
61
+ req.headers['Content-Type'] = 'application/json'
62
+ req.body = data.to_json
63
+ end
64
+ JSON.parse(response.body)['data']
65
+ end
66
+
67
+ def upload_to_production(uuid, path)
68
+ raise 'Error: uuid missing' if uuid.nil?
69
+ url = "/api/production/#{uuid}/upload.json"
70
+ payload = { input_file: Faraday::UploadIO.new(path, 'audio/basic') }
71
+ response = @connection.post(url, payload)
72
+ JSON.parse(response.body)['data']
73
+ end
74
+
75
+ def start_production(uuid)
76
+ url = "/api/production/#{uuid}/start.json"
77
+ response = @connection.post do |req|
78
+ req.url url
79
+ req.headers['Content-Type'] = 'application/json'
80
+ end
81
+ JSON.parse(response.body)['data']
82
+ end
83
+
84
+ def download(url)
85
+ url.sub!(URL, '')
86
+ filename = File.basename(url)
87
+ response = @connection.get(url)
88
+ File.open(filename, 'w') { |f| f.print(response.body) }
89
+ filename
90
+ end
91
+
92
+ # def post(url, &bloc)
93
+ # puts '=' * 80
94
+ # puts "POST #{url}"
95
+ # puts '=' * 80
96
+ # response = @connection.post url, bloc
97
+ # result = JSON.parse(response.body)
98
+ # return result['data'] if result['status_code'] == 200
99
+ # # error
100
+ # result['data'] = nil
101
+ # pp result
102
+ # exit
103
+ # end
104
+
105
+ private
106
+
107
+ def get(url)
108
+ response = @connection.get(url)
109
+ JSON.parse(response.body)
110
+ end
111
+
112
+ end
113
+ end
@@ -0,0 +1,39 @@
1
+ module Auphonic
2
+ class Exec < Struct.new(:args)
3
+ class << self
4
+ def run(args)
5
+ new(args).run
6
+ end
7
+ end
8
+
9
+ def run
10
+ usage if args[0] != 'process'
11
+ file = args[1] || usage
12
+ puts 'create new production'
13
+ p1 = Preset.all.first.new_production.save
14
+ puts "upload #{file}"
15
+ p1.upload file
16
+ puts 'start production'
17
+ p1.start
18
+ status = nil
19
+ until status == 'Done'
20
+ sleep 5
21
+ status = p1.reload.data['status_string']
22
+ puts "Status: #{status}"
23
+ end
24
+ puts 'download output files'
25
+ puts *p1.download
26
+ end
27
+
28
+ def usage
29
+ puts
30
+ puts 'Usage: auphonic process <file>'
31
+ puts
32
+ exit
33
+ end
34
+
35
+ # def parse_args
36
+ # # TODO
37
+ # end
38
+ end
39
+ end
@@ -0,0 +1,15 @@
1
+ module Auphonic
2
+ module Info
3
+ class ServiceType < Base
4
+ end
5
+
6
+ class Algorithm < Base
7
+ end
8
+
9
+ class OutputFile < Base
10
+ end
11
+
12
+ class ProductionStatus < Base
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,10 @@
1
+ module Auphonic
2
+ class Preset < Base
3
+
4
+ def new_production
5
+ Production.new preset: uuid
6
+ end
7
+
8
+ end
9
+ end
10
+
@@ -0,0 +1,35 @@
1
+ module Auphonic
2
+ class Production < Base
3
+
4
+ def save
5
+ self.data = Endpoint.instance.create_production(self.data)
6
+ self
7
+ end
8
+
9
+ def upload(path)
10
+ self.data = Endpoint.instance.upload_to_production(uuid, path)
11
+ self
12
+ end
13
+
14
+ def start
15
+ self.data = Endpoint.instance.start_production(uuid)
16
+ self
17
+ end
18
+
19
+ def reload
20
+ self.data = Endpoint.instance.load_production(uuid)
21
+ self
22
+ end
23
+
24
+ def download
25
+ data['output_files'].map do |out|
26
+ Endpoint.instance.download(out['download_url'])
27
+ end
28
+ end
29
+
30
+ def status
31
+ data['status_string']
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,5 @@
1
+ module Auphonic
2
+ class Service < Base
3
+ end
4
+ end
5
+
@@ -0,0 +1,3 @@
1
+ module Auphonic
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: auphonic
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Phil Hofmann
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-02-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: faraday
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: bundler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.3'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.3'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: A ruby wrapper and CLI for the Auphonic API.
63
+ email:
64
+ - phil@branch14.org
65
+ executables:
66
+ - auphonic
67
+ extensions: []
68
+ extra_rdoc_files: []
69
+ files:
70
+ - .gitignore
71
+ - Gemfile
72
+ - LICENSE.txt
73
+ - README.md
74
+ - Rakefile
75
+ - auphonic.gemspec
76
+ - bin/auphonic
77
+ - lib/auphonic.rb
78
+ - lib/auphonic/base.rb
79
+ - lib/auphonic/endpoint.rb
80
+ - lib/auphonic/exec.rb
81
+ - lib/auphonic/info.rb
82
+ - lib/auphonic/preset.rb
83
+ - lib/auphonic/production.rb
84
+ - lib/auphonic/service.rb
85
+ - lib/auphonic/version.rb
86
+ homepage: https://github.com/branch14/auphonic
87
+ licenses:
88
+ - MIT
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ segments:
100
+ - 0
101
+ hash: 3415940211667464281
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ! '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ segments:
109
+ - 0
110
+ hash: 3415940211667464281
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 1.8.23
114
+ signing_key:
115
+ specification_version: 3
116
+ summary: A ruby wrapper and CLI for the Auphonic API.
117
+ test_files: []