/** * Get the name of the playlist. * * @return string */ public function getName() { if ($this->name === null) { $data = $this->browse("Metadata"); $xml = new XmlParser($data["Result"]); $this->name = $xml->getTag("title")->nodeValue; } return $this->name; }
/** * Get the favourite radio shows/stations. * * @param int $type One of the class constants for either shows or stations * * @return Stream[] */ protected function getFavourites($type) { $items = []; $result = $this->controller->soap("ContentDirectory", "Browse", ["ObjectID" => "R:0/{$type}", "BrowseFlag" => "BrowseDirectChildren", "Filter" => "*", "StartingIndex" => 0, "RequestedCount" => 100, "SortCriteria" => ""]); $parser = new XmlParser($result["Result"]); $tagName = $type === self::STATIONS ? "item" : "container"; foreach ($parser->getTags($tagName) as $tag) { $name = $tag->getTag("title")->nodeValue; $uri = $tag->getTag("res")->nodeValue; $items[] = new Stream($uri, $name); } return $items; }
/** * Get attributes about the currently active track in the queue. * * @return State Track data containing the following elements */ public function getStateDetails() { $data = $this->soap("AVTransport", "GetPositionInfo"); if (!$data["TrackMetaData"]) { return new State(); } $parser = new XmlParser($data["TrackMetaData"]); $state = State::createFromXml($parser->getTag("item"), $this); if ((string) $parser->getTag("streamContent")) { $info = $this->getMediaInfo(); if (!($state->stream = (string) (new XmlParser($info["CurrentURIMetaData"]))->getTag("title"))) { $state->stream = (string) $parser->getTag("title"); } } $state->queueNumber = (int) $data["Track"]; $state->duration = $data["TrackDuration"]; $state->position = $data["RelTime"]; # If we have a queue number, it'll be one-based, rather than zero-based, so convert it if ($state->queueNumber > 0) { $state->queueNumber--; } return $state; }
/** * Get tracks from the queue. * * @param int $start The zero-based position in the queue to start from * @param int $total The maximum number of tracks to return * * @return Track[] */ public function getTracks($start = 0, $total = 0) { $tracks = []; if ($total > 0 && $total < 100) { $limit = $total; } else { $limit = 100; } do { $data = $this->browse("DirectChildren", $start, $limit); $parser = new XmlParser($data["Result"]); foreach ($parser->getTags("item") as $item) { $tracks[] = $this->trackFactory->createFromXml($item); if ($total > 0 && count($tracks) >= $total) { return $tracks; } } $start += $limit; } while ($data["NumberReturned"] && $data["TotalMatches"] && count($tracks) < $data["TotalMatches"]); return $tracks; }
/** * Get all the alarms available on the network. * * @return Alarm[] */ public function getAlarms() { if (is_array($this->alarms)) { return $this->alarms; } $data = $this->getController()->soap("AlarmClock", "ListAlarms"); $parser = new XmlParser($data["CurrentAlarmList"]); $alarms = []; foreach ($parser->getTags("Alarm") as $tag) { $alarms[] = new Alarm($tag, $this); } return $this->alarms = $alarms; }