mirror of
https://github.com/YGGverse/gemini-dl.git
synced 2026-03-31 17:15:32 +00:00
implement setSource method to update value properly
This commit is contained in:
parent
a98fb2ef5a
commit
3dd8a5256e
1 changed files with 41 additions and 7 deletions
|
|
@ -49,12 +49,12 @@ class Cli
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Appends valid address to crawler queue
|
// Appends address in crawler queue
|
||||||
public function addSource(
|
public function addSource(
|
||||||
string $url
|
string $url
|
||||||
): bool
|
): bool
|
||||||
{
|
{
|
||||||
// Validate given value and check it is unique in pool
|
// Validate given value and check it is unique in the pool
|
||||||
if ($this->_source($url) && !in_array($url, $this->source))
|
if ($this->_source($url) && !in_array($url, $this->source))
|
||||||
{
|
{
|
||||||
$this->source[] = $url;
|
$this->source[] = $url;
|
||||||
|
|
@ -65,6 +65,23 @@ class Cli
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Updates address in crawler queue
|
||||||
|
public function setSource(
|
||||||
|
int $offset,
|
||||||
|
string $url
|
||||||
|
): bool
|
||||||
|
{
|
||||||
|
// Validate given value and check it is unique in the pool
|
||||||
|
if (isset($this->source[$offset]) && $this->_source($url) && $this->source[$offset] != $url)
|
||||||
|
{
|
||||||
|
$this->source[$offset] = $url;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Begin crawler task
|
// Begin crawler task
|
||||||
public function start(
|
public function start(
|
||||||
int $offset = 0
|
int $offset = 0
|
||||||
|
|
@ -187,12 +204,29 @@ class Cli
|
||||||
if (filter_var($response->getMeta(), FILTER_VALIDATE_URL)) // @TODO resolve relative locations
|
if (filter_var($response->getMeta(), FILTER_VALIDATE_URL)) // @TODO resolve relative locations
|
||||||
{
|
{
|
||||||
// Apply redirection target to the current destination
|
// Apply redirection target to the current destination
|
||||||
$this->source[$offset] = $response->getMeta();
|
if ($this->setSource($offset, trim($response->getMeta())))
|
||||||
|
{
|
||||||
|
// Rescan current destination using updated location
|
||||||
|
$this->start(
|
||||||
|
$offset
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
print(
|
||||||
|
Message::red(
|
||||||
|
sprintf(
|
||||||
|
_("\tdestination could not be updated due to the conditions or it has already been indexed: `%s`"),
|
||||||
|
$response->getMeta()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
// Rescan current destination using updated location
|
// Continue next location
|
||||||
$this->start(
|
$this->start(
|
||||||
$offset
|
$offset + 1
|
||||||
);
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue