diff --git a/README.md b/README.md index 0401bdb..e4d9931 100644 --- a/README.md +++ b/README.md @@ -26,9 +26,10 @@ Jusqu'a présent, les fonctionalités suivantes ont été implémentées : - FsListing - FileUpload - FileSharing -- Downloads +- DownloadStats - Download (core) - Download Stats + - Download Files - Configuration - Connection - Connection (Core) @@ -122,6 +123,7 @@ Les exemples sont disponibles dans le repertoire `exemple`. Ils sont classés pa - `PortForwarding` : Exemple d'ajout d'une redirection de port - `System` : Affichage de la configuration système de la freebox - `download` + - `Download` : Listage des téléchargement en cours, liste des fichiers d'un téléchargement et mise a jour de la priorité de téléchargement - `dl_rss` : Un script qui parse les flux RSS et qui rajoute en téléchagement les items correspondant a une expression réguliere \ No newline at end of file diff --git a/TODO.md b/TODO.md index 7cdac8a..00690a8 100644 --- a/TODO.md +++ b/TODO.md @@ -1,7 +1,7 @@ - Downloads - ~~Download~~ - ~~Download Stats~~ - - Download Files + - ~~Download Files~~ - Download Trackers [UNSTABLE] - Download Peers [UNSTABLE] - Download Blacklist [UNSTABLE] diff --git a/exemple/download/Download.php b/exemple/download/Download.php index 0312463..31eb3f0 100644 --- a/exemple/download/Download.php +++ b/exemple/download/Download.php @@ -16,3 +16,14 @@ print_r( $Downloads); /// Stats $Stats = $DownloadService->getStats(); print_r( $Stats); + +/// Files +$Files = $DownloadService->getFilesFromId( $Downloads[0]->getId()); +print_r( $Files); + +/// Priority +$Success = $DownloadService->updateFilePriority( $Downloads[0]->getId(), $Files[0]->getId(), \alphayax\freebox\api\v3\symbols\Download\File\Priority::HIGH); +print_r( $Success); +$Files = $DownloadService->getFilesFromId( $Downloads[0]->getId()); +print_r( $Files); + diff --git a/freebox/api/v3/models/Download/File.php b/freebox/api/v3/models/Download/File.php new file mode 100644 index 0000000..f092af7 --- /dev/null +++ b/freebox/api/v3/models/Download/File.php @@ -0,0 +1,138 @@ +id; + } + + /** + * @return int + */ + public function getTaskId() { + return $this->task_id; + } + + /** + * @return mixed + * @deprecated + */ + public function getPath() { + return $this->path; + } + + /** + * @return string + */ + public function getFilepath() { + return base64_decode( $this->filepath); + } + + /** + * @return string + */ + public function getName() { + return $this->name; + } + + /** + * @return string + */ + public function getMimetype() { + return $this->mimetype; + } + + /** + * @return int + */ + public function getSize() { + return $this->size; + } + + /** + * @return int + */ + public function getRx() { + return $this->rx; + } + + /** + * @return string + */ + public function getStatus() { + return $this->status; + } + + /** + * @return string + */ + public function getPriority() { + return $this->priority; + } + + /** + * @param string $priority + */ + public function setPriority( $priority) { + $this->priority = $priority; + } + + /** + * @return string + */ + public function getError() { + return $this->error; + } + +} diff --git a/freebox/api/v3/models/FileSystem/FileInfo.php b/freebox/api/v3/models/FileSystem/FileInfo.php index 574bee3..c238266 100644 --- a/freebox/api/v3/models/FileSystem/FileInfo.php +++ b/freebox/api/v3/models/FileSystem/FileInfo.php @@ -141,5 +141,4 @@ class FileInfo extends Model { return $this->filecount; } - } diff --git a/freebox/api/v3/services/download/Download.php b/freebox/api/v3/services/download/Download.php index 7b77d6b..eebca04 100644 --- a/freebox/api/v3/services/download/Download.php +++ b/freebox/api/v3/services/download/Download.php @@ -15,6 +15,7 @@ class Download extends Service { const API_DOWNLOAD_ERASE = '/api/v3/downloads/%s/erase/'; const API_DOWNLOAD_ADD = '/api/v3/downloads/add/'; const API_DOWNLOAD_STATS = '/api/v3/downloads/stats'; + const API_DOWNLOAD_FILES = '/api/v3/downloads/%u/files'; /** * Returns the collection of all Download tasks @@ -184,8 +185,6 @@ class Download extends Service { return $rest->getCurlResponse()['result']['id']; } - - /** * Returns the Download task with the given id * @return models\Download\Task @@ -197,4 +196,39 @@ class Download extends Service { return new models\Download\Stats\DownloadStats( $rest->getCurlResponse()['result']); } + /** + * Returns the Download task with the given id + * @param int $taskId + * @return models\Download\File[] + */ + public function getFilesFromId( $taskId){ + $Service = sprintf( self::API_DOWNLOAD_FILES, $taskId); + $rest = $this->getAuthService( $Service); + $rest->GET(); + + $DownloadFile_xs = @$rest->getCurlResponse()['result'] ?: []; + $DownloadFiles = []; + foreach( $DownloadFile_xs as $DownloadFile_x) { + $DownloadFiles[] = new models\Download\File( $DownloadFile_x); + } + return $DownloadFiles; + } + + /** + * @param int $downloadTaskId + * @param string $FileId + * @param string $Priority + * @see alphayax\freebox\api\v3\symbols\Download\File\Priority + * @return + */ + public function updateFilePriority( $downloadTaskId, $FileId, $Priority){ + $Service = sprintf( self::API_DOWNLOAD_FILES, $downloadTaskId); + $rest = $this->getAuthService( $Service . DIRECTORY_SEPARATOR . $FileId); + $rest->PUT([ + 'priority' => $Priority, + ]); + + return $rest->getCurlResponse()['success']; + } + } diff --git a/freebox/api/v3/symbols/Download/File/Priority.php b/freebox/api/v3/symbols/Download/File/Priority.php new file mode 100644 index 0000000..8966656 --- /dev/null +++ b/freebox/api/v3/symbols/Download/File/Priority.php @@ -0,0 +1,21 @@ +