forked from filebot/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathduplicates.groovy
64 lines (51 loc) · 1.38 KB
/
duplicates.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env filebot -script
delete = 'DELETE'.equalsIgnoreCase _args.action
binary = 'BINARY'.equalsIgnoreCase _args.mode
def group(files) {
// Binary Duplicates: Group by File Size, then Fast MovieHash, then CRC32 via Xattr
if (binary) {
def groups = [:]
// 1. Group by File Size
files.groupBy{ it.length() }.each{ size, size_fs ->
if (size_fs.size() == 1) {
return
}
// 2. Group by MovieHash
size_fs.groupBy{ it.hash 'moviehash' }.each{ hash, hash_fs ->
if (hash_fs.size() == 1) {
return
}
// 3. Group by CRC32 via Xattr
hash_fs.groupBy{ it.CRC32 }.each{ crc, crc_fs ->
groups += [[size, hash, crc] : crc_fs]
}
}
}
return groups
}
// Logical Duplicates: Group by Xattr Metadata Object
return files.groupBy{ it.metadata }.findAll{ m, fs -> m && fs.size() > 1 }
}
def order(files) {
// Binary Duplicates: Keep Input Argument Order
if (binary) {
return files
}
// Logical Duplicates: Order by Video Quality
return files.toSorted(VideoQuality.DESCENDING_ORDER)
}
// select video files (and preserve input argument order)
def files = args.collectMany{ it.getFiles{ it.isVideo() } }
group(files).each{ m, fs ->
log.info "[*] $m"
order(fs).eachWithIndex{ f, i ->
if (i == 0) {
log.finest "[+] 1. $f"
} else if (delete) {
log.warning "[DELETE] ${i+1}. $f"
f.trash()
} else {
log.fine "[-] ${i+1}. $f"
}
}
}