aviglitch 0.2.0 → 0.2.2

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: 6bcaf49d8305bd36386f606954fe702468fc5196e30b0d5e4f3dea11f0bfb8a7
4
- data.tar.gz: a1ede07ce50e3005abcd505e501ddf8f73c18b0241d7b34834ac78781d76e389
3
+ metadata.gz: 1d39333c753326230a28e3ecde64dfee176af851c53fd1b185a10797e90bbdd0
4
+ data.tar.gz: dfb9e4b6613a38c7da422ac82ebf100c12bf84fee40cfc44d899950e547f13d6
5
5
  SHA512:
6
- metadata.gz: b9a0c0905f0131bec187618e48e7281eac79d01d6067a66dad82bafbc2c923d84bd7472738b147fc2866ee1f5ef14b1064556e05b7109a7ffef5a0c73370ec6f
7
- data.tar.gz: f698216510d97cf7713e14127cf75af8264c5c003fa876caed72e51168575eb75e0dba05930ff22c6a145c0da9a0967da9959dfc65d0276909e9db081ba6810c
6
+ metadata.gz: 9df626227e793840d861bd26510323d315024278bfd4dedc7a4d5a147aef2e92ccd5d7cb0564ad8b743e6c1d2c5fea70f9858c86fcefa4f2434869169df1a2c2
7
+ data.tar.gz: de1adf2790a8c7250e2db4f73bf45b7884b1f1797069ba05899b1f3cb5cd0930d89698ba7d9959099e73e15cd937f83bf3f86939528bdc4310cb4e3c6c82880e
@@ -1,35 +1,19 @@
1
- # This workflow uses actions that are not certified by GitHub.
2
- # They are provided by a third-party and are governed by
3
- # separate terms of service, privacy policy, and support
4
- # documentation.
5
- # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
- # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
-
8
1
  name: test
9
-
10
2
  on:
11
3
  push:
12
4
  branches: [ master ]
13
5
  pull_request:
14
6
  branches: [ master ]
15
-
16
7
  jobs:
17
8
  test:
18
-
19
9
  runs-on: ubuntu-latest
20
10
  strategy:
21
11
  matrix:
22
- ruby-version: ['2.6', '2.7', '3.0']
23
-
12
+ ruby-version: ['3.3']
24
13
  steps:
25
- - uses: actions/checkout@v2
26
- - name: Set up Ruby
27
- # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
28
- # change this to (see https://github.com/ruby/setup-ruby#versioning):
29
- # uses: ruby/setup-ruby@v1
30
- uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
14
+ - uses: actions/checkout@v4
15
+ - uses: ruby/setup-ruby@v1
31
16
  with:
32
17
  ruby-version: ${{ matrix.ruby-version }}
33
- bundler-cache: true # runs 'bundle install' and caches installed gems automatically
34
- - name: Run tests
35
- run: bundle exec rake
18
+ bundler-cache: true
19
+ - run: bundle exec rake
data/ChangeLog.md CHANGED
@@ -1,3 +1,9 @@
1
+ ### 0.2.2 / 2024-07-20
2
+
3
+ * Added option to set a custom directory for temporary files that internally duplicate input files.
4
+ * Also added an option for the custom temp directory in the datamosh cli.
5
+ * Some improvements regarding internal temporary files.
6
+
1
7
  ### 0.2.0 / 2021-09-13
2
8
 
3
9
  * Support for AVI2.0 formatted files. Now this library can handle files larger than 1GB.
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009-2021 ucnv
1
+ Copyright (c) 2009-2024 ucnv
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/bin/datamosh CHANGED
@@ -8,6 +8,7 @@ require 'aviglitch'
8
8
  output = './out.avi'
9
9
  all = false
10
10
  fake = false
11
+ tmpdir = nil
11
12
 
12
13
  opts = OptionParser.new do |opts|
13
14
  opts.banner = "datamosh - AviGlitch's datamoshing video generator."
@@ -28,10 +29,14 @@ opts = OptionParser.new do |opts|
28
29
  exit
29
30
  end
30
31
  end
32
+ opts.on("--tmpdir [DIR]", "Specify the temporary directory") do |dir|
33
+ tmpdir = dir
34
+ end
31
35
  opts.on_tail("-h", "--help", "Show this message") do
