mp4_renamer 0.1.2 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 85a401c7e8d3a1f27979b44a367d79be5f8388c7
4
- data.tar.gz: f89ba0f52429d393912622ac28b62092468f503c
3
+ metadata.gz: 4b2d83a264e78e6bfdc8271335e258b4b51a4dd2
4
+ data.tar.gz: 09d48379ff14f82422283c1754d8aa201747325b
5
5
  SHA512:
6
- metadata.gz: 83f2e63c617eccb1576efe26ba8d977fda82f42a65659e9350da4028defe24e3510c5bdfb1e3fdbe9e1591d8bc77ad59b2334fb1d645a2d9732aaa188608a0f9
7
- data.tar.gz: b1ec31c2d9b9a0085fffe24964839f5f7f544c31e5aebac6e42847ca1093b8ebf0d9be3548a8f07850a99dbf3c09bc40944f6ae0a01ef82305c49fe16bc4245e
6
+ metadata.gz: b1673264497ba7318dc2d5c076e72121666f4cfa7006d81751add821718ebfaf5f972c6e90f4e297848dc64f0f157cdce61020a4210b8cacd50725ab803343d5
7
+ data.tar.gz: 38e9c35e52f0ab7ae5697a1a0a2e8869fd2bdf7ec27998ad8a8921e808d4d95ffd42d441b4b99dfe99af2b1d7de2e9e21773c26327909251c6812f9ec5fa3673
data/CHANGELOGS.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ### Changelogs
2
2
 
3
+ #### 0.1.3
4
+
5
+ - Prevent the files from being rename more than once
6
+
3
7
  #### 0.1.2
4
8
 
5
9
  - Code cleanup
data/Gemfile CHANGED
@@ -1,3 +1,2 @@
1
1
  source 'https://rubygems.org'
2
- gem 'pry'
3
2
  gemspec
@@ -20,7 +20,8 @@ module Mp4Renamer
20
20
  # @param [String] sep_string the separator string to use default to '_' underscore
21
21
  # @raise [Errors::InvalidInputFileError] if the file is not valid or not readable
22
22
  # @example
23
- # # if the running time for the `sample.mp4` is '06:10' minutes
23
+ # If the running time for the `sample.mp4` is '06:10' minutes
24
+ #
24
25
  # rename("/path/to/sample.mp4") #=> will rename the file to '/path/to/sample_06.10.mp4'
25
26
  # rename("/path/to/bad-input-file.mp4") #=> will raise error
26
27
  def rename(filename, sep_string = '_')
@@ -46,11 +47,25 @@ module Mp4Renamer
46
47
 
47
48
  new_name = "#{base_name}#{sep_string}#{running_time}#{ext_name}"
48
49
  output_file = [ dir_name, new_name ].join(File::SEPARATOR)
49
- # now let rename the file
50
- FileUtils.mv filename, output_file if commit
51
50
 
52
- puts "FYI: output file: #{output_file}"
51
+ if rename_once?(output_file) || File.exist?(output_file)
52
+ puts "FYI: output file: #{filename} already exist, no action required!"
53
+ else
54
+ FileUtils.mv filename, output_file if commit
55
+ puts "FYI: output file: #{output_file}"
56
+ end
53
57
  output_file
54
58
  end
59
+
60
+ # Return true if the file has already been renamed
61
+ # @param [String] filename the input file name
62
+ # @example
63
+ # rename_once?("some_file.mp4") == false
64
+ # rename_once?("some_file_12_34.mp4") == false
65
+ # rename_once?("some_file_12_34_12_34.mp4") == true
66
+ def rename_once?(filename)
67
+ basename = File.basename(filename, File.extname(filename))
68
+ basename.match(/^(.*)_(\d+)_(\d+)_\2_\3$/)
69
+ end
55
70
  end
56
71
  end
@@ -1,3 +1,3 @@
1
1
  module Mp4Renamer
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
data/mp4_renamer.gemspec CHANGED
@@ -8,7 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.authors = ['Burin Choomnuan']
9
9
  spec.email = ['agilecreativity@gmail.com']
10
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}
11
+ spec.description = %q{Rename the mp4 and m4a files by adding the running time to the end of the filename
12
+ TL;DR; rename 'some_media_file.mp4' to 'media_file_12_34.mp4' if the running time is '12:34' minutes}
12
13
  spec.homepage = 'https://github.com/agilecreativity/mp4_renamer'
13
14
  spec.required_ruby_version = ">= 1.9.3"
14
15
  spec.license = 'MIT'
@@ -30,6 +31,7 @@ Gem::Specification.new do |spec|
30
31
  spec.add_development_dependency 'minitest', '~> 5.4.0'
31
32
  spec.add_development_dependency 'minitest-spec-context', '~> 0.0.3'
32
33
  spec.add_development_dependency 'pry', '~> 0.10.0'
34
+ spec.add_development_dependency 'pry-byebug', '~> 1.3.3' if RUBY_VERSION >= '2.0.0'
33
35
  spec.add_development_dependency 'rake', '~> 10.3.2'
34
36
  spec.add_development_dependency 'rubocop', '~> 0.24.0'
35
37
  spec.add_development_dependency 'yard', '~> 0.8.7'
@@ -28,4 +28,15 @@ describe Mp4Renamer do
28
28
  end
29
29
  end
30
30
  end
31
+
32
+ describe '#rename_once?' do
33
+ it 'returns false if not already rename' do
34
+ refute(renamer.rename_once?('sample.mp4'))
35
+ refute(renamer.rename_once?('sample_12_34.mp4'))
36
+ end
37
+
38
+ it 'returns true if already rename' do
39
+ assert(renamer.rename_once?('sample_12_34_12_34.mp4'))
40
+ end
41
+ end
31
42
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mp4_renamer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Burin Choomnuan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-21 00:00:00.000000000 Z
11
+ date: 2014-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport-core-ext
@@ -178,6 +178,20 @@ dependencies:
178
178
  - - "~>"
179
179
  - !ruby/object:Gem::Version
180
180
  version: 0.10.0
181
+ - !ruby/object:Gem::Dependency
182
+ name: pry-byebug
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - "~>"
186
+ - !ruby/object:Gem::Version
187
+ version: 1.3.3
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - "~>"
193
+ - !ruby/object:Gem::Version
194
+ version: 1.3.3
181
195
  - !ruby/object:Gem::Dependency
182
196
  name: rake
183
197
  requirement: !ruby/object:Gem::Requirement
@@ -220,8 +234,9 @@ dependencies:
220
234
  - - "~>"
221
235
  - !ruby/object:Gem::Version
222
236
  version: 0.8.7
223
- description: Rename the mp4 and m4a files by adding the running time to the end of
224
- the filename
237
+ description: |-
238
+ Rename the mp4 and m4a files by adding the running time to the end of the filename
239
+ TL;DR; rename 'some_media_file.mp4' to 'media_file_12_34.mp4' if the running time is '12:34' minutes
225
240
  email:
226
241
  - agilecreativity@gmail.com
227
242
  executables: