From 837102773006b1c48548085198800d3755228d7b Mon Sep 17 00:00:00 2001 From: Jonas Heinrich Date: Sat, 13 Mar 2021 13:37:15 +0100 Subject: [PATCH] add export favorite stations as playlist (fixes #105) --- CHANGELOG.md | 2 ++ lib/Controller/ExportController.php | 18 +++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8aed7cd..7d7d17b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ [#251](https://git.project-insanity.org/onny/nextcloud-app-radio/-/issues/251) @onny - Support add stations manually [#157](https://git.project-insanity.org/onny/nextcloud-app-radio/-/issues/157) @onny +- Export favorite radio stations as playlist + [#105](https://git.project-insanity.org/onny/nextcloud-app-radio/-/issues/105) @onny ### Fixed - Cleanup SCSS diff --git a/lib/Controller/ExportController.php b/lib/Controller/ExportController.php index 383673f..abd55e5 100644 --- a/lib/Controller/ExportController.php +++ b/lib/Controller/ExportController.php @@ -31,6 +31,7 @@ use OCP\AppFramework\Controller; use OCP\AppFramework\Http\DataResponse; use OCP\IRequest; use SimpleXMLElement; +use DOMDocument; class ExportController extends Controller { /** @var FavoriteService */ @@ -57,12 +58,19 @@ class ExportController extends Controller { $xml = new SimpleXMLElement(''); $xml->addAttribute('encoding', 'UTF-8'); $trackList = $xml->addChild('trackList'); - $track = $trackList->addChild('track'); - $track->addChild('location', 'http://localhost/test.mp3'); - $track->addChild('title', 'Radio Test 404fm'); - $track->addChild('image', 'http://localhost/favicon.ico'); + foreach($this->service->findAll($this->userId) as $station) { + $track = $trackList->addChild('track'); + $track->addChild('location', $station->getUrlresolved()); + $track->addChild('title', $station->getName()); + $track->addChild('image', $station->getFavicon()); + } - return new ExportResponse($xml->asXML()); + $dom = new DOMDocument("1.0"); + $dom->preserveWhiteSpace = false; + $dom->formatOutput = true; + $dom->loadXML($xml->asXML()); + + return new ExportResponse($dom->saveXML()); }