32
36
  puts opts
33
37
  exit
34
38
  end
39
+ opts.version = AviGlitch::VERSION
35
40
  end
36
41
 
37
42
  input = opts.parse!
@@ -48,7 +53,7 @@ else
48
53
  end
49
54
  end
50
55
 
51
- a = AviGlitch.open input.shift
56
+ a = AviGlitch.open input.shift, tmpdir: tmpdir
52
57
  unless fake
53
58
  a.glitch_with_index :keyframe do |frame, i|
54
59
  (!all && i == 0) ? frame : "" # keep the first frame
@@ -62,7 +67,7 @@ else
62
67
  end
63
68
 
64
69
  input.each do |file|
65
- b = AviGlitch.open file
70
+ b = AviGlitch.open file, tmpdir: tmpdir
66
71
  unless fake
67
72
  b.glitch :keyframe do |frame|
68
73
  ""
data/lib/aviglitch/avi.rb CHANGED
@@ -79,16 +79,22 @@ module AviGlitch
79
79
  # Object which represents RIFF structure.
80
80
  attr_accessor :riff
81
81
 
82
- attr_accessor :path, :movi #:nodoc:
82
+ attr_accessor :path, :movi, :tmpdir #:nodoc:
83
83
  protected :path, :path=, :movi, :movi=
84
84
 
85
85
  ##
86
- # Generates an instance with the necessary structure from the +path+.
86
+ # Generates an instance.
87
87
  def initialize path = nil
88
- return if path.nil?
88
+ return unless @movi.nil? # don't reconfigure the path when cloning
89
+ self.path = path unless path.nil?
90
+ end
91
+
92
+ ##
93
+ # Set +path+ of the source file.
94
+ def path= path #:nodoc:
89
95
  @path = path
90
96
  File.open(path, 'rb') do |io|
91
- @movi = Tempfile.new 'aviglitch', binmode: true
97
+ @movi = Tempfile.new 'aviglitch', @tmpdir, binmode: true
92
98
  @riff = []
93
99
  @indices = []
94
100
  @superidx = []
@@ -390,18 +396,19 @@ module AviGlitch
390
396
  end
391
397
 
392
398
  def initialize_copy avi #:nodoc:
393
- avi.path = @path.dup
394
- md = Marshal.dump @indices
395
- avi.indices = Marshal.load md
396
- md = Marshal.dump @riff
397
- avi.riff = Marshal.load md
398
- newmovi = Tempfile.new 'aviglitch', binmode: true
399
- movipos = @movi.pos
400
- @movi.rewind
401
- newmovi.print @movi.read
402
- @movi.pos = movipos
399
+ md = Marshal.dump avi.indices
400
+ @indices = Marshal.load md
401
+ md = Marshal.dump avi.riff
402
+ @riff = Marshal.load md
403
+ newmovi = Tempfile.new 'aviglitch-clone', @tmpdir, binmode: true
404
+ movipos = avi.movi.pos
405
+ avi.movi.rewind
406
+ while d = avi.movi.read(BUFFER_SIZE) do
407
+ newmovi.print d
408
+ end
409
+ avi.movi.pos = movipos
403
410
  newmovi.rewind
404
- avi.movi = newmovi
411
+ @movi = newmovi
405
412
  end
406
413
 
407
414
  def print_chunk io, chunk #:nodoc:
@@ -14,14 +14,16 @@ module AviGlitch
14
14
  # Creates a new instance of AviGlitch::Base, open the file and
15
15
  # make it ready to manipulate.
16
16
  # It requires +path+ as Pathname or an instance of AviGlirtch::Avi.
17
- def initialize path_or_object
17
+ def initialize path_or_object, tmpdir: nil
18
18
  if path_or_object.kind_of?(Avi)
19
19
  @avi = path_or_object
20
20
  else
21
21
  unless AviGlitch::Base.surely_formatted? path_or_object
22
22
  raise 'Unsupported file passed.'
23
23
  end
24
- @avi = Avi.new path_or_object
24
+ @avi = Avi.new
25
+ @avi.tmpdir = tmpdir
26
+ @avi.path = path_or_object
25
27
  end
