bridges: add context to detectParameters (#3607)

* bridges: add context to detectParameters

Some bridges did not return the context parameter but they used it in
the parameters

* bridges: add context to detectParameters

Fix test for InstagramBridge
This commit is contained in:
sysadminstory 2023-08-09 22:40:24 +02:00 committed by GitHub
parent 6cc4cf24dc
commit 52d3cce59d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 115 additions and 80 deletions

View File

@ -138,6 +138,7 @@ class BadDragonBridge extends BridgeAbstract
// Sale
$regex = '/^(https?:\/\/)?bad-dragon\.com\/sales/';
if (preg_match($regex, $url, $matches) > 0) {
$params['context'] = 'Sales';
return $params;
}
@ -192,6 +193,7 @@ class BadDragonBridge extends BridgeAbstract
isset($urlParams['noAccessories'])
&& $urlParams['noAccessories'] === '1'
&& $params['noAccessories'] = 'on';
$params['context'] = 'Clearance';
return $params;
}

View File

@ -397,6 +397,7 @@ class BandcampBridge extends BridgeAbstract
// By tag
$regex = '/^(https?:\/\/)?bandcamp\.com\/tag\/([^\/.&?\n]+)/';
if (preg_match($regex, $url, $matches) > 0) {
$params['context'] = 'By tag';
$params['tag'] = urldecode($matches[2]);
return $params;
}
@ -404,6 +405,7 @@ class BandcampBridge extends BridgeAbstract
// By band
$regex = '/^(https?:\/\/)?([^\/.&?\n]+?)\.bandcamp\.com/';
if (preg_match($regex, $url, $matches) > 0) {
$params['context'] = 'By band';
$params['band'] = urldecode($matches[2]);
return $params;
}
@ -411,6 +413,7 @@ class BandcampBridge extends BridgeAbstract
// By album
$regex = '/^(https?:\/\/)?([^\/.&?\n]+?)\.bandcamp\.com\/album\/([^\/.&?\n]+)/';
if (preg_match($regex, $url, $matches) > 0) {
$params['context'] = 'By album';
$params['band'] = urldecode($matches[2]);
$params['album'] = urldecode($matches[3]);
return $params;

View File

@ -88,6 +88,7 @@ class FacebookBridge extends BridgeAbstract
// By profile
$regex = '/^(https?:\/\/)?(www\.)?facebook\.com\/profile\.php\?id\=([^\/?&\n]+)?(.*)/';
if (preg_match($regex, $url, $matches) > 0) {
$params['context'] = 'User';
$params['u'] = urldecode($matches[3]);
return $params;
}
@ -95,6 +96,7 @@ class FacebookBridge extends BridgeAbstract
// By group
$regex = '/^(https?:\/\/)?(www\.)?facebook\.com\/groups\/([^\/?\n]+)?(.*)/';
if (preg_match($regex, $url, $matches) > 0) {
$params['context'] = 'Group';
$params['g'] = urldecode($matches[3]);
return $params;
}
@ -103,6 +105,7 @@ class FacebookBridge extends BridgeAbstract
$regex = '/^(https?:\/\/)?(www\.)?facebook\.com\/([^\/?\n]+)/';
if (preg_match($regex, $url, $matches) > 0) {
$params['context'] = '';
$params['u'] = urldecode($matches[3]);
return $params;
}

View File

@ -2,89 +2,90 @@
class FreeTelechargerBridge extends BridgeAbstract
{
const NAME = 'Free-Telecharger';
const URI = 'https://www.free-telecharger.live/';
const DESCRIPTION = 'Suivi de série sur Free-Telecharger';
const MAINTAINER = 'sysadminstory';
const PARAMETERS = [
'Suivi de publication de série' => [
'url' => [
'name' => 'URL de la série',
'type' => 'text',
'required' => true,
'title' => 'URL d\'une série sans le https://www.free-telecharger.live/',
'pattern' => 'series.*\.html',
'exampleValue' => 'series-vf-hd/145458-the-last-of-us-saison-1-web-dl-720p.html'
],
]
];
const CACHE_TIMEOUT = 3600;
public function collectData()
{
$html = getSimpleHTMLDOM(self::URI . $this->getInput('url'));
const NAME = 'Free-Telecharger';
const URI = 'https://www.free-telecharger.live/';
const DESCRIPTION = 'Suivi de série sur Free-Telecharger';
const MAINTAINER = 'sysadminstory';
const PARAMETERS = [
'Suivi de publication de série' => [
'url' => [
'name' => 'URL de la série',
'type' => 'text',
'required' => true,
'title' => 'URL d\'une série sans le https://www.free-telecharger.live/',
'pattern' => 'series.*\.html',
'exampleValue' => 'series-vf-hd/145458-the-last-of-us-saison-1-web-dl-720p.html'
],
]
];
const CACHE_TIMEOUT = 3600;
public function collectData()
{
$html = getSimpleHTMLDOM(self::URI . $this->getInput('url'));
// Find all block content of the page
$blocks = $html->find('div[class=block1]');
// Find all block content of the page
$blocks = $html->find('div[class=block1]');
// Global Infos block
$infosBlock = $blocks[0];
// Links block
$linksBlock = $blocks[2];
// Global Infos block
$infosBlock = $blocks[0];
// Links block
$linksBlock = $blocks[2];
// Extract Global Show infos
$this->showTitle = trim($infosBlock->find('div[class=titre1]', 0)->find('font', 0)->plaintext);
$this->showTechDetails = trim($infosBlock->find('div[align=center]', 0)->find('b', 0)->plaintext);
// Extract Global Show infos
$this->showTitle = trim($infosBlock->find('div[class=titre1]', 0)->find('font', 0)->plaintext);
$this->showTechDetails = trim($infosBlock->find('div[align=center]', 0)->find('b', 0)->plaintext);
// Get Episodes names and links
$episodes = $linksBlock->find('div[id=link]', 0)->find('font[color=#ff6600]');
$links = $linksBlock->find('div[id=link]', 0)->find('a');
// Get Episodes names and links
$episodes = $linksBlock->find('div[id=link]', 0)->find('font[color=#ff6600]');
$links = $linksBlock->find('div[id=link]', 0)->find('a');
foreach ($episodes as $index => $episode) {
$item = []; // Create an empty item
$item['title'] = $this->showTitle . ' ' . $this->showTechDetails . ' - ' . ltrim(trim($episode->plaintext), '-');
$item['uri'] = $links[$index]->href;
$item['content'] = '<a href="' . $item['uri'] . '">' . $item['title'] . '</a>';
$item['uid'] = hash('md5', $item['uri']);
foreach ($episodes as $index => $episode) {
$item = []; // Create an empty item
$item['title'] = $this->showTitle . ' ' . $this->showTechDetails . ' - ' . ltrim(trim($episode->plaintext), '-');
$item['uri'] = $links[$index]->href;
$item['content'] = '<a href="' . $item['uri'] . '">' . $item['title'] . '</a>';
$item['uid'] = hash('md5', $item['uri']);
$this->items[] = $item; // Add this item to the list
}
$this->items[] = $item; // Add this item to the list
}
}
public function getName()
{
switch ($this->queriedContext) {
case 'Suivi de publication de série':
return $this->showTitle . ' ' . $this->showTechDetails . ' - ' . self::NAME;
break;
default:
return self::NAME;
}
}
public function getURI()
{
switch ($this->queriedContext) {
case 'Suivi de publication de série':
return self::URI . $this->getInput('url');
break;
default:
return self::URI;
}
}
public function detectParameters($url)
{
// Example: https://www.free-telecharger.live/series-vf-hd/145458-the-last-of-us-saison-1-web-dl-720p.html
$params = [];
$regex = '/^https:\/\/www.*\.free-telecharger\.live\/(series.*\.html)/';
if (preg_match($regex, $url, $matches) > 0) {
$params['context'] = 'Suivi de publication de série';
$params['url'] = urldecode($matches[1]);
return $params;
}
public function getName()
{
switch ($this->queriedContext) {
case 'Suivi de publication de série':
return $this->showTitle . ' ' . $this->showTechDetails . ' - ' . self::NAME;
break;
default:
return self::NAME;
}
}
public function getURI()
{
switch ($this->queriedContext) {
case 'Suivi de publication de série':
return self::URI . $this->getInput('url');
break;
default:
return self::URI;
}
}
public function detectParameters($url)
{
// Example: https://www.free-telecharger.live/series-vf-hd/145458-the-last-of-us-saison-1-web-dl-720p.html
$params = [];
$regex = '/^https:\/\/www.*\.free-telecharger\.live\/(series.*\.html)/';
if (preg_match($regex, $url, $matches) > 0) {
$params['url'] = urldecode($matches[1]);
return $params;
}
return null;
}
return null;
}
}

View File

@ -64,6 +64,7 @@ class FunkBridge extends BridgeAbstract
$regex = '/^https?:\/\/(?:www\.)?funk\.net\/channel\/([^\/]+).*$/';
if (preg_match($regex, $url, $urlMatches) > 0) {
return [
'context' => 'Channel',
'channel' => $urlMatches[1]
];
} else {

View File

@ -603,6 +603,7 @@ class FurAffinityBridge extends BridgeAbstract
// Single journal
$regex = '/^(https?:\/\/)?(www\.)?furaffinity.net\/journal\/(\d+)/';
if (preg_match($regex, $url, $matches) > 0) {
$params['context'] = 'Single Journal';
$params['journal-id'] = urldecode($matches[3]);
return $params;
}
@ -610,6 +611,7 @@ class FurAffinityBridge extends BridgeAbstract
// Journals
$regex = '/^(https?:\/\/)?(www\.)?furaffinity.net\/journals\/([^\/&?\n]+)/';
if (preg_match($regex, $url, $matches) > 0) {
$params['context'] = 'Journals';
$params['username-journals'] = urldecode($matches[3]);
return $params;
}
@ -617,6 +619,7 @@ class FurAffinityBridge extends BridgeAbstract
// Gallery folder
$regex = '/^(https?:\/\/)?(www\.)?furaffinity.net\/gallery\/([^\/&?\n]+)\/folder\/(\d+)/';
if (preg_match($regex, $url, $matches) > 0) {
$params['context'] = 'Gallery Folder';
$params['username-folder'] = urldecode($matches[3]);
$params['folder-id'] = urldecode($matches[4]);
$params['full'] = 'on';
@ -626,6 +629,7 @@ class FurAffinityBridge extends BridgeAbstract
// Gallery (must be after gallery folder)
$regex = '/^(https?:\/\/)?(www\.)?furaffinity.net\/(gallery|scraps|favorites)\/([^\/&?\n]+)/';
if (preg_match($regex, $url, $matches) > 0) {
$params['context'] = 'Gallery';
$params['username-' . $matches[3]] = urldecode($matches[4]);
$params['full'] = 'on';
return $params;

View File

@ -277,6 +277,7 @@ class GithubIssueBridge extends BridgeAbstract
case 2: // Project issues
[$user, $project] = $path_segments;
$show_comments = 'off';
$context = 'Project Issues';
break;
case 3: // Project issues with issue comments
if ($path_segments[2] !== static::URL_PATH) {
@ -284,15 +285,18 @@ class GithubIssueBridge extends BridgeAbstract
}
[$user, $project] = $path_segments;
$show_comments = 'on';
$context = 'Project Issues';
break;
case 4: // Issue comments
[$user, $project, /* issues */, $issue] = $path_segments;
$context = 'Issue comments';
break;
default:
return null;
}
return [
'context' => $context,
'u' => $user,
'p' => $project,
'c' => $show_comments ?? null,

View File

@ -267,6 +267,7 @@ HTML,
$regex = '/^http(s|):\/\/((www\.|)(instagram.com)\/([a-zA-Z0-9_\.]{1,30})\/(reels\/|tagged\/|)
|(www\.|)(imgsed.com)\/(stories\/|tagged\/|)([a-zA-Z0-9_\.]{1,30})\/)/';
if (preg_match($regex, $url, $matches) > 0) {
$params['context'] = 'Username';
// Extract detected domain using the regex
$domain = $matches[8] ?? $matches[4];
if ($domain == 'imgsed.com') {

View File

@ -63,9 +63,9 @@ class InstagramBridge extends BridgeAbstract
];
const TEST_DETECT_PARAMETERS = [
'https://www.instagram.com/metaverse' => ['u' => 'metaverse'],
'https://instagram.com/metaverse' => ['u' => 'metaverse'],
'http://www.instagram.com/metaverse' => ['u' => 'metaverse'],
'https://www.instagram.com/metaverse' => ['context' => 'Username', 'u' => 'metaverse'],
'https://instagram.com/metaverse' => ['context' => 'Username', 'u' => 'metaverse'],
'http://www.instagram.com/metaverse' => ['context' => 'Username', 'u' => 'metaverse'],
];
const USER_QUERY_HASH = '58b6785bea111c67129decbe6a448951';
@ -323,6 +323,7 @@ class InstagramBridge extends BridgeAbstract
$regex = '/^(https?:\/\/)?(www\.)?instagram\.com\/([^\/?\n]+)/';
if (preg_match($regex, $url, $matches) > 0) {
$params['context'] = 'Username';
$params['u'] = urldecode($matches[3]);
return $params;
}

View File

@ -301,10 +301,12 @@ class RedditBridge extends BridgeAbstract
if ($path[1] == 'r') {
return [
'context' => 'single',
'r' => $path[2]
];
} elseif ($path[1] == 'user') {
return [
'context' => 'user',
'u' => $path[2]
];
} else {

View File

@ -455,11 +455,12 @@ class SkimfeedBridge extends BridgeAbstract
return null;
}
foreach (self::PARAMETERS as $channels) {
foreach (self::PARAMETERS as $context => $channels) {
foreach ($channels as $box_name => $box) {
foreach ($box['values'] as $name => $channel_url) {
if (static::URI . $channel_url === $url) {
return [
'context' => $context,
$box_name => $name,
];
}

View File

@ -670,7 +670,15 @@ class TrelloBridge extends BridgeAbstract
{
$regex = '/^(https?:\/\/)?trello\.com\/([bc])\/([^\/?\n]+)/';
if (preg_match($regex, $url, $matches) > 0) {
return [$matches[2] => $matches[3]];
if ($matches[2] == 'b') {
$context = 'Board';
} else if ($matches[2] == 'c') {
$context = 'Card';
}
return [
'context' => $context,
$matches[2] => $matches[3]
];
} else {
return null;
}

View File

@ -133,6 +133,7 @@ EOD
// By keyword or hashtag (search)
$regex = '/^(https?:\/\/)?(www\.)?twitter\.com\/search.*(\?|&)q=([^\/&?\n]+)/';
if (preg_match($regex, $url, $matches) > 0) {
$params['context'] = 'By keyword or hashtag';
$params['q'] = urldecode($matches[4]);
return $params;
}
@ -140,6 +141,7 @@ EOD
// By hashtag
$regex = '/^(https?:\/\/)?(www\.)?twitter\.com\/hashtag\/([^\/?\n]+)/';
if (preg_match($regex, $url, $matches) > 0) {
$params['context'] = 'By keyword or hashtag';
$params['q'] = urldecode($matches[3]);
return $params;
}
@ -147,6 +149,7 @@ EOD
// By list
$regex = '/^(https?:\/\/)?(www\.)?twitter\.com\/([^\/?\n]+)\/lists\/([^\/?\n]+)/';
if (preg_match($regex, $url, $matches) > 0) {
$params['context'] = 'By list';
$params['user'] = urldecode($matches[3]);
$params['list'] = urldecode($matches[4]);
return $params;
@ -155,6 +158,7 @@ EOD
// By username
$regex = '/^(https?:\/\/)?(www\.)?twitter\.com\/([^\/?\n]+)/';
if (preg_match($regex, $url, $matches) > 0) {
$params['context'] = 'By username';
$params['u'] = urldecode($matches[3]);
return $params;
}