[-]
Shout:
Click Refresh to load shouts.

Post Reply 
 
Thread Rating:
  • 1 Votes - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multiple folder unrarer with blacklist
05-21-2009, 04:01 PM
Post: #1
Multiple folder unrarer with blacklist
Just did this,
Wont work in Windows, but Linux!

It'll go through the @rarDirectory looking for folders, then if the folder name contains "HDTV or PDTV" or "DVDRIP" it unrars the rarfiles, moves them to $endUpDirectory and renames it to the directory name. Since the usual name of avi files isnt really descriptive.

When its done it adds it to the blacklist so it doesnt unrar it again.

This is obviously for releases from the "Scene". I needed it to go through all my old files cause my hdtv doesnt play rared files, and 800gb will take to long to do manually Sad

Code:
#!/usr/bin/ruby

@rarDirectory = "/home/hugge/Desktop/Torrent"
$endUpDirectory = "/home/hugge/Desktop/Unpacked"
$blackListFile = "%s/.blist" % $endUpDirectory

class Directory
    attr_accessor :folder, :name, :blistName, :ok, :currentFolder
    def initialize(folder)
        @folder = folder
        @name = folder.split("/").last
        @blistName = "%s\n" % @name
        @ok = false
        @currentFolder = ""
    end

    def to_str
        @folder
    end

    def getCategory
        tstring = @name.upcase
        result = 0
        if tstring.match "HDTV" or tstring.match "PDTV"
            result ="TV"
        elsif tstring.match "DVDRIP"
            result = "Film"
        end
        return result
    end

    def hasSubDirs
        return Dir["%s/CD*" % @folder].count
    end

    def moveFile
        unless hasSubDirs > 0
            @ok = system "mv *.avi %s/%s/%s.avi" % [$endUpDirectory, getCategory, @name]
        else
            @ok = system "mv *.avi %s/%s/%s-%s.avi" % [$endUpDirectory, getCategory, @name, @currentFolder.split("/").last]
        end
    end

    def doRar
        rarFile = Dir["%s/*.rar" % @currentFolder].first
        unless hasSubDirs > 0
            print "%s..." % @name
            unRAR(rarFile)
            moveFile
        else
            print "%s-%s..." % [@name, @currentFolder.split("/").last]
            unRAR(rarFile)
            moveFile
        end
    end

    def listFiles
        unless hasSubDirs > 0
            @currentFolder = @folder
            doRar
        else
            Dir["%s/CD*" % @folder].each do |subdir|
                @currentFolder = subdir
                doRar
            end
        end
        if @ok
            addToBlackList
            puts "OK!"
        else
            puts "Fail!"
        end
    end
    def addToBlackList
        File.open($blackListFile,'a') do |f|
            f.puts @name
        end
    end
end

def unRAR(fileName)
    return system "unrar e -y %s > /dev/null" % fileName
end

def getBlackList
    File.open($blackListFile) do |f|
        return f.readlines
    end
end

blackList = getBlackList
Dir["%s/*" % @rarDirectory].each do |dir|
    directory = Directory.new(dir)
    unless directory.getCategory == 0
        unless blackList.index(directory.blistName)
            Dir.chdir(directory)
            directory.listFiles
        end
    end
end
Find all posts by this user
Quote this message in a reply
Post Reply 



Contact UsTProgrammingReturn to TopReturn to ContentLite (Archive) ModeRSS Syndication