Created
June 2, 2013 05:37
-
-
Save kwon37xi/5692721 to your computer and use it in GitHub Desktop.
자막 파일을 동영상 파일 이름에 맞게 순서대로 자동 변경해준다.
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
/* | |
동영상 파일과 자막 파일의 이름을 맞춰 준다. | |
현재 디렉토리에 동영상 파일과 자막 파일의 갯수가 동일해야 한다. | |
*/ | |
def usage() { | |
println 'Usage: groovy movie_subtitle_match.groovy 동영상확장자 자막확장자' | |
println "동영상 파일과 자막 파일의 갯수가 동일해야함" | |
} | |
def filesByExt(ext) { | |
new File('.').listFiles({file, filename -> filename.endsWith('.' + ext)} as FilenameFilter) | |
} | |
if (args.length != 2) { | |
usage() | |
return | |
} | |
def movieExt = args[0] | |
def subtitleExt = args[1] | |
List movies = filesByExt(movieExt).sort() | |
List subtitles = filesByExt(subtitleExt).sort() | |
if (movies.size() != subtitles.size()) { | |
println "동영상 파일과 자막 파일의 갯수가 다르다. 동영상 ${movies.size()}개 자막 ${subtitles.size()}개" | |
return | |
} | |
movies.eachWithIndex { movie, idx -> | |
def filename = movie.name.replaceFirst(~/\.[^\.]+$/, '') | |
def newSubtitleFile = new File(filename + '.' + subtitleExt) | |
println "Processing movie.name : ${subtitles[idx].name} -> ${newSubtitleFile}" | |
subtitles[idx].renameTo(newSubtitleFile) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment