From 0ac99dfc91ee0ea08b10118e1fbe73f194c0bad7 Mon Sep 17 00:00:00 2001 From: "J. King" Date: Fri, 20 Mar 2020 11:13:32 -0400 Subject: [PATCH] Podcast categories --- lib/Category/Category.php | 7 +++-- lib/Parser/XML/Construct.php | 11 ++++++-- tests/cases/XML/feed-other.yaml | 50 +++++++++++++++++++++++++++++---- 3 files changed, 57 insertions(+), 11 deletions(-) diff --git a/lib/Category/Category.php b/lib/Category/Category.php index eff2f39..3333da0 100644 --- a/lib/Category/Category.php +++ b/lib/Category/Category.php @@ -7,9 +7,10 @@ declare(strict_types=1); namespace MensBeam\Lax\Category; class Category { - public $name = ""; - public $label = ""; - public $domain = ""; + public $name; + public $label; + public $domain; + public $subcategory; public function __toString() { return strlen(strlen((string) $this->label)) ? $this->label : $this->name; diff --git a/lib/Parser/XML/Construct.php b/lib/Parser/XML/Construct.php index 2d07733..14f24c0 100644 --- a/lib/Parser/XML/Construct.php +++ b/lib/Parser/XML/Construct.php @@ -372,10 +372,17 @@ abstract class Construct { protected function getCategoriesTunes(): ?CategoryCollection { $out = new CategoryCollection; - foreach ($this->xpath->query("apple:category", $this->subject) ?? [] as $node) { + foreach ($this->xpath->query("apple:category", $this->subject) as $node) { $c = new Category; $c->name = $this->trimText($node->getAttribute("text")); if (strlen($c->name)) { + foreach ($this->xpath->query("apple:category", $node) as $sub) { + $sname = $this->trimText($sub->getAttribute("text")); + if (strlen($sname)) { + $c->subcategory = $sname; + break; + } + } $out[] = $c; } } @@ -384,7 +391,7 @@ abstract class Construct { protected function getCategoriesGPlay(): ?CategoryCollection { $out = new CategoryCollection; - foreach ($this->xpath->query("gplay:category", $this->subject) ?? [] as $node) { + foreach ($this->xpath->query("gplay:category", $this->subject) as $node) { $c = new Category; $c->name = $this->trimText($node->getAttribute("text")); if (strlen($c->name)) { diff --git a/tests/cases/XML/feed-other.yaml b/tests/cases/XML/feed-other.yaml index 48770e9..df20c1a 100644 --- a/tests/cases/XML/feed-other.yaml +++ b/tests/cases/XML/feed-other.yaml @@ -1,6 +1,6 @@ # This file tests extensions primarily designed for RSS 2 -iPod expiration marker 1: +iTunes expiration marker 1: input: > @@ -12,7 +12,7 @@ iPod expiration marker 1: sched: expired: true -iPod expiration marker 2: +iTunes expiration marker 2: input: > @@ -25,7 +25,7 @@ iPod expiration marker 2: sched: expired: true -iPod expiration marker 3: +iTunes expiration marker 3: input: > @@ -35,7 +35,7 @@ iPod expiration marker 3: output: format: rss -iPod canonical URL: +iTunes canonical URL: input: > @@ -47,7 +47,7 @@ iPod canonical URL: format: rss url: 'http://example.com/' -iPod title: +iTunes title: input: > @@ -60,7 +60,7 @@ iPod title: title: plain: 'Plain text' -iPod summary: # Apple's own documentation doesn't mention a namespaced summary element, but Google's does +iTunes summary: # Apple's own documentation doesn't mention a namespaced summary element, but Google's does input: > @@ -101,3 +101,41 @@ Google Play image: output: format: rss image: 'http://example.com/' + +iTunes categories: + input: > + + + + + + + + + + + + Bogus + + output: + format: rss + categories: + - name: Arts + - name: Arts + subcategory: 'Fashion & Beauty' + - name: Arts + subcategory: Books + +Google Play categories: + input: > + + + + Bogus + + + output: + format: rss + categories: + - name: Arts + - name: Music