Created
April 11, 2014 22:29
-
-
Save HugoPoi/10506768 to your computer and use it in GitHub Desktop.
Rules for Maid file cleaner, bunch of rules to sorting Photorec output folder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Rules for Maid file cleaner, bunch of rules to sorting Photorec output folder. | |
# Maid Tool : https://github.com/benjaminoakes/maid | |
# PhotoRec Tool : http://www.cgsecurity.org/wiki/PhotoRec | |
# | |
# ----Help---- | |
# Get All extension in directory : find . -type f | perl -ne 'print $1 if m/\.([^.\/]+)$/' | sort -u | |
# ------------ | |
# Author: HugoPoi | |
# | |
# ----Notes---- | |
# The code behind is not best quality code, it's example to demonstrate possibilities | |
# with 2 ruby gems and a little bunch of codes. If you are a Ruby expert you must correct and clean this code. | |
# ------------- | |
require "id3tag" | |
recupDir = '/output/dir/of/photorec' | |
sortedDir = '/output/dir/for/sorted/files' | |
Maid.rules do | |
rule 'jpg > 10KB' do | |
dir(recupDir + '/*/*.jpg').each do |path| | |
andir = path.split('/') | |
ndir = andir[andir.length - 2] | |
if File.size(path) > 10000 | |
if !File.directory?(sortedDir + '/photos/' + ndir) | |
Dir.mkdir(sortedDir + '/photos/' + ndir) | |
end | |
move(path, sortedDir + '/photos/' + ndir) | |
end | |
end | |
end | |
rule 'doc,docx,pdf,xls,xlsx,ppt,pptx,odt,ods' do | |
(dir(recupDir + '/*/*.doc') + dir(recupDir + '/*/*.docx') + dir(recupDir + '/*/*.pdf') + dir(recupDir + '/*/*.xls') + dir(recupDir + '/*/*.xlsx') + dir(recupDir + '/*/*.ppt') + dir(recupDir + '/*/*.pptx') + dir(recupDir + '/*/*.odt') + dir(recupDir + '/*/*.ods')).each do |path| | |
andir = path.split('/') | |
ndir = andir[andir.length - 2] | |
if !File.directory?(sortedDir + '/documents/' + ndir) | |
Dir.mkdir(sortedDir + '/documents/' + ndir) | |
end | |
move(path, sortedDir + '/documents/' + ndir) | |
end | |
end | |
rule 'mp3,wma,aac + rename' do | |
dir(recupDir + '/*/*.mp3').each do |path| | |
tags = ID3Tag.read(File.open(path)) | |
@artist = tags.artist | |
@title = tags.title | |
@album = tags.album | |
@track_nr = tags.track_nr | |
newdir = "/music" | |
newname = "" | |
if @title == nil or @title.gsub!(/^[ \\\/\s\r\n]+|\/|\\|[ \\\/\s\r\n]+$/, "") == "" | |
andir = path.split('/') | |
@title = "unknown (" + andir[andir.length - 1].split('.mp3')[0] + ")" | |
end | |
if @track_nr != nil and @track_nr.gsub!(/^[ \\\/\s\r\n]+|\/|\\|[ \\\/\s\r\n]+$/, "") != "" | |
@track_nr = " (" + @track_nr + ")" | |
else | |
@track_nr = "" | |
end | |
if @artist != nil and @artist.gsub!(/^[ \\\/\s\r\n]+|\/|\\|[ \\\/\s\r\n]+$/, "") != "" | |
newdir << ("/" + @artist) | |
newname = @title + @track_nr + " - " + @artist | |
if !File.directory?(sortedDir + newdir) | |
Dir.mkdir(sortedDir + newdir) | |
end | |
if @album != nil and @album.gsub!(/^[ \\\/\s\r\n]+|\/|\\|[ \\\/\s\r\n]+$/, "") != "" | |
newdir << ("/" + @album) | |
if !File.directory?(sortedDir + newdir) | |
Dir.mkdir(sortedDir + newdir) | |
end | |
end | |
else | |
newname = @title + @track_nr | |
end | |
rename(path, sortedDir + newdir + "/" + newname + ".mp3") | |
end | |
end | |
rule 'video mp4,avi,mkv,mpg,mov' do | |
(dir(recupDir + '/*/*.mp4') + dir(recupDir + '/*/*.avi') + dir(recupDir + '/*/*.mkv') + dir(recupDir + '/*/*.mpg') + dir(recupDir + '/*/*.mov')).each do |path| | |
andir = path.split('/') | |
ndir = andir[andir.length - 2] | |
if !File.directory?(sortedDir + '/video/' + ndir) | |
Dir.mkdir(sortedDir + '/video/' + ndir) | |
end | |
move(path, sortedDir + '/video/' + ndir) | |
end | |
end | |
rule 'audio asf' do | |
(dir(recupDir + '/*/*.asf')).each do |path| | |
andir = path.split('/') | |
ndir = andir[andir.length - 2] | |
if !File.directory?(sortedDir + '/music_asf/' + ndir) | |
Dir.mkdir(sortedDir + '/music_asf/' + ndir) | |
end | |
move(path, sortedDir + '/music_asf/' + ndir) | |
end | |
end | |
rule 'archives zip,gz,7z,rar' do | |
(dir(recupDir + '/*/*.zip') + dir(recupDir + '/*/*.gz') + dir(recupDir + '/*/*.7z') + dir(recupDir + '/*/*.rar')).each do |path| | |
move(path, sortedDir + '/archives/') | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment