media_trim 0.2.0 → 0.2.1

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
  SHA256:
3
- metadata.gz: 36ab2c24be1441d81a352ca71f72e7476e5bc748cde55da317fac140063c5a6d
4
- data.tar.gz: bb39ea9a3dd5b8e91da60dd6b6e64d1e03b31330647cfb5ec7666041d470ee89
3
+ metadata.gz: 37f7ed510ad90d35e85ef47e33fabf9d1994779512a6c6b4342c570e3a957048
4
+ data.tar.gz: b0f0aed439b2fe793be04f38ea30937a767f53c997bb1723c38d9b2357b23e63
5
5
  SHA512:
6
- metadata.gz: b5fa5f3e4634c0f04197744edf1c809a9ff139931af5ba6911b8098c5de37abe26f14b3353de3ae7468868f1435256549b025634e723d4973d8333abcd4ce0c9
7
- data.tar.gz: 21fa1ee01fa7b71392e2acd7f40a4b1e63ee69f6fcbc8300939b542974b39b4a76ec232ce02d4b8aca6d0e63000f6edc47a31e673af908721e3ab2b22163175f
6
+ metadata.gz: de4ee11b00dfc2067a94f1da192d76940ca09d1baacd8ce3ddb215444a0dd45c1a4aac93c46399432e5818aa76efba4bc2ccadaeb8f51bb317f707b40c8f456f
7
+ data.tar.gz: 1bdea1d74ba69994bfaf7452c1fe1fe6cd9b9c9ecb76530c45bfb640c5624ae55456ab3012cb39157778cb5fc4d0532003285285218b3a64702b0035926fbd71
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.2.1
4
+
5
+ * Added `spec.platform` to `media_trim.gemspec` because `RubyGems.org` now requires it
6
+ * Various Ruby syntax issues corrected
7
+
3
8
 
4
9
  ## 0.2.0
5
10
 
data/README.md CHANGED
@@ -69,7 +69,7 @@ When run as a command, output files are named by adding a `trim.` prefix to the
69
69
  e.g. `dir/trim.file.ext`.
70
70
  By default, the `trim` command does not overwrite pre-existing output files.
71
71
  When trimming is complete, the `trim` command displays the trimmed file,
72
- unless the `-q` option is specified.
72
+ unless the `-V` option is specified.
73
73
 
74
74
  `OPTIONS` are:
75
75
 
@@ -1,3 +1,3 @@
1
1
  module MediaTrimVersion
2
- VERSION = '0.2.0'.freeze
2
+ VERSION = '0.2.1'.freeze
3
3
  end
data/lib/trim_class.rb CHANGED
@@ -13,13 +13,26 @@ class MediaTrim
13
13
  end
14
14
 
15
15
  def self.time_format(elapsed_seconds)
16
- elapsed_time = elapsed_seconds.to_i
16
+ elapsed_time = elapsed_seconds.to_f
17
17
  hours = (elapsed_time / (60 * 60)).to_i
18
- minutes = ((elapsed_time - (hours * 60)) / 60).to_i
19
- seconds = elapsed_time - (hours * 60 * 60) - (minutes * 60)
18
+ remaining_after_hours = elapsed_time - (hours * 60 * 60)
19
+ minutes = (remaining_after_hours / 60).to_i
20
+ seconds = remaining_after_hours - (minutes * 60)
20
21
 
21
- result = "#{minutes.to_s.rjust 2, '0'}:#{seconds.to_s.delete_suffix('.0').rjust 2, '0'}"
22
- result = "#{hours}:#{result}}" unless hours.zero?
22
+ # Format seconds with proper padding
23
+ if seconds == seconds.to_i
24
+ # No decimal part
25
+ seconds_str = seconds.to_i.to_s.rjust(2, '0')
26
+ else
27
+ # Has decimal part
28
+ whole_seconds = seconds.to_i
29
+ decimal_part = seconds - whole_seconds
30
+ decimal_str = format('%.2f', decimal_part)[1..] # Remove leading "0" from "0.XX"
31
+ seconds_str = "#{whole_seconds.to_s.rjust(2, '0')}#{decimal_str}"
32
+ end
33
+
34
+ result = "#{minutes.to_s.rjust(2, '0')}:#{seconds_str}"
35
+ result = "#{hours}:#{result}" unless hours.zero?
23
36
  result
24
37
  end
25
38
 
@@ -52,9 +65,9 @@ class MediaTrim
52
65
  end
53
66
 
54
67
  def self.to_seconds(str)
55
- array = str.split(':').map(&:to_i).reverse
68
+ array = str.split(':').map(&:to_f).reverse
56
69
  case array.length
57
- when 1 then str.to_i
70
+ when 1 then str.to_f
58
71
  when 2 then array[0] + (array[1] * 60)
59
72
  when 3 then array[0] + (array[1] * 60) + (array[2] * 60 * 60)
60
73
  else raise TrimError, "Error: #{str} is not a valid time"
data/lib/trim_help.rb CHANGED
@@ -10,7 +10,7 @@ class MediaTrim
10
10
  - Can be used as a Ruby gem.
11
11
  - Installs the 'trim' command.
12
12
 
13
- When run as a command, output files are named by adding a 'trim.' prefix to the media file name, e.g. 'dir/trim.file.ext'.
13
+ When run as a command, output files are named by adding a 'trim.' prefix to the media file name, e.g., 'dir/trim.file.ext'.
14
14
  By default, the trim command does not overwrite pre-existing output files.
15
15
  When trimming is complete, the trim command displays the trimmed file, unless the -q option is specified
16
16
 
@@ -43,11 +43,11 @@ class MediaTrim
43
43
  trim demo/demo.mp4 3:25 for 6:10
44
44
 
45
45
  Need a way to figure out the start and stop times to trim a video?
46
- DJV is an excellent video viewer https://darbyjohnston.github.io/DJV/
46
+ DJV is an excellent video viewer. https://darbyjohnston.github.io/DJV/
47
47
  - allows frame-by-frame stepping
48
- - displays the current time reliabily
48
+ - displays the current time reliably
49
49
  - F/OSS
50
- - Mac, Windows, Linux
50
+ - Mac, Windows, and Linux
51
51
  - High quality
52
52
  END_HELP
53
53
  exit 1
data/lib/trim_main.rb CHANGED
@@ -1,37 +1,42 @@
1
- TrimError = Class.new StandardError # Define a new StandardError subclass
1
+ class TrimError < StandardError
2
+ end # Define a new StandardError subclass
2
3
 
3
4
  class MediaTrim
4
- attr_accessor :copy_filename, :fname, :interval, :msg_end, :overwrite, :quiet, :start, :view
5
+ attr_accessor :copy_filename, :debug, :fname, :interval, :msg_end, :overwrite, :quiet, :start, :view
5
6
 
6
7
  # @param to [String] end timecode; duration not supported for API
7
8
  def initialize(filename = nil, trimmed_filename = nil, start = '0', to = nil, **options)
8
9
  @fname = MediaTrim.expand_env(filename) if filename
9
10
  @copy_filename = MediaTrim.expand_env(trimmed_filename) if trimmed_filename
10
- @start = MediaTrim.time_format start
11
- @interval = ['-ss', MediaTrim.time_format(@start)]
11
+ @start = MediaTrim.time_format(MediaTrim.to_seconds(start))
12
+ @interval = ['-ss', @start]
13
+ @debug = options[:debug] || false
12
14
 
13
15
  @overwrite = options[:overwrite] ? '-y' : '-n'
14
16
  @quiet = options[:quiet].nil? || options[:quiet] ? ['-hide_banner', '-loglevel', 'error', '-nostats'] : []
