Multimedia scripts
Last update
2024-09-05
2024-09-05
«scripts per organizzare i files multimediali a suoceri e moglie»
MOGLIE / ANDROID
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 | # ----- FOTO ------------------------------------------------------------------- # resize f.jpg to _f.jpg ruby -e '%w{fileutils shellwords}.each{|l| require l}; lista=Dir["**/*"].grep(/\.jpg/i).sort; lista.each_with_index{|f,i| '\ 'puts "#{((i+1)/lista.size.to_f*100).to_i}%\t#{f}"; next if File.basename(f).start_with?("_"); system %Q[ '\ 'vips jpegsave #{f.shellescape} /tmp/rz.jpg --Q 80 && '\ 'jhead -autorot /tmp/rz.jpg && '\ 'mv /tmp/rz.jpg #{File.dirname(f).shellescape}/_#{File.basename(f).shellescape} && '\ 'rm -f #{f.shellescape} || echo ERRORE ] }' # rename by exif/file date ruby -e 'lista=Dir["**/*"].grep(/\.jpg/i).sort; lista.each_with_index{|f,i| '\ 'print "#{((i+1)/lista.size.to_f*100).to_i}%\t"; '\ 'system %Q[jhead -n"%Y-%m-%d_%H-%M-%S" "#{f}"] }' ## OR rename _f.jpg to f.jpg #ruby -e 'lista=Dir["**/*"].grep(/\.jpg/i).sort; lista.each_with_index{|f,i| '\ #'puts "#{((i+1)/lista.size.to_f*100).to_i}%\t#{f}"; next unless File.basename(f).start_with?("_"); '\ #'File.rename(f, File.join(File.dirname(f), File.basename(f).sub(/^_/, ""))) }' # crea sottocartelle foto e video (per ogni cartella avente files video) ruby -e 'Dir["**/*"].grep_v(/\.jpg/i).map{|f| File.dirname(f) if File.file?(f) }.compact.sort.uniq.each{|d| '\ 'Dir.chdir(d){ files = Dir["*"]; system "mkdir -p foto video"; '\ 'files.each{|f| dst = (f =~ /\.jpg/i ? :foto : :video); File.rename(f, "#{dst}/#{f}") } } }' # zippa cartelle di sole foto ruby -e 'require "shellwords"; Dir["**/*"].grep(/\.jpg/i).map{|f| File.dirname(f) }.compact.sort.uniq.each{|d| '\ 'puts d; Dir.chdir(File.join d, ".."){ n=File.basename(d); system "zip -r #{n.shellescape}.zip #{n.shellescape} && rm -rf #{n.shellescape}" } }' # ----- AUDIO ------------------------------------------------------------------ # converti video neri in MP3 => ffmpeg -i in.mp4 -ab 128k out.mp3 mdkir audio && cd audio for i in *.mp4; ffmpeg -i $i -ab 128k (string replace mp4 mp3 $i); end # fish #for i in *.mp4; do ffmpeg -i "$i" -ab 128k "${i%.*}.mp3"; done # bash rm -f *.mp4 # ----- VIDEO ------------------------------------------------------------------ # converti video MP4 in AVI/h264 for i in (find -type f -iname "*.mp4" -printf '%s\t%p\n' | sort -n | cut -f 2) echo $i vid2all -l -v 2048 -a 192 --no-expand --no-resize $i /mnt/ramd/out.avi \ && mv /mnt/ramd/out.avi (string replace -i mp4 avi $i) \ || touch (string replace -i mp4 ERR $i) end find -type f -name "*.ERR" # sposta tutti gli MP4 for i in (find -type f -iname "*.mp4"|sed -r 's/^..//'); mv -i $i (echo $i|sed -r 's/ /_/g ; s/\//--/g'); end |
SUOCERI / WINDOWS
external tools
- ffmpeg for windows
- jhead
- VisiPics photo duplicate finder
- WinDirStat folder tree size
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 |
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 |