Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[InternetArchiveBridge] Add detectParameters method #2142

Merged
merged 2 commits into from
Aug 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions bridges/InternetArchiveBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,40 @@ class InternetArchiveBridge extends BridgeAbstract {

const CACHE_TIMEOUT = 900; // 15 mins

const TEST_DETECT_PARAMETERS = array(
'https://archive.org/details/@verifiedjoseph' => array(
'context' => 'Account', 'username' => 'verifiedjoseph', 'content' => 'uploads'
),
'https://archive.org/details/@verifiedjoseph?tab=collections' => array(
'context' => 'Account', 'username' => 'verifiedjoseph', 'content' => 'collections'
),
);

private $skipClasses = array(
'item-ia mobile-header hidden-tiles',
'item-ia account-ia'
);

private $detectParamsRegex = '/https?:\/\/archive\.org\/details\/@([\w]+)(?:\?tab=([a-z-]+))?/';

public function detectParameters($url) {
$params = array();

if(preg_match($this->detectParamsRegex, $url, $matches) > 0) {
$params['context'] = 'Account';
$params['username'] = $matches[1];
$params['content'] = 'uploads';

if (isset($matches[2])) {
$params['content'] = $matches[2];
}

return $params;
}

return null;
}

public function collectData() {

$html = getSimpleHTMLDOM($this->getURI())
Expand Down