Download API exemple
This commit is contained in:
parent
36d7069512
commit
5de23258c6
|
@ -6,4 +6,5 @@
|
||||||
/composer.phar
|
/composer.phar
|
||||||
|
|
||||||
# Project files
|
# Project files
|
||||||
|
/exemple/dl_rss/app_token
|
||||||
/app_token
|
/app_token
|
17
README.md
17
README.md
|
@ -1,11 +1,11 @@
|
||||||
|
|
||||||
# Freebox v6 PHP API v3
|
# Freebox v6 PHP API v3
|
||||||
|
|
||||||
Implementation PHP de l'API de la freebox.
|
Implementation PHP de l'API de la freebox (dans sa version 3).
|
||||||
|
|
||||||
## Prérequis
|
## Prérequis
|
||||||
|
|
||||||
Ce projet est basé sur composer. Pensez a installer les dependences :)
|
Ce projet est basé sur **composer**. Pensez à installer les dependences :)
|
||||||
|
|
||||||
## Utilisation
|
## Utilisation
|
||||||
|
|
||||||
|
@ -22,8 +22,10 @@ $App->openSession();
|
||||||
```
|
```
|
||||||
|
|
||||||
### Services
|
### Services
|
||||||
Les appels aux services de l'API se font de la maniere suivante :
|
Les appels aux services de l'API se font par l'intermédiaire de services.
|
||||||
Voiuci un exemple d'utilisation de l'API System.
|
Ces derniers possedent les méthodes pour récuperer, ajouter ou mettre a jour des données.
|
||||||
|
|
||||||
|
Voici un exemple d'utilisation de l'API System.
|
||||||
1. Nous créons un nouveau service "System"
|
1. Nous créons un nouveau service "System"
|
||||||
2. Nous demandons de récuperer la configuration actuelle
|
2. Nous demandons de récuperer la configuration actuelle
|
||||||
3. Nous utilisons le modele retourné pour acceder a la donnée `uptime`
|
3. Nous utilisons le modele retourné pour acceder a la donnée `uptime`
|
||||||
|
@ -36,3 +38,10 @@ $SystemConfig = $System->getConfiguration();
|
||||||
|
|
||||||
\alphayax\utils\cli\IO::stdout( 'Uptime : '. $SystemConfig->uptime);
|
\alphayax\utils\cli\IO::stdout( 'Uptime : '. $SystemConfig->uptime);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Exemples
|
||||||
|
|
||||||
|
Les exemples sont disponibles dans le repertoire `exemple`:
|
||||||
|
- `dhcp_config` : Un script pour récuperer la configuration courrante du DHCP
|
||||||
|
- `dl_rss` : Un script qui parse les flux RSS et qui rajoute en téléchagement les items correspondant a une expression réguliere
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/// Require Composer AutoLoader
|
/// Require Composer AutoLoader
|
||||||
require_once 'vendor/autoload.php';
|
require_once '../../vendor/autoload.php';
|
||||||
|
|
||||||
/// Define our application
|
/// Define our application
|
||||||
$App = new \alphayax\freebox\utils\Application( 'com.alphayax.freebox.example', 'Freebox PHP API Exemple', '0.0.2');
|
$App = new \alphayax\freebox\utils\Application( 'com.alphayax.freebox.example', 'Freebox PHP API Example', '0.0.2');
|
||||||
$App->authorize();
|
$App->authorize();
|
||||||
$App->openSession();
|
$App->openSession();
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"rss": "https:\/\/www.nyaa.se\/?page=rss&user=175467",
|
||||||
|
"pattern": "\/One_Piece.*HD.*mp4\/",
|
||||||
|
"last_date": 1457259493
|
||||||
|
}
|
|
@ -0,0 +1,50 @@
|
||||||
|
<?php
|
||||||
|
use alphayax\utils\cli\IO;
|
||||||
|
|
||||||
|
/// Require Composer AutoLoader
|
||||||
|
require_once '../../vendor/autoload.php';
|
||||||
|
|
||||||
|
/// Define our application
|
||||||
|
$App = new \alphayax\freebox\utils\Application( 'com.alphayax.freebox.example', 'Freebox PHP API Example', '0.0.2');
|
||||||
|
$App->authorize();
|
||||||
|
$App->openSession();
|
||||||
|
|
||||||
|
/// Scan files for configs
|
||||||
|
$config_rfi_s = glob( 'config/*.json');
|
||||||
|
foreach( $config_rfi_s as $config_rfi){
|
||||||
|
$config = json_decode( file_get_contents( $config_rfi), true);
|
||||||
|
$config = checkRSS( $config, $App);
|
||||||
|
file_put_contents( $config_rfi, json_encode( $config, JSON_PRETTY_PRINT));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $config
|
||||||
|
* @param $App
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
function checkRSS( $config, $App){
|
||||||
|
IO::stdout( "Scan RSS {$config['rss']} for pattern {$config['pattern']}", 0, true, IO::COLOR_YELLOW);
|
||||||
|
$rss = simplexml_load_file( $config['rss']);
|
||||||
|
foreach( $rss->xpath('//item') as $item){
|
||||||
|
$title = (string) $item->xpath('title')[0];
|
||||||
|
$date = (string) $item->xpath('pubDate')[0];
|
||||||
|
$link = (string) $item->xpath('link')[0];
|
||||||
|
$desc = (string) $item->xpath('description')[0];
|
||||||
|
if( preg_match( $config['pattern'], $title)){
|
||||||
|
if( strtotime( $date) > $config['last_date']){
|
||||||
|
$config['last_date'] = strtotime( $date);
|
||||||
|
|
||||||
|
$Downloads = new \alphayax\freebox\api\v3\services\download\Download( $App);
|
||||||
|
$Downloads->addFromUrl( $link);
|
||||||
|
|
||||||
|
IO::stdout( "Add download $title ($desc)", 0, true, IO::COLOR_GREEN);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $config;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -136,11 +136,11 @@ class Download extends Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ! empty( $archive_password)){
|
if( ! empty( $archive_password)){
|
||||||
$params['archive_password'] = $password;
|
$params['archive_password'] = $archive_password;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( ! empty( $cookies)){
|
if( ! empty( $cookies)){
|
||||||
$params['cookies'] = $password;
|
$params['cookies'] = $cookies;
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = http_build_query( $params);
|
$data = http_build_query( $params);
|
||||||
|
|
|
@ -1,48 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
/// Require Composer AutoLoader
|
|
||||||
use alphayax\utils\cli\IO;
|
|
||||||
|
|
||||||
require_once 'vendor/autoload.php';
|
|
||||||
|
|
||||||
/// Define our application
|
|
||||||
$App = new \alphayax\freebox\utils\Application( 'com.alphayax.freebox.example', 'Freebox PHP API Exemple', '0.0.2');
|
|
||||||
$App->authorize();
|
|
||||||
$App->openSession();
|
|
||||||
|
|
||||||
|
|
||||||
//--
|
|
||||||
if( file_exists( 'one_piece')){
|
|
||||||
$toto = json_decode( file_get_contents( 'one_piece'), true);
|
|
||||||
} else {
|
|
||||||
$toto = [
|
|
||||||
'rss' => 'https://www.nyaa.se/?page=rss&user=175467',
|
|
||||||
'pattern' => '/One_Piece.*HD.*mp4/',
|
|
||||||
'last_date' => 1456388223,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
$rss = simplexml_load_file( $toto['rss']);
|
|
||||||
foreach( $rss->xpath('//item') as $item){
|
|
||||||
$title = (string) $item->xpath('title')[0];
|
|
||||||
$date = (string) $item->xpath('pubDate')[0];
|
|
||||||
$link = (string) $item->xpath('link')[0];
|
|
||||||
$desc = (string) $item->xpath('description')[0];
|
|
||||||
if( preg_match( $toto['pattern'], $title)){
|
|
||||||
if( strtotime( $date) > $toto['last_date']){
|
|
||||||
// echo $title . ' '. $link . ' ' . $desc . PHP_EOL;
|
|
||||||
$toto['last_date'] = strtotime( $date);
|
|
||||||
|
|
||||||
$Downloads = new \alphayax\freebox\api\v3\services\download\Download( $App);
|
|
||||||
$dl_id = $Downloads->addFromUrl( $link);
|
|
||||||
|
|
||||||
IO::stdout( "Download $title added (id=$dl_id)", 0, true, IO::COLOR_GREEN);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
file_put_contents( 'one_piece', json_encode( $toto, JSON_PRETTY_PRINT));
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue