activestorage-audio 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.
- checksums.yaml +7 -0
- data/.github/workflows/ci.yml +23 -0
- data/.gitignore +10 -0
- data/.rubocop.yml +6 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +13 -0
- data/LICENSE.txt +21 -0
- data/README.md +97 -0
- data/Rakefile +17 -0
- data/activestorage-audio.gemspec +36 -0
- data/bin/console +9 -0
- data/bin/rake +32 -0
- data/bin/setup +23 -0
- data/lib/active_storage/audio.rb +14 -0
- data/lib/active_storage/audio/analyzer.rb +112 -0
- data/lib/active_storage/audio/railtie.rb +12 -0
- data/lib/active_storage/audio/version.rb +7 -0
- data/lib/activestorage-audio.rb +1 -0
- data/lib/tasks/changelog.rake +85 -0
- metadata +78 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: c31019f3eb870d07657ea9829f27c254da8f1f621a35f7be674fecb33f2a29bd
|
|
4
|
+
data.tar.gz: 8565fc6cd76964fa54e73283bd501da8fa632d719505e290cbe4946c81fab817
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 53982c532789866ed39692ebc8ed6f259c4beca368a3ef0564a6bc448936993f742503627b811e88bac3614708f42710e29fa378eed37f3c388a89488939b386
|
|
7
|
+
data.tar.gz: 60ecd6e1d46d2887033d1fd3936b1e5ef86b550e0b9a0580f992a2c5200923cf6d32a7cae3c6d15b9e0cee6cc35b4cfd0d2a2ae55fcd0434beded398d496942b
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
on: [push]
|
|
3
|
+
jobs:
|
|
4
|
+
test:
|
|
5
|
+
runs-on: ubuntu-latest
|
|
6
|
+
strategy:
|
|
7
|
+
matrix:
|
|
8
|
+
ruby_version: [2.4, 2.5, 2.6, 2.7]
|
|
9
|
+
steps:
|
|
10
|
+
- name: Checkout Source Code
|
|
11
|
+
uses: actions/checkout@v1
|
|
12
|
+
- name: Install Ruby
|
|
13
|
+
uses: actions/setup-ruby@v1
|
|
14
|
+
with:
|
|
15
|
+
ruby_version: ${{ matrix.ruby_version }}
|
|
16
|
+
- name: Install FFmpeg
|
|
17
|
+
use: mstksg/get-package@v1
|
|
18
|
+
with:
|
|
19
|
+
apt-get: ffmpeg
|
|
20
|
+
- name: Bundle Dependencies
|
|
21
|
+
run: bundle install
|
|
22
|
+
- name: Run Tests
|
|
23
|
+
run: bundle exec rake
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
|
10
|
+
orientation.
|
|
11
|
+
|
|
12
|
+
## Our Standards
|
|
13
|
+
|
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
|
15
|
+
include:
|
|
16
|
+
|
|
17
|
+
* Using welcoming and inclusive language
|
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
|
19
|
+
* Gracefully accepting constructive criticism
|
|
20
|
+
* Focusing on what is best for the community
|
|
21
|
+
* Showing empathy towards other community members
|
|
22
|
+
|
|
23
|
+
Examples of unacceptable behavior by participants include:
|
|
24
|
+
|
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
+
advances
|
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
28
|
+
* Public or private harassment
|
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
|
30
|
+
address, without explicit permission
|
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
+
professional setting
|
|
33
|
+
|
|
34
|
+
## Our Responsibilities
|
|
35
|
+
|
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
+
response to any instances of unacceptable behavior.
|
|
39
|
+
|
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
+
threatening, offensive, or harmful.
|
|
45
|
+
|
|
46
|
+
## Scope
|
|
47
|
+
|
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
+
when an individual is representing the project or its community. Examples of
|
|
50
|
+
representing a project or community include using an official project e-mail
|
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
|
53
|
+
further defined and clarified by project maintainers.
|
|
54
|
+
|
|
55
|
+
## Enforcement
|
|
56
|
+
|
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
+
reported by contacting the project team at tscott@weblinc.com. All
|
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
|
63
|
+
|
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
+
members of the project's leadership.
|
|
67
|
+
|
|
68
|
+
## Attribution
|
|
69
|
+
|
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
|
72
|
+
|
|
73
|
+
[homepage]: https://contributor-covenant.org
|
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
source 'https://rubygems.org'
|
|
4
|
+
|
|
5
|
+
# Specify your gem's dependencies in active_storage-audio.gemspec
|
|
6
|
+
gemspec
|
|
7
|
+
|
|
8
|
+
gem 'minitest', '~> 5.0'
|
|
9
|
+
gem 'mocha', '~> 1.11'
|
|
10
|
+
gem 'rake', '~> 12.0'
|
|
11
|
+
gem 'rubocop', '~> 0.78'
|
|
12
|
+
|
|
13
|
+
gem 'pry', '~> 0.12.2'
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Tom Scott
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# activestorage-audio
|
|
2
|
+
|
|
3
|
+
An audio analyzer for [ActiveStorage](https://guides.rubyonrails.org/active_storage_overview.html)
|
|
4
|
+
which will automatically analyze audio files using [FFmpeg](https://www.ffmpeg.org/).
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
Add this line to your application's Gemfile:
|
|
9
|
+
|
|
10
|
+
```ruby
|
|
11
|
+
gem 'active_storage-audio'
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Then, run:
|
|
15
|
+
|
|
16
|
+
$ bundle install
|
|
17
|
+
|
|
18
|
+
You will also need `ffmpeg` installed. On Debian-based systems, run:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
$ apt-get install -y ffmpeg
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
For macOS, run:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
$ brew install ffmpeg
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
If you're running Rails, `ActiveStorage::Audio::Analyzer` will be
|
|
33
|
+
automatically included in the list of analyzers to run on your uploaded
|
|
34
|
+
files. For a manual setup, add this to your app initialization:
|
|
35
|
+
|
|
36
|
+
```ruby
|
|
37
|
+
require "activestorage"
|
|
38
|
+
require "activestorage/audio"
|
|
39
|
+
|
|
40
|
+
ActiveStorage.analyzers << ActiveStorage::Audio::Analyzer
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
The analyzer will save its data to the `metadata` Hash on an audio file
|
|
44
|
+
`blob`, which can be accessed in the model like so:
|
|
45
|
+
|
|
46
|
+
```ruby
|
|
47
|
+
class Model < ApplicationRecord
|
|
48
|
+
has_attached_file :audio
|
|
49
|
+
|
|
50
|
+
# Return the duration of this Track
|
|
51
|
+
#
|
|
52
|
+
# @return [Float]
|
|
53
|
+
def duration
|
|
54
|
+
audio.blob.metadata[:duration] if audio.attached?
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
When you `#attach` an audio file to this model, the duration will be
|
|
60
|
+
computed using `ffprobe`, found using the current `$PATH`. If you wish
|
|
61
|
+
to set a custom path to ffprobe, do this in an initializer:
|
|
62
|
+
|
|
63
|
+
```ruby
|
|
64
|
+
ActiveSupport.paths[:ffprobe] = '/opt/local/bin/ffprobe'
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Development
|
|
68
|
+
|
|
69
|
+
After checking out the repo, run `bin/setup` to install dependencies.
|
|
70
|
+
Then, run `rake test` to run the tests. You can also run `bin/console`
|
|
71
|
+
for an interactive prompt that will allow you to experiment.
|
|
72
|
+
|
|
73
|
+
To install this gem onto your local machine, run `bundle exec rake
|
|
74
|
+
install`. To release a new version, update the version number in
|
|
75
|
+
`version.rb`, and then run `bundle exec rake release`, which will create
|
|
76
|
+
a git tag for the version, push git commits and tags, and push the
|
|
77
|
+
`.gem` file to [rubygems.org](https://rubygems.org).
|
|
78
|
+
|
|
79
|
+
## Contributing
|
|
80
|
+
|
|
81
|
+
vBug reports and pull requests are welcome on GitHub at
|
|
82
|
+
https://github.com/tubbo/active_storage-audio. This project is intended
|
|
83
|
+
to be a safe, welcoming space for collaboration, and contributors are
|
|
84
|
+
expected to adhere to the [code of
|
|
85
|
+
conduct](https://github.com/tubbo/active_storage-audio/blob/master/CODE_OF_CONDUCT.md).
|
|
86
|
+
|
|
87
|
+
## License
|
|
88
|
+
|
|
89
|
+
The gem is available as open source under the terms of the [MIT
|
|
90
|
+
License](https://opensource.org/licenses/MIT).
|
|
91
|
+
|
|
92
|
+
## Code of Conduct
|
|
93
|
+
|
|
94
|
+
Everyone interacting in the ActiveStorage::Audio project's codebases,
|
|
95
|
+
issue trackers, chat rooms and mailing lists is expected to follow the
|
|
96
|
+
[code of
|
|
97
|
+
conduct](https://github.com/tubbo/active_storage-audio/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'bundler/gem_tasks'
|
|
4
|
+
require 'rake/testtask'
|
|
5
|
+
require 'rubocop/rake_task'
|
|
6
|
+
|
|
7
|
+
load 'lib/tasks/changelog.rake'
|
|
8
|
+
|
|
9
|
+
RuboCop::RakeTask.new :lint
|
|
10
|
+
|
|
11
|
+
Rake::TestTask.new :test do |t|
|
|
12
|
+
t.libs << 'test'
|
|
13
|
+
t.libs << 'lib'
|
|
14
|
+
t.test_files = FileList['test/**/*_test.rb']
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
task default: %i[lint test build]
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'lib/active_storage/audio/version'
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = 'activestorage-audio'
|
|
7
|
+
spec.version = ActiveStorage::Audio::VERSION
|
|
8
|
+
spec.authors = ['Tom Scott']
|
|
9
|
+
spec.email = ['tubbo@psychedeli.ca']
|
|
10
|
+
|
|
11
|
+
spec.summary = 'Audio analyzer for uploaded files using ffprobe'
|
|
12
|
+
spec.description = spec.summary
|
|
13
|
+
spec.homepage = 'https://github.com/tubbo/activestorage-audio'
|
|
14
|
+
spec.license = 'MIT'
|
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
|
|
16
|
+
|
|
17
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
|
18
|
+
spec.metadata['source_code_uri'] =
|
|
19
|
+
'https://tubbo.github.io/activestorage-audio'
|
|
20
|
+
spec.metadata['changelog_uri'] =
|
|
21
|
+
'https://tubbo.github.io/activestorage-audio/blob/master/CHANGELOG.md'
|
|
22
|
+
|
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been
|
|
25
|
+
# added into git.
|
|
26
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
|
27
|
+
`git ls-files -z`.split("\x0").reject do |path|
|
|
28
|
+
path.match(%r{^(test|spec|features)/})
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
spec.bindir = 'exe'
|
|
32
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
33
|
+
spec.require_paths = ['lib']
|
|
34
|
+
|
|
35
|
+
spec.add_dependency 'activestorage', '>= 5'
|
|
36
|
+
end
|
data/bin/console
ADDED
data/bin/rake
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
#
|
|
5
|
+
# This file was generated by Bundler.
|
|
6
|
+
#
|
|
7
|
+
# The application 'rake' is installed as part of a gem, and
|
|
8
|
+
# this file is here to facilitate running it.
|
|
9
|
+
#
|
|
10
|
+
|
|
11
|
+
require 'pathname'
|
|
12
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile',
|
|
13
|
+
Pathname.new(__FILE__).realpath)
|
|
14
|
+
|
|
15
|
+
bundle_binstub = File.expand_path('bundle', __dir__)
|
|
16
|
+
|
|
17
|
+
if File.file?(bundle_binstub)
|
|
18
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
|
19
|
+
load(bundle_binstub)
|
|
20
|
+
else
|
|
21
|
+
abort %(
|
|
22
|
+
Your `bin/bundle` was not generated by Bundler, so this binstub
|
|
23
|
+
cannot run. Replace `bin/bundle` by running
|
|
24
|
+
`bundle binstubs bundler --force`, then run this command again.
|
|
25
|
+
)
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
require 'rubygems'
|
|
30
|
+
require 'bundler/setup'
|
|
31
|
+
|
|
32
|
+
load Gem.bin_path('rake', 'rake')
|
data/bin/setup
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
IFS=$'\n\t'
|
|
4
|
+
set -vx
|
|
5
|
+
|
|
6
|
+
# Install FFmpeg
|
|
7
|
+
case "$(uname -s)" in
|
|
8
|
+
Darwin)
|
|
9
|
+
brew install ffmpeg
|
|
10
|
+
;;
|
|
11
|
+
Linux)
|
|
12
|
+
debian="$(grep -qEi 'debian|buntu|mint' /etc/*release)"
|
|
13
|
+
if [ -n "$debian" ]; then
|
|
14
|
+
apt-get install -yy ffmpeg
|
|
15
|
+
fi
|
|
16
|
+
;;
|
|
17
|
+
*)
|
|
18
|
+
echo "Please install \`ffmpeg\` from source"
|
|
19
|
+
;;
|
|
20
|
+
esac
|
|
21
|
+
|
|
22
|
+
# Install the bundle
|
|
23
|
+
bundle install
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'active_storage'
|
|
4
|
+
require 'active_storage/audio/version'
|
|
5
|
+
require 'active_storage/audio/analyzer'
|
|
6
|
+
require 'active_storage/audio/railtie' if defined? Rails
|
|
7
|
+
|
|
8
|
+
module ActiveStorage
|
|
9
|
+
module Audio
|
|
10
|
+
class Error < StandardError; end
|
|
11
|
+
|
|
12
|
+
# Your code goes here...
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ActiveStorage
|
|
4
|
+
module Audio
|
|
5
|
+
# Uses `ffprobe` to quickly find information about the track file, such
|
|
6
|
+
# as duration, bitrate, sample rate, and its codec.
|
|
7
|
+
class Analyzer < ActiveStorage::Analyzer
|
|
8
|
+
# Tests whether the given `blob` is an audio file. If so, this
|
|
9
|
+
# file will be analyzed by the `Audio::Analyzer`.
|
|
10
|
+
#
|
|
11
|
+
# @param [ActiveStorage::Blob] blob - Blob to test
|
|
12
|
+
# @return [Boolean] whether `#audio?` returns true
|
|
13
|
+
def self.accept?(blob)
|
|
14
|
+
blob.audio?
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Metadata to add to the blob. Any empty values are omitted.
|
|
18
|
+
#
|
|
19
|
+
# @return [Hash]
|
|
20
|
+
def metadata
|
|
21
|
+
{
|
|
22
|
+
duration: duration,
|
|
23
|
+
bit_rate: bit_rate,
|
|
24
|
+
sample_rate: sample_rate,
|
|
25
|
+
codec: codec,
|
|
26
|
+
channels: channels,
|
|
27
|
+
channel_layout: channel_layout
|
|
28
|
+
}.compact
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Duration of this audio file in seconds.
|
|
32
|
+
#
|
|
33
|
+
# @return [Float]
|
|
34
|
+
def duration
|
|
35
|
+
stream['duration'].to_f
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Bit rate of this audio file, e.g. `16.0`
|
|
39
|
+
#
|
|
40
|
+
# @return [Float]
|
|
41
|
+
def bit_rate
|
|
42
|
+
stream['bit_rate'].to_f
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Sample rate of this audio file, e.g. `44.1`
|
|
46
|
+
#
|
|
47
|
+
# @return [Float]
|
|
48
|
+
def sample_rate
|
|
49
|
+
stream['sample_rate'].to_i
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Codec used to encode this audio file.
|
|
53
|
+
#
|
|
54
|
+
# @return [String]
|
|
55
|
+
def codec
|
|
56
|
+
stream['codec']
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Number of audio channels (1 for mono, 2 for stereo)
|
|
60
|
+
#
|
|
61
|
+
# @return [Integer]
|
|
62
|
+
def channels
|
|
63
|
+
stream['channels'].to_i
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# Layout of channels.
|
|
67
|
+
#
|
|
68
|
+
# @return [String]
|
|
69
|
+
def channel_layout
|
|
70
|
+
stream['channel_layout']
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
private
|
|
74
|
+
|
|
75
|
+
# @private
|
|
76
|
+
# @return [Hash] Raw data from `ffprobe`
|
|
77
|
+
def probe
|
|
78
|
+
@probe ||= download_blob_to_tempfile do |file|
|
|
79
|
+
IO.popen(command(file.path)) do |output|
|
|
80
|
+
JSON.parse(output.read)
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# @private
|
|
86
|
+
# @return [Hash] The first stream found in the search.
|
|
87
|
+
def stream
|
|
88
|
+
probe['streams'].first
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# @private
|
|
92
|
+
# @return [String] Output of the `ffprobe` command execution.
|
|
93
|
+
def command(path)
|
|
94
|
+
[
|
|
95
|
+
ffprobe,
|
|
96
|
+
'-show_streams',
|
|
97
|
+
'-v',
|
|
98
|
+
'error',
|
|
99
|
+
'-print_format',
|
|
100
|
+
'json',
|
|
101
|
+
path
|
|
102
|
+
]
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# @private
|
|
106
|
+
# @return [String] Path to `ffprobe`.
|
|
107
|
+
def ffprobe
|
|
108
|
+
@ffprobe ||= ActiveStorage.paths[:ffprobe] || 'ffprobe'
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ActiveStorage
|
|
4
|
+
module Audio
|
|
5
|
+
# Rails hook that automatically appends
|
|
6
|
+
# `ActiveStorage::Audio::Analyzer` to the collection of analyzers
|
|
7
|
+
# that `ActiveStorage` will run on uploaded files.
|
|
8
|
+
class Engine < Rails::Railtie
|
|
9
|
+
config.active_storage.analyzers.append ActiveStorage::Audio::Analyzer
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require 'active_storage/audio'
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
desc 'Generate CHANGELOG based on Git history'
|
|
4
|
+
task :changelog do
|
|
5
|
+
# Ensure directory
|
|
6
|
+
if Dir['.git'].empty?
|
|
7
|
+
raise "the changelog task must be run from this repo's root directory"
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
# set up & capture git log
|
|
11
|
+
from =
|
|
12
|
+
if `git tag`.empty?
|
|
13
|
+
`git rev-list --max-parents=0 HEAD`.strip
|
|
14
|
+
else
|
|
15
|
+
`git describe --tags --abbrev=0`.strip
|
|
16
|
+
end
|
|
17
|
+
git_log_format = '%H[/PIECE]%s[/PIECE]%b[/PIECE]%an[/ENTRY]'
|
|
18
|
+
log = `git log #{from}..HEAD --pretty=format:'#{git_log_format}' --no-merges`
|
|
19
|
+
|
|
20
|
+
# assumes only one gemspec in project root
|
|
21
|
+
gem = Gem::Specification.load(Dir['./*.gemspec'].first)
|
|
22
|
+
gem_name = gem.name.tr('_', '-').split('-').map(&:capitalize).join(' ')
|
|
23
|
+
gem_version = gem.version.version
|
|
24
|
+
|
|
25
|
+
# Iterate through each commit in the log, cataloging entries and reverts
|
|
26
|
+
entries = {}
|
|
27
|
+
reverts = []
|
|
28
|
+
log.split('[/ENTRY]').each do |commit|
|
|
29
|
+
pieces = commit.split('[/PIECE]').map(&:strip)
|
|
30
|
+
sha, subject, body, author = pieces
|
|
31
|
+
|
|
32
|
+
next if subject =~ /update changelog/i
|
|
33
|
+
next if subject =~ /release version/i
|
|
34
|
+
next if body =~ /no changelog/i
|
|
35
|
+
|
|
36
|
+
entries[sha] = {
|
|
37
|
+
subject: subject,
|
|
38
|
+
body: body,
|
|
39
|
+
author: author
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if subject.start_with?('Revert')
|
|
43
|
+
reverts << body.match(/[a-f0-9]{40}/)
|
|
44
|
+
reverts << sha
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Remove revert commits from log entries
|
|
49
|
+
reverts.each { |key| entries.delete key }
|
|
50
|
+
|
|
51
|
+
# guard against empty changelog
|
|
52
|
+
raise 'the generated changelog must have at least one entry' if entries.empty?
|
|
53
|
+
|
|
54
|
+
# set message title
|
|
55
|
+
message = []
|
|
56
|
+
message << "#{gem_name} #{gem_version} (#{Date.today})"
|
|
57
|
+
message << '-' * 80 + "\n"
|
|
58
|
+
|
|
59
|
+
# loop through all entries, templetizing their contents
|
|
60
|
+
entries.each do |_sha, entry|
|
|
61
|
+
message << "* #{entry[:subject]}\n"
|
|
62
|
+
entry[:body].each_line do |line|
|
|
63
|
+
message << if line.strip.empty?
|
|
64
|
+
''
|
|
65
|
+
else
|
|
66
|
+
" #{line.strip}"
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
message << " #{entry[:author]}\n"
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# ensure and append to changelog
|
|
73
|
+
FileUtils.touch('CHANGELOG.md')
|
|
74
|
+
|
|
75
|
+
tempfile = Tempfile.new
|
|
76
|
+
changelog = File.expand_path('./CHANGELOG.md')
|
|
77
|
+
|
|
78
|
+
File.open(tempfile, 'a') do |file|
|
|
79
|
+
file << message.join("\n")
|
|
80
|
+
file << "\n\n\n"
|
|
81
|
+
file << File.read(changelog)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
FileUtils.mv(tempfile, changelog)
|
|
85
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: activestorage-audio
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Tom Scott
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2019-12-28 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: activestorage
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '5'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '5'
|
|
27
|
+
description: Audio analyzer for uploaded files using ffprobe
|
|
28
|
+
email:
|
|
29
|
+
- tubbo@psychedeli.ca
|
|
30
|
+
executables: []
|
|
31
|
+
extensions: []
|
|
32
|
+
extra_rdoc_files: []
|
|
33
|
+
files:
|
|
34
|
+
- ".github/workflows/ci.yml"
|
|
35
|
+
- ".gitignore"
|
|
36
|
+
- ".rubocop.yml"
|
|
37
|
+
- CODE_OF_CONDUCT.md
|
|
38
|
+
- Gemfile
|
|
39
|
+
- LICENSE.txt
|
|
40
|
+
- README.md
|
|
41
|
+
- Rakefile
|
|
42
|
+
- activestorage-audio.gemspec
|
|
43
|
+
- bin/console
|
|
44
|
+
- bin/rake
|
|
45
|
+
- bin/setup
|
|
46
|
+
- lib/active_storage/audio.rb
|
|
47
|
+
- lib/active_storage/audio/analyzer.rb
|
|
48
|
+
- lib/active_storage/audio/railtie.rb
|
|
49
|
+
- lib/active_storage/audio/version.rb
|
|
50
|
+
- lib/activestorage-audio.rb
|
|
51
|
+
- lib/tasks/changelog.rake
|
|
52
|
+
homepage: https://github.com/tubbo/activestorage-audio
|
|
53
|
+
licenses:
|
|
54
|
+
- MIT
|
|
55
|
+
metadata:
|
|
56
|
+
homepage_uri: https://github.com/tubbo/activestorage-audio
|
|
57
|
+
source_code_uri: https://tubbo.github.io/activestorage-audio
|
|
58
|
+
changelog_uri: https://tubbo.github.io/activestorage-audio/blob/master/CHANGELOG.md
|
|
59
|
+
post_install_message:
|
|
60
|
+
rdoc_options: []
|
|
61
|
+
require_paths:
|
|
62
|
+
- lib
|
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - ">="
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: 2.3.0
|
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
69
|
+
requirements:
|
|
70
|
+
- - ">="
|
|
71
|
+
- !ruby/object:Gem::Version
|
|
72
|
+
version: '0'
|
|
73
|
+
requirements: []
|
|
74
|
+
rubygems_version: 3.0.3
|
|
75
|
+
signing_key:
|
|
76
|
+
specification_version: 4
|
|
77
|
+
summary: Audio analyzer for uploaded files using ffprobe
|
|
78
|
+
test_files: []
|