Skip to content

Instantly share code, notes, and snippets.

@kwon37xi
Created June 2, 2013 05:37
Show Gist options
  • Save kwon37xi/5692721 to your computer and use it in GitHub Desktop.
Save kwon37xi/5692721 to your computer and use it in GitHub Desktop.
자막 파일을 동영상 파일 이름에 맞게 순서대로 자동 변경해준다.
/*
동영상 파일과 자막 파일의 이름을 맞춰 준다.
현재 디렉토리에 동영상 파일과 자막 파일의 갯수가 동일해야 한다.
*/
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