extract archives in encode-and-add-to-itunes.rb
This commit is contained in:
parent
d088493c89
commit
9f7869c1c4
1 changed files with 27 additions and 2 deletions
|
|
@ -5,9 +5,18 @@ require 'fileutils'
|
||||||
ADD_TO_ITUNES_DIR = File.expand_path('~/Music/iTunes/iTunes Media/Automatically Add to iTunes.localized')
|
ADD_TO_ITUNES_DIR = File.expand_path('~/Music/iTunes/iTunes Media/Automatically Add to iTunes.localized')
|
||||||
|
|
||||||
def main
|
def main
|
||||||
root_dir = ENV['TR_TORRENT_DIR'] || ARGV.shift
|
root_dir =
|
||||||
|
if ENV['TR_TORRENT_DIR']
|
||||||
|
File.join(ENV['TR_TORRENT_DIR'], ENV['TR_TORRENT_NAME'])
|
||||||
|
else
|
||||||
|
ARGV.shift
|
||||||
|
end
|
||||||
|
|
||||||
if File.exists?(root_dir)
|
if File.exists?(root_dir)
|
||||||
puts "* Encoding files in #{root_dir}"
|
puts "* Looking for archives in #{root_dir}..."
|
||||||
|
extract_archives(root_dir)
|
||||||
|
|
||||||
|
puts "* Encoding files in #{root_dir}..."
|
||||||
encode_and_add_to_itunes(root_dir)
|
encode_and_add_to_itunes(root_dir)
|
||||||
elsif root_dir
|
elsif root_dir
|
||||||
puts "file not found: #{root_dir}"
|
puts "file not found: #{root_dir}"
|
||||||
|
|
@ -18,6 +27,22 @@ def main
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def extract_archives(dir)
|
||||||
|
Dir.foreach(dir) do |filename|
|
||||||
|
next if filename == '.' || filename == '..'
|
||||||
|
path = File.join(dir, filename)
|
||||||
|
if File.directory?(path)
|
||||||
|
extract_archives(path)
|
||||||
|
elsif filename =~ /\.rar$/
|
||||||
|
pwd = Dir.pwd
|
||||||
|
Dir.chdir(dir)
|
||||||
|
puts "* Extracting #{filename}..."
|
||||||
|
`unrar x '#{filename}'`
|
||||||
|
Dir.chdir(pwd)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def encode_and_add_to_itunes(dir)
|
def encode_and_add_to_itunes(dir)
|
||||||
Dir.foreach(dir) do |filename|
|
Dir.foreach(dir) do |filename|
|
||||||
next if filename == '.' || filename == '..'
|
next if filename == '.' || filename == '..'
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue