Browse Source

Podcast categories

master
J. King 4 years ago
parent
commit
0ac99dfc91
  1. 7
      lib/Category/Category.php
  2. 11
      lib/Parser/XML/Construct.php
  3. 50
      tests/cases/XML/feed-other.yaml

7
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;

11
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)) {

50
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: >
<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
<channel>
@ -12,7 +12,7 @@ iPod expiration marker 1:
sched:
expired: true
iPod expiration marker 2:
iTunes expiration marker 2:
input: >
<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
<channel>
@ -25,7 +25,7 @@ iPod expiration marker 2:
sched:
expired: true
iPod expiration marker 3:
iTunes expiration marker 3:
input: >
<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
<channel>
@ -35,7 +35,7 @@ iPod expiration marker 3:
output:
format: rss
iPod canonical URL:
iTunes canonical URL:
input: >
<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
<channel>
@ -47,7 +47,7 @@ iPod canonical URL:
format: rss
url: 'http://example.com/'
iPod title:
iTunes title:
input: >
<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
<channel>
@ -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: >
<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
<channel>
@ -101,3 +101,41 @@ Google Play image:
output:
format: rss
image: 'http://example.com/'
iTunes categories:
input: >
<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:play="http://www.google.com/schemas/play-podcasts/1.0"><channel>
<itunes:category text="Arts"/>
<itunes:category text="Arts ">
<itunes:category text=" Fashion &amp; Beauty"/>
</itunes:category>
<itunes:category text="Arts ">
<itunes:category text=" "/>
<itunes:category text="Books"/>
<itunes:category text="Design"/>
</itunes:category>
<itunes:category text=" "/>
<itunes:category>Bogus</itunes:category>
</channel></rss>
output:
format: rss
categories:
- name: Arts
- name: Arts
subcategory: 'Fashion & Beauty'
- name: Arts
subcategory: Books
Google Play categories:
input: >
<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:play="http://www.google.com/schemas/play-podcasts/1.0"><channel>
<play:category text="Arts"/>
<play:category text=" "/>
<play:category>Bogus</play:category>
<play:category text="Music"/>
</channel></rss>
output:
format: rss
categories:
- name: Arts
- name: Music

Loading…
Cancel
Save