#!/usr/bin/ruby require 'sqlite3' require 'mp3info' require 'ogginfo' require 'find' directory='/home/My Music/Classical' db = SQLite3::Database.new( "musicdatabase.db" ) db.execute( "CREATE TEMP TABLE music ( title TEXT, artist TEXT, filepath TEXT )" ) duplicate_output = File.new('duplicates.txt', 'w') duplicate_output.print 'This file generated by Duplicate Removal v 0.2' duplicate_output.close class Fileread def mp3info( file, db ) begin @info = Mp3Info.new(file) @title = @info.tag1["title"] @artist = @info.tag1["artist"] rescue puts "File (mp3) " + file + " has unreadable tags." return false end return true end def ogginfo( file, db ) begin @info = OggInfo.new(file) @title = @info["title"] @artist = @info["artist"] rescue puts "File (ogg) " + file + " has unreadable tags." return false end return true end def duplicate( file, db ) @filecheck = db.execute( "SELECT filepath FROM music WHERE title = ? and artist = ?", @title, @artist ) if @filecheck.empty? db.execute( "INSERT INTO music VALUES ( ?, ?, ? )", @title, @artist, file.to_s ) return false else duplicate_output=File.open( "duplicates.txt", "a" ) duplicate_output.print "\n" + @title + " by " + @artist + "\nLocated at\n" + file + "and\n" + @filecheck duplicate_output.close return true end end end check = Fileread.new Find.find(directory) do |f| if FileTest.directory?(f) puts "Currently Searching " + f.to_s else if f[-4..-1] == ".mp3" if check.mp3info(f, db) == true check.duplicate(f, db) end elsif f[-4..-1] == ".ogg" || f[-5..-1] == ".flac" if check.mp3info(f, db) == true check.duplicate(f, db) end end end end