Multimedia scripts for windows
mouse 1317 · person cloud · link
Last update
2024-01-14
2024
01-14
«scripts per organizzare i files multimediali ai suoceri»

external tools

comprimi_media

1
2
3
4
5
6
7
8
9
10
11
#!/bin/env ruby
dirs = %x[ find -mindepth 1 -maxdepth 1 -type d ].split("\n").sort

dirs.each do |d|
  puts "===== CARTELLA [ #{d} ] ====="
  print 'foto : '; system 'ls|egrep -i "(jpe*g|png|heic)$"|wc -l', chdir: d
  print 'video: '; system 'ls|egrep -i "(mp4|mov|avi|mpeg|hevc)$"|wc -l', chdir: d
  system 'comprimi_media.single', chdir: d
end

puts "\n\nFINE"

comprimi_media.single

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/env ruby

%w{ shellwords FileUtils progressbar }.each{|l| require l }

pb_opts = { progress_mark: '#', remainder_mark: '_', length: 79,
            starting_at: 0, format: '%t: %J
[%B] %e'
} all_files = Dir['*'].sort all_files.grep(/\.(aae)$/i).each{|f| FileUtils.rm_f f } re_images = /\.(jpe*g|png|heic)$/i files = all_files.grep(re_images) if files.size > 0 puts '' FileUtils.mkdir_p '_fatti' FileUtils.mkdir_p 'foto' pb = ProgressBar.create pb_opts.merge(title: "#{files.size} immagini", total: files.size) files.each do |f| pb.log " => #{f}" fout = f.sub(re_images, '.jpg') system %Q| convert -quality 80 #{f.shellescape} foto/#{fout.shellescape} | FileUtils.mv f, "_fatti/#{f}" if $?.to_i == 0 pb.increment end end re_videos = /\.(mp4|mov|avi|mpeg|hevc)$/i files = all_files.grep(re_videos) if files.size > 0 puts '' FileUtils.mkdir_p '_fatti' FileUtils.mkdir_p 'video' pb = ProgressBar.create pb_opts.merge(title: "#{files.size} video", total: files.size) files.each do |f| pb.log " => #{f}" fout = f.sub(re_videos, '.mp4') # https://superuser.com/questions/326629/how-can-i-make-ffmpeg-be-quieter-less-verbose system %Q| ffmpeg -hide_banner -loglevel error -stats -i #{f.shellescape} -c:v libx264 -c:a libmp3lame -b:a 128k video/#{fout.shellescape} | FileUtils.mv f, "_fatti/#{f}" if $?.to_i == 0 pb.increment end end if Dir['*'].reject{|f| File.directory? f }.size == 0 # elinmina fatti se tutto e' andato a buon fine FileUtils.rm_rf '_fatti' # elimina l'unica cartella presente dopo averne spostato i files nel parent if Dir['*'].size == 1 dir = Dir['*'].first system "mv -i * ..", chdir: dir FileUtils.rm_rf dir if $?.to_i == 0 end end # mostra evntuali cartelle _fatti ancora presenti dirs = %x[ find -mindepth 1 -type d -name _fatti ].split("\n").sort.map{|d| File.dirname d[2,300] } if dirs.size > 0 puts "Cartelle da controllare:" puts dirs end

misc ruby

1
2
3
4
5
# rename_foto_by_ts
ruby -e 'Dir["**/*"].grep(/\.jpg/i).sort.each{|f| system %Q[jhead -n"%Y-%m-%d_%H-%M-%S" "#{f}"] }'

# enumerate files
Dir['*'].sort.each_with_index{|f, i| File.rename f, "#{'%04d' % (i+1)}.mp4"}; nil

misc shell

1
2
3
4
5
# PDF to JPG
ls *.pdf | sed -r 's/(.+).pdf/pdftoppm -jpeg \0 \L\1.jpg/' | sh

# lossless rotate JPG
jpegtran -rotate 90 in.jpg > out.jpg