Browse Source

fix crontab scrape

main
ghost 1 year ago
parent
commit
c50e3a777b
  1. 65
      src/crontab/scrape.php

65
src/crontab/scrape.php

@ -57,10 +57,10 @@ try {
foreach ($db->getMagnetToAddressTrackerScrapeQueue(CRAWLER_SCRAPE_QUEUE_LIMIT) as $queue) foreach ($db->getMagnetToAddressTrackerScrapeQueue(CRAWLER_SCRAPE_QUEUE_LIMIT) as $queue)
{ {
$hash = []; $hashes = [];
foreach ($db->findMagnetToInfoHashByMagnetId($queue->magnetId) as $result) foreach ($db->findMagnetToInfoHashByMagnetId($queue->magnetId) as $result)
{ {
$hash[] = $db->getInfoHash($result->infoHashId)->value; $hashes[] = $db->getInfoHash($result->infoHashId)->value;
} }
if ($addressTracker = $db->getAddressTracker($queue->addressTrackerId)) if ($addressTracker = $db->getAddressTracker($queue->addressTrackerId))
@ -78,47 +78,50 @@ try {
$host->value, $host->value,
$uri->value); $uri->value);
if ($scrape = $scraper->scrape($hash, [$url], null, 1)) foreach ($hashes as $hash)
{ {
$db->updateMagnetToAddressTrackerTimeOffline( if ($scrape = $scraper->scrape([$hash], [$url], null, 1))
$queue->magnetToAddressTrackerId,
null
);
if (isset($scrape[$hash]['seeders']))
{ {
$db->updateMagnetToAddressTrackerSeeders( $db->updateMagnetToAddressTrackerTimeOffline(
$queue->magnetToAddressTrackerId, $queue->magnetToAddressTrackerId,
(int) $scrape[$hash]['seeders'], null
time()
); );
}
if (isset($scrape[$hash]['completed'])) if (isset($scrape[$hash]['seeders']))
{ {
$db->updateMagnetToAddressTrackerCompleted( $db->updateMagnetToAddressTrackerSeeders(
$queue->magnetToAddressTrackerId, $queue->magnetToAddressTrackerId,
(int) $scrape[$hash]['completed'], (int) $scrape[$hash]['seeders'],
time() time()
); );
}
if (isset($scrape[$hash]['completed']))
{
$db->updateMagnetToAddressTrackerCompleted(
$queue->magnetToAddressTrackerId,
(int) $scrape[$hash]['completed'],
time()
);
}
if (isset($scrape[$hash]['leechers']))
{
$db->updateMagnetToAddressTrackerLeechers(
$queue->magnetToAddressTrackerId,
(int) $scrape[$hash]['leechers'],
time()
);
}
} }
else
if (isset($scrape[$hash]['leechers']))
{ {
$db->updateMagnetToAddressTrackerLeechers( $db->updateMagnetToAddressTrackerTimeOffline(
$queue->magnetToAddressTrackerId, $queue->magnetToAddressTrackerId,
(int) $scrape[$hash]['leechers'],
time() time()
); );
} }
} }
else
{
$db->updateMagnetToAddressTrackerTimeOffline(
$queue->magnetToAddressTrackerId,
time()
);
}
} }
} }

Loading…
Cancel
Save