26
28
  @frames = Frames.new @avi
27
29
  end
@@ -22,6 +22,7 @@ module AviGlitch
22
22
 
23
23
  ##
24
24
  # Creates a new AviGlitch::Frames object.
25
+ # It takes AviGlitch::Avi as an argument.
25
26
  def initialize avi
26
27
  @avi = avi
27
28
  end
@@ -31,7 +32,7 @@ module AviGlitch
31
32
  # It returns Enumerator if a block is not given.
32
33
  def each &block
33
34
  if block_given?
34
- Tempfile.open('temp', binmode: true) do |newmovi|
35
+ Tempfile.open('aviglitch-temp', @avi.tmpdir, binmode: true) do |newmovi|
35
36
  @avi.process_movi do |indices, movi|
36
37
  newindices = indices.select do |m|
37
38
  movi.pos = m[:offset] + 8 # 8 for id and size
@@ -136,6 +137,7 @@ module AviGlitch
136
137
  times.times do
137
138
  result.concat frames
138
139
  end
140
+ frames.terminate
139
141
  result
140
142
  end
141
143
 
@@ -175,7 +177,12 @@ module AviGlitch
175
177
  l = 1 if l.nil?
176
178
  tail = self.slice((b + l)..-1)
177
179
  self.clear
178
- self.concat head + tail
180
+ temp = head + tail
181
+ self.concat temp
182
+ temp.terminate
183
+ head.terminate
184
+ tail.terminate
185
+
179
186
  sliced
180
187
  end
181
188
 
@@ -199,6 +206,10 @@ module AviGlitch
199
206
 
200
207
  self.clear
201
208
  self.concat new_frames
209
+
210
+ new_frames.terminate
211
+ head.terminate
212
+ rest.terminate
202
213
  end
203
214
 
204
215
  ##
@@ -342,6 +353,7 @@ module AviGlitch
342
353
 
343
354
  self.clear
344
355
  self.concat new_frames
356
+ new_frames.terminate
345
357
  self
346
358
  end
347
359
 
@@ -369,6 +381,13 @@ module AviGlitch
369
381
  @avi == other.avi
370
382
  end
371
383
 
384
+ ##
385
+ # Closes the internal temp file explicitly. This instance becomes unusable.
386
+ def terminate
387
+ @avi.close
388
+ @avi = nil
389
+ end
390
+
372
391
  ##
373
392
  # Generates new AviGlitch::Base instance using self.
374
393
  def to_avi
data/lib/aviglitch.rb CHANGED
@@ -28,9 +28,16 @@ require 'aviglitch/frames'
28
28
  # end
29
29
  # avi.output '/path/to/broken.avi'
30
30
  #
31
+ # Since v0.2.2, it allows to specify the temporary directory. This library
32
+ # duplicates and processes a input file in the temporary directory, which
33
+ # by default is +Dir.tmpdir+. To specify the custom temporary directory, use
34
+ # +tmpdir:+ option, like:
35
+ #
36
+ # avi = AviGlitch.open '/path/to/your.avi', tmpdir: '/path/to/tmpdir'
37
+ #
31
38
  module AviGlitch
32
39
 
33
- VERSION = '0.2.0'
40
+ VERSION = '0.2.2'
34
41
 
35
42
  BUFFER_SIZE = 2 ** 24
36
43
 
@@ -38,11 +45,12 @@ module AviGlitch
38
45
  ##
39
46
  # Returns AviGlitch::Base instance.
40
47
  # It requires +path_or_frames+ as String or Pathname, or Frames instance.
41
- def open path_or_frames
48
+ # Additionally, it allows +tmpdir:+ as the internal temporary directory.
49
+ def open path_or_frames, tmpdir: nil
42
50
  if path_or_frames.kind_of?(Frames)
43
51
  path_or_frames.to_avi
44
52
  else
45
- AviGlitch::Base.new(Pathname(path_or_frames))
53
+ AviGlitch::Base.new(Pathname(path_or_frames), tmpdir: tmpdir)
46
54
  end
47
55
  end
48
56
  end
data/spec/avi2_spec.rb CHANGED
@@ -31,6 +31,7 @@ describe AviGlitch, 'AVI2.0' do
31
31
  n.times do
32
32
  fx = f[0..-1]
33
33
  f.concat fx
34
+ fx.terminate
34
35
  end
35
36
  f.to_avi.output @out
36
37
  b = AviGlitch.open @out
@@ -92,7 +92,7 @@ describe AviGlitch do
92
92
  }.should raise_error(IOError)
93
93
  end
94
94
 
95
- it 'can explicit close file' do
95
+ it 'can close the file explicitly' do
96
96
  avi = AviGlitch.open @in
97
97
  avi.close
98
98
  lambda {
@@ -160,7 +160,7 @@ describe AviGlitch do
160
160
  end
161
161
  end
162
162
 
163
- it 'should check if keyframes exist.' do
163
+ it 'should check if keyframes exist' do
164
164
  a = AviGlitch.open @in
165
165
  a.has_keyframe?.should be true
166
166
  a.glitch :keyframe do |f|
@@ -190,5 +190,24 @@ describe AviGlitch do
190
190
 
191
191
  expect(dc1).to eq(dc2)
192
192
  end
193
+
194
+ it 'can be set custom temp dir' do
195
+ custom_tmpdir = Pathname.new(OUTPUT_DIR) + 'custom_tmpdir'
196
+ Dir.mkdir custom_tmpdir unless File.exist? custom_tmpdir
197
+
198
+ c = Dir.glob((custom_tmpdir + '*').to_s).size
199
+ b = AviGlitch.open @in, tmpdir: custom_tmpdir
200
+ b2 = b.frames[0, 100].to_avi
201
+ b2.frames.each do |f|
202
+ Dir.glob((custom_tmpdir + '*').to_s).size.should >= c
203
+ end
204
+ end
205
+
206
+ it 'shoud raise an error when specified temp dir is not writable' do
207
+ custom_tmpdir = Pathname.new(OUTPUT_DIR) + 'not_dir'
208
+ lambda {
209
+ AviGlitch.open @in, tmpdir: custom_tmpdir
210
+ }.should raise_error(SystemCallError)
211
+ end
193
212
 
194
213
  end
data/spec/frames_spec.rb CHANGED
@@ -1,6 +1,9 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
- describe AviGlitch::Frames do
3
+ # Since Ruby 3.3.x, Windows frequently fails to close the Tempfile on GC.
4
+ # Although not a fatal error, it should be better to remove them manually in such cases.
5
+ # Now this spec is skipped in Windows because it could generate a lot of warning messages and undeleted temp files.
6
+ describe AviGlitch::Frames, :skip => Gem.win_platform? do
4
7
 
5
8
  before :all do
6
9
  AviGlitch::Frames.class_eval do
@@ -479,8 +482,7 @@ describe AviGlitch::Frames do
479
482
  expect(File.size(@out)).to be < File.size(@in)
480
483
  end
481
484
 
482
- it 'should use Enumerator as an external iterator',
483
- :skip => Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new('1.9.0') || RUBY_PLATFORM == 'java' do
485
+ it 'should use Enumerator as an external iterator' do
484
486
  a = AviGlitch.open @in
485
487
  e = a.frames.each
486
488
  expect {
data/spec/spec_helper.rb CHANGED
@@ -50,6 +50,10 @@ RSpec.configure do |config|
50
50
  end
51
51
 
52
52
  config.after(:each) do
53
- FileUtils.rm Dir.glob((OUTPUT_DIR + '*').to_s)
53
+ begin
54
+ FileUtils.rm_r Dir.glob((OUTPUT_DIR + '*').to_s)
55
+ rescue => e
56
+ # Sometimes windows can't remove files.
57
+ end
54
58
  end
55
59
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aviglitch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - ucnv
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-13 00:00:00.000000000 Z
11
+ date: 2024-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -103,7 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  - !ruby/object:Gem::Version
104
104
  version: '0'
105
105
  requirements: []
106
- rubygems_version: 3.2.22
106
+ rubygems_version: 3.5.11
107
107
  signing_key:
108
108
  specification_version: 4
109
109
  summary: A Ruby library to destroy your AVI files.