Created
March 23, 2014 03:17
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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