-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimgcrawler.php
91 lines (69 loc) · 2.2 KB
/
imgcrawler.php
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/php
<?php
$ts = time();
set_time_limit(0);
require_once 'config.inc.php';
require_once 'dainews.class.php';
function o($s) {
echo $s . "\n";
}
$DAINEWS = new DAINEWS(DAI_USER, DAI_PASS);
$total = 0;
$dupes = 0;
$downloaded = 0;
$had = 0;
$tdownloaded = 0;
$thad = 0;
$sql = "SELECT * FROM celebrities WHERE images=0";
$res = mysql_query($sql);
while ($c = mysql_fetch_assoc($res)) {
$added = 0;
$IMG_DIR = str_replace("%celebname%", $c['name'], IMG_DIR);
if (($pics = $DAINEWS->getPics($c['firstname'], $c['lastname'])) !== FALSE) {
o(count($pics) . ' pics found');
foreach ($pics as $p) {
if (!is_file($IMG_DIR . $p['img'])) {
$im = $DAINEWS->getImg($p['img']);
$fp = fopen($IMG_DIR . $p['img'], 'w');
fwrite($fp, $im);
fclose($fp);
o('DOWNLOADED ' . IMG_DIR . $p['img']);
$downloaded++;
} else {
$had++;
}
if (!is_file($IMG_DIR . $p['thumbfile'])) {
$im = $DAINEWS->getThumb($p['img']);
$fp = fopen($IMG_DIR . $p['thumbfile'], 'w');
fwrite($fp, $im);
fclose($fp);
o('DOWNLOADED ' . THUMB_DIR . $p['thumbfile']);
$tdownloaded++;
} else {
$thad++;
}
$sql2 = sprintf("SELECT * FROM images WHERE filename='%s' AND celeb_id=%d", mysql_escape_string($p['img']), $c['celeb_id']);
$res2 = mysql_query($sql2);
if (mysql_num_rows($res2) == 0) {
$info = explode('x', $p['res']);
$sql = sprintf("INSERT INTO images VALUES (0, %d, %d, %d, '%s', %d, %d, %d, '%s', 0, 0, 1)",
$c['celeb_id'], $p['n'], $p['q'], date('Ymd'), filesize($IMG_DIR . $p['img']), $info[0], $info[1], mysql_escape_string($p['img']));
mysql_query($sql);
unset($info);
$total++;
$added++;
} else {
$dupes++;
}
mysql_free_result($res2);
}
}
$sql = sprintf("UPDATE celebrities SET images=images+%d,last_crawl=%d WHERE celeb_id=%d", $added, time(), $c['celeb_id']);
mysql_query($sql);
o('spidered ' . $c['firstname'] . ' ' . $c['lastname'] . ' added ' . $added . ' pics');
sleep(2);
unset($c);
}
mysql_free_result($res);
o('done: ' . $total . ' images added, ' . $dupes . ' dupes, had ' . $had . ' images, dl\'d ' . $downloaded . ', had ' . $thad . ' thumbs, dl\'d ' . $tdownloaded . ', ' . (time()-$ts) . ' seconds');
?>