mp4_renamer 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +20 -0
- data/.rubocop.yml +10 -0
- data/.yardopts +2 -0
- data/CHANGELOGS.md +5 -0
- data/Gemfile +3 -0
- data/Guardfile +9 -0
- data/LICENSE +22 -0
- data/README.md +127 -0
- data/Rakefile +28 -0
- data/bin/mp4_renamer +13 -0
- data/fixtures/.gitkeep +0 -0
- data/fixtures/01.mp4 +0 -0
- data/fixtures/02.m4a +0 -0
- data/fixtures/faac.m4a +0 -0
- data/fixtures/iTunes.m4a +0 -0
- data/fixtures/iTunes_utf8.m4a +0 -0
- data/fixtures/nero.mp4 +0 -0
- data/fixtures/real.m4a +0 -0
- data/lib/mp4_renamer.rb +12 -0
- data/lib/mp4_renamer/cli.rb +77 -0
- data/lib/mp4_renamer/renamer.rb +57 -0
- data/lib/mp4_renamer/version.rb +3 -0
- data/mp4_renamer.gemspec +36 -0
- data/test/lib/mp4_renamer/fixture_helper.rb +45 -0
- data/test/lib/mp4_renamer/test_renamer.rb +31 -0
- data/test/test_helper.rb +9 -0
- metadata +287 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 826534e93fe57cf0fffadbf4399699ba64b5f7c3
|
4
|
+
data.tar.gz: ecee1a8f93318535a3e0ae40ddd664d8980fa1d0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ebc6a08eb2a1ba02a7df3f75a41a342b97703d884618328ff3597c67e8f743ce8fe2cf013b13e9ae04c2288c6053a8c252cb81830afbbf8a48f4e71823bff519
|
7
|
+
data.tar.gz: 743688b45ad5652ecb4e05a401b324230c5a7356c168f05cbc37e7b724fff04d807849faa440a6e29e5221c6f79524e32bdeb526939fadbce892877e60d2e17b
|
data/.gitignore
ADDED
@@ -0,0 +1,20 @@
|
|
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
|
18
|
+
# Custom generated files
|
19
|
+
.ruby-version
|
20
|
+
#fixtures/*.mp4
|
data/.rubocop.yml
ADDED
data/.yardopts
ADDED
data/CHANGELOGS.md
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
project_name = 'mp4_renamer'
|
4
|
+
|
5
|
+
guard 'minitest' do
|
6
|
+
watch(%r|^test/(.*)\/?test_(.*)\.rb|)
|
7
|
+
watch(%r|^lib/(.*)([^/]+)\.rb|) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
|
8
|
+
watch(%r|^test/test_helper\.rb|) { "test" }
|
9
|
+
end
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Burin Choomnuan
|
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,127 @@
|
|
1
|
+
## Mp4Renamer
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/mp4_renamer.svg)][gem]
|
4
|
+
[![Dependency Status](https://gemnasium.com/agilecreativity/mp4_renamer.png)][gemnasium]
|
5
|
+
[![Code Climate](https://codeclimate.com/github/agilecreativity/mp4_renamer.png)][codeclimate]
|
6
|
+
|
7
|
+
[gem]: http://badge.fury.io/rb/mp4_renamer
|
8
|
+
[gemnasium]: https://gemnasium.com/agilecreativity/mp4_renamer
|
9
|
+
[codeclimate]: https://codeclimate.com/github/agilecreativity/mp4_renamer
|
10
|
+
|
11
|
+
Simple gem to rename the `mp4` or `m4a` file by adding the running time to the input file name.
|
12
|
+
|
13
|
+
e.g. If the input file name is `introduction.mp4` and it contain `00:54` of running time then
|
14
|
+
the file would be renamed to `introduction_00_54.mp4` e.g. <original_filename><running_time>.mp4
|
15
|
+
|
16
|
+
- Support the `*.m4a` and `*.mp4` file formats only
|
17
|
+
|
18
|
+
### Sample Usage
|
19
|
+
|
20
|
+
- Install the gem
|
21
|
+
|
22
|
+
```shell
|
23
|
+
$gem install mp4_renamer
|
24
|
+
```
|
25
|
+
|
26
|
+
- Running the command without any argument will show the default help message
|
27
|
+
|
28
|
+
```shell
|
29
|
+
mp4_renamer
|
30
|
+
```
|
31
|
+
|
32
|
+
Should show the following output
|
33
|
+
|
34
|
+
```
|
35
|
+
Usage:
|
36
|
+
mp4_renamer [options]
|
37
|
+
|
38
|
+
Options:
|
39
|
+
-b, [--base-dir=BASE_DIR] # Starting directory
|
40
|
+
# Default: . (current directory)
|
41
|
+
-r, [--recursive=RECURSIVE] # Perform the operation recursively
|
42
|
+
# Default: true
|
43
|
+
-c, [--commit], [--no-commit] # Commit your changes
|
44
|
+
# Default: --no-commit
|
45
|
+
-v, [--version], [--no-version] # Display version number
|
46
|
+
# Default: --no-version
|
47
|
+
|
48
|
+
Execute the main program
|
49
|
+
```
|
50
|
+
|
51
|
+
- Running the default command to see what will the result be like without making any changes (dry-run)
|
52
|
+
|
53
|
+
```shell
|
54
|
+
mp4_renamer --base-dir . --recursive
|
55
|
+
|
56
|
+
# or short version
|
57
|
+
mp4_renamer -b . -r
|
58
|
+
```
|
59
|
+
|
60
|
+
Shous show outputs similar to the following
|
61
|
+
|
62
|
+
```
|
63
|
+
FYI: your options {:base_dir=>".", :recursive=>true, :commit=>false, :version=>false}
|
64
|
+
-----------------------------------------------------------------------
|
65
|
+
FYI: this is a dry-run only, to commit your changes use --commit option
|
66
|
+
-----------------------------------------------------------------------
|
67
|
+
FYI: input file : ./fixtures/01.mp4
|
68
|
+
FYI: output file: ./fixtures/01_00_54.mp4
|
69
|
+
FYI: input file : ./fixtures/02.mp4
|
70
|
+
FYI: output file: ./fixtures/02_00_54.mp4
|
71
|
+
```
|
72
|
+
|
73
|
+
- To make your change permanent just add the `--commit` flag
|
74
|
+
|
75
|
+
```shell
|
76
|
+
mp4_renamer --base-dir . --recursive --commit
|
77
|
+
# or short version
|
78
|
+
mp4_renamer -b . -r -c
|
79
|
+
```
|
80
|
+
|
81
|
+
### Why is this useful?
|
82
|
+
|
83
|
+
- Know how long it will take to watch the video
|
84
|
+
- Give you the context without the need to open file and look at the running time of a given file
|
85
|
+
- To make your output even more useful, try using this with [filename_cleaner][] gem
|
86
|
+
|
87
|
+
### Installation
|
88
|
+
|
89
|
+
Add this line to your application's Gemfile:
|
90
|
+
|
91
|
+
gem 'mp4_renamer'
|
92
|
+
|
93
|
+
And then execute:
|
94
|
+
|
95
|
+
$ bundle
|
96
|
+
|
97
|
+
Or install it yourself as:
|
98
|
+
|
99
|
+
$ gem install mp4_renamer
|
100
|
+
|
101
|
+
### Usage
|
102
|
+
|
103
|
+
Use as library try
|
104
|
+
|
105
|
+
```ruby
|
106
|
+
require 'mp4_renamer'
|
107
|
+
include Mp4Renamer
|
108
|
+
# then call the appropriate functions
|
109
|
+
```
|
110
|
+
|
111
|
+
### Contributing
|
112
|
+
|
113
|
+
1. Fork it
|
114
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
115
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
116
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
117
|
+
5. Create new Pull Request
|
118
|
+
|
119
|
+
[Thor]: https://github.com/erikhuda/thor
|
120
|
+
[Minitest]: https://github.com/seattlerb/minitest
|
121
|
+
[RSpec]: https://github.com/rspec
|
122
|
+
[Guard]: https://github.com/guard/guard
|
123
|
+
[Yard]: https://github.com/lsegal/yard
|
124
|
+
[Pry]: https://github.com/pry/pry
|
125
|
+
[Rubocop]: https://github.com/bbatsov/rubocop
|
126
|
+
[Grit]: https://github.com/mojombo/grit
|
127
|
+
[filename_cleaner]: https://github.com/agilecreativity/filename_cleaner
|
data/Rakefile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rake/testtask'
|
3
|
+
project_name = 'mp4_renamer'
|
4
|
+
Rake::TestTask.new do |t|
|
5
|
+
t.libs << "lib/#{project_name}"
|
6
|
+
t.test_files = FileList["test/lib/#{project_name}/test_*.rb"]
|
7
|
+
t.verbose = true
|
8
|
+
end
|
9
|
+
|
10
|
+
task default: [:test, :rubocop]
|
11
|
+
task :pry do
|
12
|
+
require 'pry'
|
13
|
+
require 'awesome_print'
|
14
|
+
require_relative 'lib/mp4_renamer'
|
15
|
+
include Mp4Renamer
|
16
|
+
ARGV.clear
|
17
|
+
Pry.start
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'rubocop/rake_task'
|
21
|
+
desc 'Run RuboCop on the lib directory'
|
22
|
+
RuboCop::RakeTask.new(:rubocop) do |task|
|
23
|
+
task.patterns = ['lib/**/*.rb']
|
24
|
+
# only show the files with failures
|
25
|
+
task.formatters = ['files']
|
26
|
+
# don't abort rake on failure
|
27
|
+
task.fail_on_error = false
|
28
|
+
end
|
data/bin/mp4_renamer
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require_relative '../lib/mp4_renamer'
|
3
|
+
include Mp4Renamer
|
4
|
+
# To get the help for your gem uncomment the next line
|
5
|
+
# Mp4Renamer::CLI.start(ARGV)
|
6
|
+
# and run the following command
|
7
|
+
# $./bin/mp4_renamer help execute
|
8
|
+
|
9
|
+
if ARGV.empty?
|
10
|
+
Mp4Renamer::CLI.start(%w[usage])
|
11
|
+
else
|
12
|
+
Mp4Renamer::CLI.start(%w[execute].concat(ARGV))
|
13
|
+
end
|
data/fixtures/.gitkeep
ADDED
File without changes
|
data/fixtures/01.mp4
ADDED
Binary file
|
data/fixtures/02.m4a
ADDED
Binary file
|
data/fixtures/faac.m4a
ADDED
Binary file
|
data/fixtures/iTunes.m4a
ADDED
Binary file
|
Binary file
|
data/fixtures/nero.mp4
ADDED
Binary file
|
data/fixtures/real.m4a
ADDED
Binary file
|
data/lib/mp4_renamer.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
require 'active_support/core_ext/object/blank'
|
3
|
+
require 'active_support/core_ext/hash/keys'
|
4
|
+
require 'thor'
|
5
|
+
require 'fileutils'
|
6
|
+
require 'mp4info'
|
7
|
+
require 'code_lister'
|
8
|
+
|
9
|
+
require_relative 'mp4_renamer/version'
|
10
|
+
require_relative 'mp4_renamer/cli'
|
11
|
+
require_relative 'mp4_renamer/renamer'
|
12
|
+
include Mp4Renamer
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module Mp4Renamer
|
2
|
+
class CLI < Thor
|
3
|
+
desc 'execute', 'Execute the main program'
|
4
|
+
method_option "base_dir",
|
5
|
+
aliases: '-b',
|
6
|
+
desc: 'Starting directory',
|
7
|
+
default: File.expand_path(".")
|
8
|
+
method_option 'recursive',
|
9
|
+
aliases: '-r',
|
10
|
+
desc: 'Perform the operation recursively',
|
11
|
+
default: true
|
12
|
+
method_option :commit,
|
13
|
+
type: :boolean,
|
14
|
+
aliases: "-c",
|
15
|
+
desc: "Commit your changes",
|
16
|
+
default: false
|
17
|
+
method_option 'version',
|
18
|
+
type: :boolean,
|
19
|
+
aliases: '-v',
|
20
|
+
desc: 'Display version number',
|
21
|
+
default: false
|
22
|
+
def execute
|
23
|
+
opts = options.symbolize_keys
|
24
|
+
if opts[:version]
|
25
|
+
puts "You are using Mp4Renamer version #{Mp4Renamer::VERSION}"
|
26
|
+
exit
|
27
|
+
end
|
28
|
+
process(opts)
|
29
|
+
end
|
30
|
+
|
31
|
+
desc 'usage', 'Display help screen'
|
32
|
+
def usage
|
33
|
+
puts <<-EOS
|
34
|
+
Usage:
|
35
|
+
mp4_renamer [options]
|
36
|
+
|
37
|
+
Options:
|
38
|
+
-b, [--base-dir=BASE_DIR] # Starting directory
|
39
|
+
# Default: . (current directory)
|
40
|
+
-r, [--recursive=RECURSIVE] # Perform the operation recursively
|
41
|
+
# Default: true
|
42
|
+
-c, [--commit], [--no-commit] # Commit your changes
|
43
|
+
# Default: --no-commit
|
44
|
+
-v, [--version], [--no-version] # Display version number
|
45
|
+
# Default: --no-version
|
46
|
+
|
47
|
+
Execute the main program
|
48
|
+
EOS
|
49
|
+
end
|
50
|
+
|
51
|
+
default_task :usage
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def process(opts = {})
|
56
|
+
puts "FYI: your options #{opts.inspect}"
|
57
|
+
# Note: currently `mp4info` gem supports only two extensions
|
58
|
+
opts.merge!(exts: %w(mp4 m4a))
|
59
|
+
files = CodeLister.files(opts)
|
60
|
+
|
61
|
+
if files.empty?
|
62
|
+
puts "No files found for your options #{opts}"
|
63
|
+
return
|
64
|
+
end
|
65
|
+
|
66
|
+
renamer = Renamer.new(opts[:commit])
|
67
|
+
unless opts[:commit]
|
68
|
+
puts '-----------------------------------------------------------------------'
|
69
|
+
puts 'FYI: this is a dry-run only, to commit your changes use --commit option'
|
70
|
+
puts '-----------------------------------------------------------------------'
|
71
|
+
end
|
72
|
+
files.each do |file|
|
73
|
+
renamer.rename(file)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
#require 'fileutils'
|
2
|
+
module Mp4Renamer
|
3
|
+
module Errors
|
4
|
+
InvalidInputFileError = Class.new(StandardError)
|
5
|
+
MetadataNotAvailableError = Class.new(StandardError)
|
6
|
+
end
|
7
|
+
|
8
|
+
class Renamer
|
9
|
+
attr_reader :commit
|
10
|
+
|
11
|
+
# Initialization code
|
12
|
+
#
|
13
|
+
# @param [Boolean] commit the flag to indicate if the operation is to be executed
|
14
|
+
def initialize(commit = false)
|
15
|
+
@commit = commit
|
16
|
+
end
|
17
|
+
|
18
|
+
# Rename the input mp4 file and append the track time to the end
|
19
|
+
#
|
20
|
+
# @param [String] filename the input file
|
21
|
+
# @param [String] sep_string the separator string to use default to '_' underscore
|
22
|
+
# @raise [Errors::InvalidInputFileError] if the file is not valid or not readable
|
23
|
+
# @example
|
24
|
+
# # if the running time for the `sample.mp4` is '06:10' minutes
|
25
|
+
# rename("/path/to/sample.mp4") #=> will rename the file to '/path/to/sample_06.10.mp4'
|
26
|
+
# rename("/path/to/bad-input-file.mp4") #=> will raise error
|
27
|
+
def rename(filename, sep_string = '_')
|
28
|
+
raise Errors::InvalidInputFileError unless File.exist?(filename) && File.readable?(filename)
|
29
|
+
puts "FYI: input file : #{filename}"
|
30
|
+
info = MP4Info.open(filename)
|
31
|
+
|
32
|
+
# e.g. Other useful information that may be used if applicable
|
33
|
+
# * SECS - Total seconds, rounded to nearest second
|
34
|
+
# * MM - Minutes
|
35
|
+
# * SS - Leftover seconds
|
36
|
+
# * MS - Leftover milliseconds, rounded to nearest millisecond
|
37
|
+
# * TIME - Time in MM:SS, rounded to nearest second
|
38
|
+
# Note: info.TIME always available? if not we need to ignore the operation
|
39
|
+
# Or just skip the file?
|
40
|
+
raise Errors::MetadataNotAvailableError unless info.TIME
|
41
|
+
|
42
|
+
running_time = info.TIME.gsub(":", sep_string)
|
43
|
+
|
44
|
+
base_name = File.basename(filename, '.*') # 'sample01'
|
45
|
+
ext_name = File.extname(filename) # '.mp4'
|
46
|
+
dir_name = File.dirname(filename) # '/path/to/this/sample'
|
47
|
+
|
48
|
+
new_name = "#{base_name}#{sep_string}#{running_time}#{ext_name}"
|
49
|
+
output_file = [ dir_name, new_name ].join(File::SEPARATOR)
|
50
|
+
# now let rename the file
|
51
|
+
FileUtils.mv filename, output_file if commit
|
52
|
+
|
53
|
+
puts "FYI: output file: #{output_file}"
|
54
|
+
output_file
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/mp4_renamer.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'mp4_renamer/version'
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'mp4_renamer'
|
7
|
+
spec.version = Mp4Renamer::VERSION
|
8
|
+
spec.authors = ['Burin Choomnuan']
|
9
|
+
spec.email = ['agilecreativity@gmail.com']
|
10
|
+
spec.summary = %q{Simple gem to rename mp4 and m4a files by adding running time to the filename using embeded metadata}
|
11
|
+
spec.description = %q{Rename the mp4 and m4a files by adding the running time to the end of the filename}
|
12
|
+
spec.homepage = 'https://github.com/agilecreativity/mp4_renamer'
|
13
|
+
spec.required_ruby_version = ">= 1.9.3"
|
14
|
+
spec.license = 'MIT'
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
|
20
|
+
spec.add_runtime_dependency 'activesupport-core-ext', '~> 4.0.0.2'
|
21
|
+
spec.add_runtime_dependency 'thor', '~> 0.19.1'
|
22
|
+
spec.add_runtime_dependency 'mp4info', '~> 1.7.3'
|
23
|
+
spec.add_runtime_dependency 'code_lister'
|
24
|
+
|
25
|
+
spec.add_development_dependency 'awesome_print', '~> 1.2.0'
|
26
|
+
spec.add_development_dependency 'bundler', '~> 1.7.3'
|
27
|
+
spec.add_development_dependency 'gem-ctags', '~> 1.0.6'
|
28
|
+
spec.add_development_dependency 'guard', '~> 2.6.1'
|
29
|
+
spec.add_development_dependency 'guard-minitest', '~> 2.3.1'
|
30
|
+
spec.add_development_dependency 'minitest', '~> 5.4.0'
|
31
|
+
spec.add_development_dependency 'minitest-spec-context', '~> 0.0.3'
|
32
|
+
spec.add_development_dependency 'pry', '~> 0.10.0'
|
33
|
+
spec.add_development_dependency 'rake', '~> 10.3.2'
|
34
|
+
spec.add_development_dependency 'rubocop', '~> 0.24.0'
|
35
|
+
spec.add_development_dependency 'yard', '~> 0.8.7'
|
36
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
module Mp4Renamer
|
3
|
+
class FixtureHelper
|
4
|
+
attr_reader :fixture_files,
|
5
|
+
:fixtures_dir,
|
6
|
+
:sample_files
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@fixtures_dir = File.expand_path("../../../../fixtures", __FILE__)
|
10
|
+
@fixture_files = %w(01.mp4 02.m4a).map { |file| [fixtures_dir, file].join(File::SEPARATOR) }
|
11
|
+
@sample_files = fixture_files.map { |file| sample_file(file) }
|
12
|
+
end
|
13
|
+
|
14
|
+
def setup
|
15
|
+
fixture_files.each do |file|
|
16
|
+
FileUtils.cp file, sample_file(file)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def teardown
|
21
|
+
fixture_files.each do |file|
|
22
|
+
FileUtils.rm_rf sample_file(file)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def sample_file(file)
|
29
|
+
[fixtures_dir, "sample_#{File.basename(file, '.*')}#{File.extname(file)}"].join(File::SEPARATOR)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
if __FILE__ == $0
|
35
|
+
require 'pry'
|
36
|
+
require 'awesome_print'
|
37
|
+
include Mp4Renamer
|
38
|
+
|
39
|
+
helper = FixtureHelper.new
|
40
|
+
|
41
|
+
helper.setup
|
42
|
+
samples = helper.sample_files
|
43
|
+
puts samples
|
44
|
+
helper.teardown
|
45
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
describe Mp4Renamer do
|
3
|
+
let :renamer do
|
4
|
+
Renamer.new
|
5
|
+
end
|
6
|
+
|
7
|
+
let :helper do
|
8
|
+
FixtureHelper.new
|
9
|
+
end
|
10
|
+
|
11
|
+
before do
|
12
|
+
helper.setup
|
13
|
+
end
|
14
|
+
|
15
|
+
after do
|
16
|
+
helper.teardown
|
17
|
+
# remove the file that we rename also if after the steps
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#rename' do
|
21
|
+
it 'renames the file if metadata is valailable' do
|
22
|
+
helper.sample_files.each do |file|
|
23
|
+
result = renamer.rename(file)
|
24
|
+
# the result must be available
|
25
|
+
assert(result)
|
26
|
+
# cleanup after each use
|
27
|
+
FileUtils.rm_rf result
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'minitest'
|
2
|
+
require 'minitest/autorun'
|
3
|
+
require 'minitest/pride'
|
4
|
+
require 'minitest-spec-context'
|
5
|
+
require 'pry'
|
6
|
+
require 'awesome_print'
|
7
|
+
require_relative '../lib/mp4_renamer'
|
8
|
+
require_relative './lib/mp4_renamer/fixture_helper'
|
9
|
+
include Mp4Renamer
|
metadata
ADDED
@@ -0,0 +1,287 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mp4_renamer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Burin Choomnuan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-09-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport-core-ext
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.0.0.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.0.0.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: thor
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.19.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.19.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: mp4info
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.7.3
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.7.3
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: code_lister
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: awesome_print
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.2.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.2.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: bundler
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.7.3
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.7.3
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: gem-ctags
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 1.0.6
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 1.0.6
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: guard
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 2.6.1
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 2.6.1
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: guard-minitest
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 2.3.1
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 2.3.1
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: minitest
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 5.4.0
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 5.4.0
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: minitest-spec-context
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: 0.0.3
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: 0.0.3
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: pry
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - "~>"
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: 0.10.0
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - "~>"
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: 0.10.0
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: rake
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - "~>"
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: 10.3.2
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - "~>"
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: 10.3.2
|
195
|
+
- !ruby/object:Gem::Dependency
|
196
|
+
name: rubocop
|
197
|
+
requirement: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - "~>"
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: 0.24.0
|
202
|
+
type: :development
|
203
|
+
prerelease: false
|
204
|
+
version_requirements: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - "~>"
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: 0.24.0
|
209
|
+
- !ruby/object:Gem::Dependency
|
210
|
+
name: yard
|
211
|
+
requirement: !ruby/object:Gem::Requirement
|
212
|
+
requirements:
|
213
|
+
- - "~>"
|
214
|
+
- !ruby/object:Gem::Version
|
215
|
+
version: 0.8.7
|
216
|
+
type: :development
|
217
|
+
prerelease: false
|
218
|
+
version_requirements: !ruby/object:Gem::Requirement
|
219
|
+
requirements:
|
220
|
+
- - "~>"
|
221
|
+
- !ruby/object:Gem::Version
|
222
|
+
version: 0.8.7
|
223
|
+
description: Rename the mp4 and m4a files by adding the running time to the end of
|
224
|
+
the filename
|
225
|
+
email:
|
226
|
+
- agilecreativity@gmail.com
|
227
|
+
executables:
|
228
|
+
- mp4_renamer
|
229
|
+
extensions: []
|
230
|
+
extra_rdoc_files: []
|
231
|
+
files:
|
232
|
+
- ".gitignore"
|
233
|
+
- ".rubocop.yml"
|
234
|
+
- ".yardopts"
|
235
|
+
- CHANGELOGS.md
|
236
|
+
- Gemfile
|
237
|
+
- Guardfile
|
238
|
+
- LICENSE
|
239
|
+
- README.md
|
240
|
+
- Rakefile
|
241
|
+
- bin/mp4_renamer
|
242
|
+
- fixtures/.gitkeep
|
243
|
+
- fixtures/01.mp4
|
244
|
+
- fixtures/02.m4a
|
245
|
+
- fixtures/faac.m4a
|
246
|
+
- fixtures/iTunes.m4a
|
247
|
+
- fixtures/iTunes_utf8.m4a
|
248
|
+
- fixtures/nero.mp4
|
249
|
+
- fixtures/real.m4a
|
250
|
+
- lib/mp4_renamer.rb
|
251
|
+
- lib/mp4_renamer/cli.rb
|
252
|
+
- lib/mp4_renamer/renamer.rb
|
253
|
+
- lib/mp4_renamer/version.rb
|
254
|
+
- mp4_renamer.gemspec
|
255
|
+
- test/lib/mp4_renamer/fixture_helper.rb
|
256
|
+
- test/lib/mp4_renamer/test_renamer.rb
|
257
|
+
- test/test_helper.rb
|
258
|
+
homepage: https://github.com/agilecreativity/mp4_renamer
|
259
|
+
licenses:
|
260
|
+
- MIT
|
261
|
+
metadata: {}
|
262
|
+
post_install_message:
|
263
|
+
rdoc_options: []
|
264
|
+
require_paths:
|
265
|
+
- lib
|
266
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
267
|
+
requirements:
|
268
|
+
- - ">="
|
269
|
+
- !ruby/object:Gem::Version
|
270
|
+
version: 1.9.3
|
271
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
272
|
+
requirements:
|
273
|
+
- - ">="
|
274
|
+
- !ruby/object:Gem::Version
|
275
|
+
version: '0'
|
276
|
+
requirements: []
|
277
|
+
rubyforge_project:
|
278
|
+
rubygems_version: 2.2.2
|
279
|
+
signing_key:
|
280
|
+
specification_version: 4
|
281
|
+
summary: Simple gem to rename mp4 and m4a files by adding running time to the filename
|
282
|
+
using embeded metadata
|
283
|
+
test_files:
|
284
|
+
- test/lib/mp4_renamer/fixture_helper.rb
|
285
|
+
- test/lib/mp4_renamer/test_renamer.rb
|
286
|
+
- test/test_helper.rb
|
287
|
+
has_rdoc:
|