15
- @view = options[:view].nil? ? true : options[:view]
17
+ @view = options[:view].nil? || options[:view]
16
18
 
17
19
  prepare(@start, to, mode: :timecode) if to
18
20
  end
19
21
 
20
22
  def options
21
23
  OptionParser.new do |opts|
22
- opts.banner = "Usage: #{$PROGRAM_NAME} [options]"
24
+ opts.banner = "Usage: #{$PROGRAM_NAME} [options] file start [[to|for] end]"
23
25
 
24
- opts.on('-f', '--[no-]@overwrite', 'Overwrite any previous output') do |f|
25
- @overwrite = f ? '-y' : '-n'
26
+ opts.on('-f', '--overwrite', 'Overwrite any previous output') do
27
+ @overwrite = '-y'
28
+ end
29
+ opts.on('-v', '--verbose', 'Run verbosely') do
30
+ @quiet = []
26
31
  end
27
- opts.on('-v', '--[no-]verbose', 'Run verbosely') do |v|
28
- @quiet = [] if v
32
+ opts.on('-h', '--help', 'Display help') do
33
+ MediaTrim.help
29
34
  end
30
- opts.on('-h', '', 'Display help') do |_|
31
- help
35
+ opts.on('-V', '--no-view', 'Do not view the trimmed file when complete') do
36
+ @view = false
32
37
  end
33
- opts.on('-V', '--[no-]@view', 'View ffmpeg output') do |v|
34
- @view = false if v
38
+ opts.on('-d', '--debug', 'Enable debug output') do
39
+ @debug = true
35
40
  end
36
41
  end.parse!
37
42
  end
@@ -49,7 +54,7 @@ class MediaTrim
49
54
  @copy_filename = "#{File.dirname @fname}/trim.#{original_filename}#{ext}"
50
55
 
51
56
  MediaTrim.help 'Please specify the time to @start trimming the video file from' unless argv[1]
52
- @start = MediaTrim.time_format argv[1]
57
+ @start = MediaTrim.time_format(MediaTrim.to_seconds(argv[1]))
53
58
 
54
59
  @interval = ['-ss', @start]
55
60
  @msg_end = ''
@@ -72,7 +77,7 @@ class MediaTrim
72
77
 
73
78
  def prepare(from, duration_or_timecode, mode: :duration)
74
79
  if mode == :duration
75
- timecode = MediaTrim.time_format duration_or_timecode
80
+ timecode = MediaTrim.time_format(MediaTrim.to_seconds(duration_or_timecode))
76
81
  time_end = MediaTrim.add_times from, timecode
77
82
  @interval += ['-t', time_end]
78
83
  @msg_end = " for a duration of #{timecode} (until #{time_end})"
data/media_trim.gemspec CHANGED
@@ -59,6 +59,7 @@ Gem::Specification.new do |spec|
59
59
  'source_code_uri' => host,
60
60
  }
61
61
  spec.name = 'media_trim'
62
+ spec.platform = Gem::Platform::RUBY
62
63
  spec.post_install_message = <<~END_MESSAGE
63
64
 
64
65
  Thanks for installing #{spec.name} v#{MediaTrimVersion::VERSION}!
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: media_trim
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Slinn
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2023-11-29 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: colorator
@@ -97,7 +96,7 @@ metadata:
97
96
  source_code_uri: https://github.com/mslinn/media_trim
98
97
  post_install_message: |2+
99
98
 
100
- Thanks for installing media_trim v0.2.0!
99
+ Thanks for installing media_trim v0.2.1!
101
100
 
102
101
  rdoc_options: []
103
102
  require_paths:
@@ -113,8 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
112
  - !ruby/object:Gem::Version
114
113
  version: '0'
115
114
  requirements: []
116
- rubygems_version: 3.3.7
117
- signing_key:
115
+ rubygems_version: 4.0.16
118
116
  specification_version: 4
119
117
  summary: Trim an audio or video file using ffmpeg
120
118
  test_files: []