75 lines
1.7 KiB
Ruby
75 lines
1.7 KiB
Ruby
require 'optparse'
|
|
require 'open3'
|
|
require 'json'
|
|
|
|
options = {}
|
|
OptionParser.new do |opts|
|
|
opts.banner = "Usage: ruby delete_av1.rb [directory]"
|
|
end.parse!
|
|
|
|
directory = ARGV[0]
|
|
if directory.nil? || !Dir.exist?(directory)
|
|
puts "Usage: ruby delete_av1.rb [directory]"
|
|
exit 1
|
|
end
|
|
|
|
def is_av1?(file_path)
|
|
# Check only video stream
|
|
cmd = ['ffprobe', '-v', 'quiet', '-print_format', 'json', '-show_streams', '-select_streams', 'v:0', file_path]
|
|
stdout, _, status = Open3.capture3(*cmd)
|
|
return false unless status.success?
|
|
|
|
begin
|
|
data = JSON.parse(stdout)
|
|
stream = data['streams'][0]
|
|
return stream && stream['codec_name'] == 'av1'
|
|
rescue
|
|
false
|
|
end
|
|
end
|
|
|
|
puts "Scanning #{directory} for AV1 files..."
|
|
puts "This might take a while..."
|
|
|
|
av1_files = []
|
|
|
|
Dir.glob("#{directory}/**/*").each do |file|
|
|
next if File.directory?(file)
|
|
next unless ['.mp4', '.mkv', '.avi', '.mov', '.m4v'].include?(File.extname(file).downcase)
|
|
|
|
if is_av1?(file)
|
|
puts "Found: #{file}"
|
|
av1_files << file
|
|
end
|
|
end
|
|
|
|
if av1_files.empty?
|
|
puts "\nNo AV1 files found."
|
|
exit
|
|
end
|
|
|
|
puts "\n" + "="*40
|
|
puts "Found #{av1_files.length} AV1 files:"
|
|
av1_files.each { |f| puts " - #{f}" }
|
|
puts "="*40
|
|
puts "\nFound #{av1_files.length} files encoded with AV1."
|
|
print "Do you want to DELETE these files? [y/N]: "
|
|
STDOUT.flush
|
|
confirm = STDIN.gets.chomp.strip.downcase
|
|
|
|
if confirm == 'y'
|
|
deleted_count = 0
|
|
av1_files.each do |file|
|
|
begin
|
|
File.delete(file)
|
|
puts "Deleted: #{file}"
|
|
deleted_count += 1
|
|
rescue => e
|
|
puts "Failed to delete #{file}: #{e.message}"
|
|
end
|
|
end
|
|
puts "\nDeletion complete. #{deleted_count} files removed."
|
|
else
|
|
puts "\nOperation cancelled. No files were deleted."
|
|
end
|