Première version du nouveau système de méta-données.
Voir exemple dans YoutubeBridge.
This commit is contained in:
parent
e9e7a421ff
commit
2deef45867
3 changed files with 150 additions and 83 deletions
|
@ -2,25 +2,70 @@
|
||||||
/**
|
/**
|
||||||
* RssBridgeYoutube
|
* RssBridgeYoutube
|
||||||
* Returns the newest videos
|
* Returns the newest videos
|
||||||
*
|
* WARNING: to parse big playlists (over ~90 videos), you need to edit simple_html_dom.php:
|
||||||
* @name Youtube Bridge
|
|
||||||
* @homepage https://www.youtube.com/
|
|
||||||
* @description Returns the 10 newest videos by username/channel/playlist or search
|
|
||||||
* @maintainer mitsukarenai
|
|
||||||
* @update 2015-07-08
|
|
||||||
* @use1(u="username")
|
|
||||||
* @use2(c="channel id")
|
|
||||||
* @use3(p="playlist id")
|
|
||||||
* @use4(s="search keyword",pa="page")
|
|
||||||
*
|
|
||||||
* WARNING: to parse big playlists (over ~90 videos), you need to edit simple_html_dom.php:
|
|
||||||
* change: define('MAX_FILE_SIZE', 600000);
|
* change: define('MAX_FILE_SIZE', 600000);
|
||||||
* into: define('MAX_FILE_SIZE', 900000); (or more)
|
* into: define('MAX_FILE_SIZE', 900000); (or more)
|
||||||
*/
|
*/
|
||||||
class YoutubeBridge extends BridgeAbstract{
|
class YoutubeBridge extends BridgeAbstract {
|
||||||
|
|
||||||
private $request;
|
|
||||||
|
public function loadMetadatas() {
|
||||||
|
|
||||||
|
$this->name = "Youtube Bridge";
|
||||||
|
|
||||||
|
$this->homepage = "https://youtube.com";
|
||||||
|
$this->description = "Returns the 10 newest videos by username/channel/playlist or search";
|
||||||
|
$this->maintainer = "mitsukarenai";
|
||||||
|
|
||||||
|
$this->parameters["By username"] =
|
||||||
|
'[
|
||||||
|
{
|
||||||
|
"type" : "text",
|
||||||
|
"identifier" : "u",
|
||||||
|
"name" : "username",
|
||||||
|
"exampleValue" : "test"
|
||||||
|
}
|
||||||
|
]';
|
||||||
|
|
||||||
|
$this->parameters['By channel id'] =
|
||||||
|
'[
|
||||||
|
{
|
||||||
|
"type" : "number",
|
||||||
|
"identifier" : "c",
|
||||||
|
"name" : "channel id",
|
||||||
|
"exampleValue" : "15"
|
||||||
|
}
|
||||||
|
]';
|
||||||
|
|
||||||
|
$this->parameters['By playlist Id'] =
|
||||||
|
'[
|
||||||
|
{
|
||||||
|
"type" : "number",
|
||||||
|
"identifier" : "c",
|
||||||
|
"name" : "playlist id",
|
||||||
|
"exampleValue" : "15"
|
||||||
|
}
|
||||||
|
]';
|
||||||
|
|
||||||
|
$this->parameters["Search result"] =
|
||||||
|
'[
|
||||||
|
{
|
||||||
|
"type" : "text",
|
||||||
|
"identifier" : "s",
|
||||||
|
"name" : "search keyword",
|
||||||
|
"exampleValue" : "test"
|
||||||
|
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type" : "number",
|
||||||
|
"identifier" : "pa",
|
||||||
|
"name" : "page",
|
||||||
|
"exampleValue" : "1"
|
||||||
|
|
||||||
|
}
|
||||||
|
]';
|
||||||
|
}
|
||||||
|
|
||||||
public function collectData(array $param){
|
public function collectData(array $param){
|
||||||
|
|
||||||
function getPublishDate($id) {
|
function getPublishDate($id) {
|
||||||
|
|
138
index.php
138
index.php
|
@ -1,4 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
|
$time_start = microtime(true);
|
||||||
/*
|
/*
|
||||||
TODO :
|
TODO :
|
||||||
- manage SSL detection because if library isn't loaded, some bridge crash !
|
- manage SSL detection because if library isn't loaded, some bridge crash !
|
||||||
|
@ -13,7 +14,7 @@ TODO :
|
||||||
|
|
||||||
date_default_timezone_set('UTC');
|
date_default_timezone_set('UTC');
|
||||||
error_reporting(0);
|
error_reporting(0);
|
||||||
//ini_set('display_errors','1'); error_reporting(E_ALL); // For debugging only.
|
ini_set('display_errors','1'); error_reporting(E_ALL); // For debugging only.
|
||||||
|
|
||||||
// extensions check
|
// extensions check
|
||||||
if (!extension_loaded('openssl'))
|
if (!extension_loaded('openssl'))
|
||||||
|
@ -70,6 +71,7 @@ if (!file_exists($whitelist_file)) {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$whitelist_selection = explode("\n", file_get_contents($whitelist_file));
|
$whitelist_selection = explode("\n", file_get_contents($whitelist_file));
|
||||||
|
array_pop($whitelist_selection);
|
||||||
}
|
}
|
||||||
|
|
||||||
// whitelist control function
|
// whitelist control function
|
||||||
|
@ -153,86 +155,85 @@ function getHelperButtonsFormat($formats){
|
||||||
return $buttons;
|
return $buttons;
|
||||||
}
|
}
|
||||||
|
|
||||||
function displayBridgeCard($bridgeReference, $bridgeInformations, $formats, $isActive = true)
|
function displayBridgeCard($bridgeName, $formats, $isActive = true)
|
||||||
{
|
{
|
||||||
$name = isset($bridgeInformations['homepage']) ? '<a href="'.$bridgeInformations['homepage'].'">'.$bridgeInformations['name'].'</a>' : $bridgeInformations['name'];
|
|
||||||
$description = isset($bridgeInformations['description']) ? $bridgeInformations['description'] : 'No description provided';
|
$bridgeElement = Bridge::create($bridgeName);
|
||||||
|
$bridgeElement->loadMetadatas();
|
||||||
|
|
||||||
|
$name = '<a href="'.$bridgeElement->homepage.'">'.$bridgeElement->name.'</a>';
|
||||||
|
$description = $bridgeElement->description;
|
||||||
|
|
||||||
$card = <<<CARD
|
$card = <<<CARD
|
||||||
<section id="bridge-{$bridgeReference}" data-ref="{$bridgeReference}">
|
<section id="bridge-{$bridgeName}" data-ref="{$bridgeName}">
|
||||||
<h2>{$name}</h2>
|
<h2>{$name}</h2>
|
||||||
<p class="description">
|
<p class="description">
|
||||||
{$description}
|
{$description}
|
||||||
</p>
|
</p>
|
||||||
CARD;
|
CARD;
|
||||||
if( isset($bridgeInformations['use']) && count($bridgeInformations['use']) > 0 )
|
|
||||||
|
// If we don't have any parameter for the bridge, we print a generic form to load it.
|
||||||
|
if(count($bridgeElement->parameters) == 0) {
|
||||||
|
|
||||||
|
$card .= '<form method="GET" action="?">
|
||||||
|
<input type="hidden" name="action" value="display" />
|
||||||
|
<input type="hidden" name="bridge" value="' . $bridgeName . '" />' . PHP_EOL;
|
||||||
|
|
||||||
|
if ($isActive)
|
||||||
{
|
{
|
||||||
$card .= '<ol class="list-use">' . PHP_EOL;
|
$card .= getHelperButtonsFormat($formats);
|
||||||
foreach($bridgeInformations['use'] as $anUseNum => $anUse)
|
|
||||||
{
|
|
||||||
$card .= '<li data-use="' . $anUseNum . '">' . PHP_EOL;
|
|
||||||
$card .= '<form method="GET" action="?">
|
|
||||||
<input type="hidden" name="action" value="display" />
|
|
||||||
<input type="hidden" name="bridge" value="' . $bridgeReference . '" />' . PHP_EOL;
|
|
||||||
|
|
||||||
foreach($anUse as $argValue)
|
|
||||||
{
|
|
||||||
$idArg = 'arg-' . $bridgeReference . '-' . $anUseNum . '-' . $argValue['query-name'];
|
|
||||||
if($argValue['type'] == null || $argValue['type'] == "text") { //If we have no type, treat it as a text field for compatibility
|
|
||||||
$card .= '<input id="' . $idArg . '" type="text" value="" placeholder="' . $argValue['value'] . '" name="' . $argValue['query-name'] . '" />' . PHP_EOL;
|
|
||||||
} else if($argValue['type'] == "list") {
|
|
||||||
$card .= '<select id="' . $idArg . '" name="' . $argValue['query-name'] . '" >' . PHP_EOL;
|
|
||||||
$optionList = explode(";", $argValue['value']);
|
|
||||||
|
|
||||||
foreach($optionList as $option) {
|
|
||||||
$option = explode("=>", $option);
|
|
||||||
$card .= "<option value='".$option[1]."'>".$option[0]."</option>";
|
|
||||||
}
|
|
||||||
$card .= "</select>";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
$card .= '<br />';
|
|
||||||
|
|
||||||
if ($isActive)
|
|
||||||
{
|
|
||||||
$card .= getHelperButtonsFormat($formats);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$card .= '<span style="font-weight: bold;">Inactive</span>';
|
|
||||||
}
|
|
||||||
|
|
||||||
$card .= '</form></li>' . PHP_EOL;
|
|
||||||
}
|
|
||||||
$card .= '</ol>' . PHP_EOL;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$card .= '<form method="GET" action="?">
|
$card .= '<span style="font-weight: bold;">Inactive</span>';
|
||||||
<input type="hidden" name="action" value="display" />
|
|
||||||
<input type="hidden" name="bridge" value="' . $bridgeReference . '" />' . PHP_EOL;
|
|
||||||
|
|
||||||
if ($isActive)
|
|
||||||
{
|
|
||||||
$card .= getHelperButtonsFormat($formats);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$card .= '<span style="font-weight: bold;">Inactive</span>';
|
|
||||||
}
|
|
||||||
$card .= '</form>' . PHP_EOL;
|
|
||||||
}
|
}
|
||||||
|
$card .= '</form>' . PHP_EOL;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
$card .= isset($bridgeInformations['maintainer']) ? '<span class="maintainer">'.$bridgeInformations['maintainer'].'</span>' : '';
|
foreach($bridgeElement->parameters as $parameterName => $parameter)
|
||||||
|
{
|
||||||
|
$card .= '<ol class="list-use">' . PHP_EOL;
|
||||||
|
$card .= '<h5>'.$parameterName.'</h5>' . PHP_EOL;
|
||||||
|
$card .= '<form method="GET" action="?">
|
||||||
|
<input type="hidden" name="action" value="display" />
|
||||||
|
<input type="hidden" name="bridge" value="' . $bridgeName . '" />' . PHP_EOL;
|
||||||
|
|
||||||
|
$parameter = json_decode($parameter, true);
|
||||||
|
|
||||||
|
foreach($parameter as $inputEntry) {
|
||||||
|
|
||||||
|
$idArg = 'arg-' . $bridgeName . '-' . $parameterName . '-' . $inputEntry['identifier'];
|
||||||
|
|
||||||
|
$card .= '<label for="' .$idArg. '">' .$inputEntry['name']. ' : </label>' . PHP_EOL;
|
||||||
|
|
||||||
|
if(!isset($inputEntry['type']) || $inputEntry['type'] == 'text') {
|
||||||
|
$card .= '<input id="' . $idArg . '" type="text" value="" placeholder="' . $inputEntry['exampleValue'] . '" name="' . $inputEntry['identifier'] . '" /><br />' . PHP_EOL;
|
||||||
|
} else if($inputEntry['type'] == 'number') {
|
||||||
|
$card .= '<input id="' . $idArg . '" type="number" value="" placeholder="' . $inputEntry['exampleValue'] . '" name="' . $inputEntry['identifier'] . '" /><br />' . PHP_EOL;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if ($isActive)
|
||||||
|
{
|
||||||
|
$card .= getHelperButtonsFormat($formats);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$card .= '<span style="font-weight: bold;">Inactive</span>';
|
||||||
|
}
|
||||||
|
$card .= '</form>' . PHP_EOL;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$card .= '<span class="maintainer">'.$bridgeElement->maintainer.'</span>';
|
||||||
$card .= '</section>';
|
$card .= '</section>';
|
||||||
|
|
||||||
return $card;
|
return $card;
|
||||||
}
|
}
|
||||||
|
|
||||||
$bridges = Bridge::searchInformation();
|
|
||||||
$formats = Format::searchInformation();
|
$formats = Format::searchInformation();
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
@ -257,24 +258,27 @@ $formats = Format::searchInformation();
|
||||||
$activeFoundBridgeCount = 0;
|
$activeFoundBridgeCount = 0;
|
||||||
$showInactive = isset($_REQUEST['show_inactive']) && $_REQUEST['show_inactive'] == 1;
|
$showInactive = isset($_REQUEST['show_inactive']) && $_REQUEST['show_inactive'] == 1;
|
||||||
$inactiveBridges = '';
|
$inactiveBridges = '';
|
||||||
foreach($bridges as $bridgeReference => $bridgeInformations)
|
foreach($whitelist_selection as $bridgeName)
|
||||||
{
|
{
|
||||||
if(BridgeWhitelist($whitelist_selection, $bridgeReference))
|
if(BridgeWhitelist($whitelist_selection, $bridgeName))
|
||||||
{
|
{
|
||||||
echo displayBridgeCard($bridgeReference, $bridgeInformations, $formats);
|
echo displayBridgeCard($bridgeName, $formats);
|
||||||
$activeFoundBridgeCount++;
|
$activeFoundBridgeCount++;
|
||||||
}
|
}
|
||||||
elseif ($showInactive)
|
elseif ($showInactive)
|
||||||
{
|
{
|
||||||
// inactive bridges
|
// inactive bridges
|
||||||
$inactiveBridges .= displayBridgeCard($bridgeReference, $bridgeInformations, $formats, false) . PHP_EOL;
|
$inactiveBridges .= displayBridgeCard($bridgeName, $formats, false) . PHP_EOL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
echo '<hr />' . $inactiveBridges;
|
echo '<hr />' . $inactiveBridges;
|
||||||
?>
|
?>
|
||||||
<footer>
|
<footer>
|
||||||
<?= $activeFoundBridgeCount; ?>/<?= count($bridges) ?> active bridges (<a href="?show_inactive=1">Show inactive</a>)<br />
|
<?= $activeFoundBridgeCount; ?>/<?= count($whitelist_selection) ?> active bridges (<a href="?show_inactive=1">Show inactive</a>)<br />
|
||||||
<a href="https://github.com/sebsauvage/rss-bridge">RSS-Bridge alpha 0.1 ~ Public Domain</a>
|
<a href="https://github.com/sebsauvage/rss-bridge">RSS-Bridge alpha 0.1 ~ Public Domain</a>
|
||||||
</footer>
|
</footer>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
<?php
|
||||||
|
echo "Ran for ". (microtime(true) - $time_start);
|
||||||
|
?>
|
||||||
|
|
|
@ -9,12 +9,28 @@ interface BridgeInterface{
|
||||||
public function getName();
|
public function getName();
|
||||||
public function getURI();
|
public function getURI();
|
||||||
public function getCacheDuration();
|
public function getCacheDuration();
|
||||||
|
public function loadMetadatas();
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class BridgeAbstract implements BridgeInterface{
|
abstract class BridgeAbstract implements BridgeInterface{
|
||||||
|
|
||||||
protected $cache;
|
protected $cache;
|
||||||
protected $items = array();
|
protected $items = array();
|
||||||
|
|
||||||
|
public $name = "Bridge sans nom";
|
||||||
|
public $homepage = "";
|
||||||
|
public $description = 'No description provided';
|
||||||
|
public $maintainer = 'No maintainer';
|
||||||
|
public $parameters = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads the Bridge Metadatas
|
||||||
|
*/
|
||||||
|
public function loadMetadatas() {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Launch probative exception
|
* Launch probative exception
|
||||||
*/
|
*/
|
||||||
|
@ -30,6 +46,8 @@ abstract class BridgeAbstract implements BridgeInterface{
|
||||||
return $this->items;
|
return $this->items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defined datas with parameters depending choose bridge
|
* Defined datas with parameters depending choose bridge
|
||||||
* Note : you can defined a cache before with "setCache"
|
* Note : you can defined a cache before with "setCache"
|
||||||
|
|
Loading…
Reference in a new issue