Browse Source

Correct podcast person semantics

master
J. King 4 years ago
parent
commit
bbeb73eb56
  1. 17
      lib/Parser/XML/Construct.php
  2. 25
      lib/Parser/XML/Feed.php
  3. 128
      tests/cases/XML/feed-other.yaml

17
lib/Parser/XML/Construct.php

@ -189,23 +189,6 @@ abstract class Construct {
return count($out) ? $out : null;
}
/** Returns at most a single person: podcasts implicitly have only one author or webmaster */
protected function fetchPodPerson(string $prefix, string $role): ?PersonCollection {
assert(in_array($prefix, ["apple", "gplay"]));
assert(in_array($role, ["author", "webmaster"]));
$prefix = ($role === "webmaster") ? "$prefix:owner/$prefix" : $prefix;
$out = new PersonCollection;
$p = new Person;
$mail = $this->fetchString("$prefix:email") ?? "";
$p->mail = $this->validateMail($mail) ? $mail : null;
$p->name = $this->fetchString("$prefix:name", ".+") ?? "";
$p->role = $role;
if (strlen($p->name)) {
$out[] = $p;
}
return count($out) ? $out : null;
}
/** Returns a node-list of Atom link elements with the desired relation or equivalents.
*
* Links without an href attribute are excluded.

25
lib/Parser/XML/Feed.php

@ -7,6 +7,7 @@ declare(strict_types=1);
namespace MensBeam\Lax\Parser\XML;
use MensBeam\Lax\Parser\Exception;
use MensBeam\Lax\Person\Person;
use MensBeam\Lax\Person\Collection as PersonCollection;
use MensBeam\Lax\Category\Collection as CategoryCollection;
use MensBeam\Lax\Feed as FeedStruct;
@ -198,8 +199,8 @@ class Feed extends Construct implements \MensBeam\Lax\Parser\Feed {
$this->fetchAtomPeople("atom:author", "author") // Atom authors
?? $this->fetchPeople("dc:creator", "author") // Dublin Core creators
?? $this->fetchPeople("rss2:author", "author") // RSS 2.0 authors
?? $this->fetchPodPerson("gplay", "author") // Google Play author
?? $this->fetchPodPerson("apple", "author") // iTunes author
?? $this->fetchPeople("gplay:author", "author") // Google Play authors
?? $this->fetchPeople("apple:author", "author") // iTunes authors
?? new PersonCollection;
$contributors =
$this->fetchAtomPeople("atom:contributor", "contributor") // Atom contributors
@ -211,8 +212,8 @@ class Feed extends Construct implements \MensBeam\Lax\Parser\Feed {
?? new PersonCollection;
$webmasters =
$this->fetchPeople("rss2:webMaster", "webmaster") // RSS 2.0 authors
?? $this->fetchPodPerson("gplay", "webmaster") // Google Play webmaster
?? $this->fetchPodPerson("apple", "webmaster") // iTunes webmaster
?? $this->getOwnersTunes() // iTunes webmaster
?? $this->fetchPeople("gplay:email", "webmaster") // Google Play webmaster
?? new PersonCollection;
return $authors->merge($contributors, $editors, $webmasters);
}
@ -313,4 +314,20 @@ class Feed extends Construct implements \MensBeam\Lax\Parser\Feed {
}
return $out ?: null;
}
/** Returns at most a single person: podcasts implicitly have only one author or webmaster */
protected function getOwnersTunes(): ?PersonCollection {
$out = new PersonCollection;
foreach ($this->xpath->query("apple:owner", $this->subject) as $node) {
$p = new Person;
$mail = $this->fetchString("apple:email", null, null, $node) ?? "";
$p->mail = $this->validateMail($mail) ? $mail : null;
$p->name = $this->fetchString("apple:name", ".+", null, $node) ?? $mail;
$p->role = "webmaster";
if (strlen($p->name)) {
$out[] = $p;
}
}
return count($out) ? $out : null;
}
}

128
tests/cases/XML/feed-other.yaml

@ -140,11 +140,10 @@ Google Play categories:
- name: Arts
- name: Music
iTunes author 1:
iTunes author:
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:author>Jane Doe</itunes:author>
<itunes:email>jane.doe@example.com</itunes:email>
<itunes:author>jane.doe@example.com (Jane Doe)</itunes:author>
</channel></rss>
output:
format: rss
@ -153,41 +152,6 @@ iTunes author 1:
mail: 'jane.doe@example.com'
role: author
iTunes author 2:
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:author>Jane Doe</itunes:author>
<itunes:email>bogus@example].com</itunes:email>
</channel></rss>
output:
format: rss
people:
- name: 'Jane Doe'
role: author
iTunes author 3:
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:author/>
<itunes:author>Jane Doe</itunes:author>
<itunes:email>jane.doe@example.com</itunes:email>
</channel></rss>
output:
format: rss
people:
- name: 'Jane Doe'
mail: 'jane.doe@example.com'
role: author
iTunes author 4:
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:author/>
<itunes:email>jane.doe@example.com</itunes:email>
</channel></rss>
output:
format: rss
iTunes owner 1:
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>
@ -243,38 +207,15 @@ iTunes owner 4:
</channel></rss>
output:
format: rss
Google Play author 1:
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:author>Jane Doe</play:author>
<play:email>jane.doe@example.com</play:email>
</channel></rss>
output:
format: rss
people:
- name: 'Jane Doe'
- name: 'jane.doe@example.com'
mail: 'jane.doe@example.com'
role: author
Google Play author 2:
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:author>Jane Doe</play:author>
<play:email>bogus@example].com</play:email>
</channel></rss>
output:
format: rss
people:
- name: 'Jane Doe'
role: author
role: webmaster
Google Play author 3:
Google Play author:
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:author/>
<play:author>Jane Doe</play:author>
<play:email>jane.doe@example.com</play:email>
<play:author>jane.doe@example.com (Jane Doe)</play:author>
</channel></rss>
output:
format: rss
@ -283,22 +224,10 @@ Google Play author 3:
mail: 'jane.doe@example.com'
role: author
Google Play author 4:
Google Play owner:
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:author/>
<play:email>jane.doe@example.com</play:email>
</channel></rss>
output:
format: rss
Google Play owner 1:
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:owner>
<play:author>Jane Doe</play:author>
<play:email>jane.doe@example.com</play:email>
</play:owner>
<play:email>jane.doe@example.com (Jane Doe)</play:email>
</channel></rss>
output:
format: rss
@ -306,44 +235,3 @@ Google Play owner 1:
- name: 'Jane Doe'
mail: 'jane.doe@example.com'
role: webmaster
Google Play owner 2:
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:owner>
<play:author>Jane Doe</play:author>
<play:email>bogus@example].com</play:email>
</play:owner>
</channel></rss>
output:
format: rss
people:
- name: 'Jane Doe'
role: webmaster
Google Play owner 3:
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:owner>
<play:author/>
<play:author>Jane Doe</play:author>
<play:email>jane.doe@example.com</play:email>
</play:owner>
</channel></rss>
output:
format: rss
people:
- name: 'Jane Doe'
mail: 'jane.doe@example.com'
role: webmaster
Google Play owner 4:
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:owner>
<play:author/>
<play:email>jane.doe@example.com</play:email>
</play:owner>
</channel></rss>
output:
format: rss

Loading…
Cancel
Save