-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathduplicate.php
More file actions
74 lines (62 loc) · 2.05 KB
/
duplicate.php
File metadata and controls
74 lines (62 loc) · 2.05 KB
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
65
66
67
68
69
70
71
72
73
74
<?php
require_once 'STFU.php';
class STFU_Duplicate {
private $stfu;
private $dry;
public function __construct($dry) {
$this->stfu = new SimpleTerminalFlickrUtility('AutoSync Duplicate Finder');
$this->dry = $dry;
}
public function exec() {
$autoSyncAlbum = $this->stfu->getAutoSyncAlbum();
$photos = $autoSyncAlbum->getPhotos($this->stfu);
Color::text("Looking for duplicates ...\n");
foreach ($photos as $photo) {
//Color::text("Looking for duplicates of ".$photo['title']." ...\t");
$search = $this->stfu->api->photos_search(array(
'user_id' => $this->stfu->userID,
'text' => $photo['title']
));
//Color::ok();
if (count($search['photo']) > 1) {
$compare = array();
foreach ($search['photo'] as $element) {
$compare[$element['id']] = $this->stfu->api->photos_getInfo($element['id']);
}
// set base for comparison the photo we were searching duplicates for and remove it from the comparison array
$baseCompare = $compare[$photo['id']];
unset($compare[$photo['id']]);
$same = false;
foreach ($compare as $element) {
if ($baseCompare['photo']['media'] == 'video') {
// if it's a video, we'll compare the duration
$same = ($baseCompare['photo']['video']['duration'] == $element['photo']['video']['duration']);
}
else {
// if it's a photo the datetaken exif data should be enough
$same = ($baseCompare['photo']['dates']['taken'] == $element['photo']['dates']['taken']);
}
}
if ($same) {
Color::text("Duplicate found for ");
Color::text($photo['title']."\t", Color::blue);
if ($this->dry) {
Color::text("No action taken (dry mode)\n", Color::green);
}
else {
Color::text("Deleting ... ");
$result = $this->stfu->api->photos_delete($photo['id']);
($result) ? Color::ok() : Color::text("FAILED\n", Color::red);
}
}
}
}
}
}
$dry = false;
if (count($argv) == 2) {
if ($argv[1] == "--dry") $dry = true;
}
$stfu = new STFU_Duplicate($dry);
$stfu->exec();
Color::text("\n\nYATA!!\n", Color::blue);