1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-11-13 12:55:00 -05:00

Update data files only if the contents have actually changed

This commit is contained in:
Reinhard Pointner 2019-05-22 18:48:39 +07:00
parent d5c8551761
commit 34db5810df

View File

@ -44,21 +44,32 @@ def osdb_out = dir_release.resolve('osdb.txt')
def pack(file, lines) {
def previousHash = hash(file)
file.withOutputStream{ out ->
out.withWriter('UTF-8'){ writer ->
lines.each{ writer.append(it).append('\n') }
}
}
file.parentFile.resolve(file.name + '.xz').withOutputStream{ out ->
new XZOutputStream(out, new LZMA2Options(LZMA2Options.PRESET_DEFAULT)).withWriter('UTF-8'){ writer ->
lines.each{ writer.append(it).append('\n') }
if (hash(file) != previousHash) {
file.parentFile.resolve(file.name + '.xz').withOutputStream{ out ->
new XZOutputStream(out, new LZMA2Options(LZMA2Options.PRESET_DEFAULT)).withWriter('UTF-8'){ writer ->
lines.each{ writer.append(it).append('\n') }
}
}
} else {
log.warning "[NOT MODIFIED] $file [$previousHash]"
}
def rows = lines.size()
def columns = lines.collect{ it.split(/\t/).length }.max()
log.info "${file.canonicalFile} ($rows rows, $columns columns)"
}
def hash(file) {
return file.length()
}
def isValidMovieName(s) {
return (s.normalizePunctuation().length() >= 4) || (s=~ /^[A-Z0-9]/ && s =~ /[\p{Alnum}]{3}/)