-
-
Save gouf/d49d83af278339faaf6a to your computer and use it in GitHub Desktop.
This file contains 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 'fileutils' | |
class TermColor | |
class << self | |
# 色を解除 | |
def reset | |
c 0 | |
end | |
# カラーシーケンスを出力する | |
def c(num) | |
print "\e[#{num}m" | |
end | |
# 各色 | |
%i(red green yellow | |
blue magenta cyan white).each.with_index(31) do |name, color_code| | |
define_method(name) do | |
c color_code | |
end | |
end | |
end | |
end | |
def scrub_redundant_string(string) | |
progname = string | |
progname.gsub!(/(\[新\])/, '') | |
progname.rstrip! | |
progname.gsub!(/^[\s ]+|[\s ]+$/, '') | |
progname.gsub!('[終]', '') | |
progname | |
end | |
def notice_found(progname) | |
# ゴニョゴニョ | |
TermColor.cyan | |
print 'Found:' | |
TermColor.white | |
puts progname | |
end | |
progname_regex = /(.*-((.*)((#|♯).*))\.ts|.*-(.*)\.ts)/ | |
basefolder = 'Z:/録画フォルダ/' | |
Dir.glob("#{basefolder}*.ts").each do |f| | |
basename = File.basename(f) | |
capt = basename.match(progname_regex).captures | |
progname = capt.values_at(2, 5).compact.first | |
unless progname | |
puts "No Match: #{basename}" | |
next | |
end | |
# 余計な文字列を削除する | |
progname = scrub_redundant_string(progname) | |
notice_found(progname) | |
# 下準備としてフォルダを必要に応じて作成する | |
dist = "#{basefolder}#{progname}" | |
FileUtils.mkdir_p(dist) unless FileTest.exist?(dist) | |
TermColor.green | |
print 'Moving file....' | |
TermColor.yellow | |
print basename | |
# ファイルを移動する | |
File.rename(f, "#{basefolder}#{progname}/#{basename}") | |
TermColor.magenta | |
puts '....Done!' | |
TermColor.reset | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment