Skip to content

Instantly share code, notes, and snippets.

@albertohm
Created March 23, 2014 03:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save albertohm/9718115 to your computer and use it in GitHub Desktop.
Save albertohm/9718115 to your computer and use it in GitHub Desktop.
Just a simple script to move files from my download dir to my tvshows dir
require 'find'
require 'fileutils'
DOWNLOAD_PATH = '/media/raspberry/descargas'
EXCLUDED_DIRS = %w( temp torrents )
TVSHOWS_PATH = '/media/raspberry/series'
EXCLUDED_DIRS_PATH = EXCLUDED_DIRS.map{|dir| DOWNLOAD_PATH + "/#{dir}"}
TVSHOWS = Dir.entries(TVSHOWS_PATH).select do |entry|
File.directory? File.join(TVSHOWS_PATH,entry) and
!(entry =='.' || entry == '..')
end
TVSHOWS.each do |tvshow|
show_file_paths = []
regexp = tvshow.split('_').join('*')
Find.find(DOWNLOAD_PATH) do |path|
if File.basename(path)[0] == ?. or EXCLUDED_DIRS_PATH.include? File.dirname(path)
Find.prune
end
regexp = tvshow.gsub('_', '.')
if path.downcase =~ /^.*#{regexp}.*\.(mp4|avi|mkv)$/
show_file_paths << path
end
end
show_file_paths.each do |file|
puts "Moving #{file}"
FileUtils.mv(file, "#{TVSHOWS_PATH}/#{tvshow}")
end
puts "There was no episode found for #{tvshow}" if show_file_paths.empty?
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment