Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions src/parser/__test__/fixtures/podcast-image-example.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:podcast="https://github.com/Podcastindex-org/podcast-namespace/blob/main/docs/1.0.md"
xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
<channel>
<title>Podcast with Phase 8 Image Tag</title>
<description>This is an example feed demonstrating the new podcast:image tag from Phase 8.</description>
<link>http://example.com/podcast</link>
<docs>http://blogs.law.harvard.edu/tech/rss</docs>
<language>en-US</language>
<generator>Phase 8 Example</generator>
<pubDate>Fri, 09 Oct 2020 04:30:38 GMT</pubDate>
<lastBuildDate>Fri, 09 Oct 2020 04:30:38 GMT</lastBuildDate>
<managingEditor>john@example.com (John Doe)</managingEditor>
<webMaster>support@example.com (Tech Support)</webMaster>

<!-- Phase 8: New podcast:image tag with all attributes -->
<podcast:image
href="https://example.com/images/podcast-cover.jpg"
alt="Podcast cover art showing an antenna emanating signal waves"
aspect-ratio="1/1"
type="image/jpeg"
width="1400"
height="1400"
purpose="artwork"/>

<!-- Multiple images for different use cases -->
<podcast:image
href="https://example.com/images/podcast-banner.jpg"
alt="Podcast banner for social sharing"
aspect-ratio="16/9"
type="image/jpeg"
width="1920"
height="1080"
purpose="artwork social"/>

<podcast:image
href="https://example.com/images/publisher-logo.png"
alt="Publisher logo"
aspect-ratio="1/1"
type="image/png"
width="512"
height="512"
purpose="publisher"/>

<itunes:author>John Doe</itunes:author>
<itunes:explicit>no</itunes:explicit>
<itunes:type>episodic</itunes:type>
<itunes:category text="News"/>
<itunes:category text="Technology"/>

<itunes:image>https://example.com/images/pci_avatar-massive.jpg</itunes:image>

<item>
<title>Episode 1 - Introduction to Phase 8</title>
<description>&lt;p&gt;This episode introduces the new podcast:image tag from Phase 8!&lt;/p&gt;</description>
<link>https://example.com/podcast/ep0001</link>
<guid isPermaLink="true">https://example.com/ep0001</guid>
<pubDate>Fri, 09 Oct 2020 04:30:38 GMT</pubDate>
<author>John Doe (john@example.com)</author>
<itunes:image>https://example.com/ep0001/artMd.jpg</itunes:image>
<itunes:explicit>no</itunes:explicit>
<enclosure url="https://mp3s.nashownotes.com/PC20-17-2020-12-25-Final.mp3" length="76606111" type="audio/mpeg"/>

<!-- Phase 8: podcast:image at episode level with multiple formats -->
<podcast:image
href="https://example.com/ep0001/episode-cover.jpg"
alt="Episode 1 cover art"
aspect-ratio="1/1"
type="image/jpeg"
width="800"
height="800"
purpose="artwork"/>

<podcast:image
href="https://example.com/ep0001/episode-banner.mp4"
alt="Episode 1 animated banner"
aspect-ratio="16/9"
type="video/mp4"
width="1920"
height="1080"
purpose="artwork social canvas"/>
</item>
</channel>
</rss>
145 changes: 145 additions & 0 deletions src/parser/phase/__test__/phase-8.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/* eslint-disable sonarjs/no-duplicate-string */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
import * as helpers from "../../__test__/helpers";

const phase = 8;

describe("phase 8", () => {
let feed;
beforeAll(async () => {
feed = await helpers.loadSimple();
});

describe("podcast:image", () => {
const supportedName = "image";

it("correctly identifies a basic feed", () => {
const result = helpers.parseValidFeed(feed);

expect(result).not.toHaveProperty("podcastImage");
expect(helpers.getPhaseSupport(result, phase)).not.toContain(supportedName);
});

it("ignores missing href", () => {
const xml = helpers.spliceFeed(
feed,
// missing href, not valid
`<podcast:image type="image/jpeg" width="1400" height="1400"/>`
);
const result = helpers.parseValidFeed(xml);

expect(result).not.toHaveProperty("podcastImage");
expect(helpers.getPhaseSupport(result, phase)).not.toContain(supportedName);
});

it("extracts a basic image with only href", () => {
const xml = helpers.spliceFeed(
feed,
`<podcast:image href="https://example.com/image.jpg"/>`
);
const result = helpers.parseValidFeed(xml);

expect(result).toHaveProperty("podcastImage");
expect(result.podcastImage).toHaveProperty("href", "https://example.com/image.jpg");
expect(result.podcastImage).not.toHaveProperty("type");
expect(result.podcastImage).not.toHaveProperty("width");
expect(result.podcastImage).not.toHaveProperty("height");
expect(helpers.getPhaseSupport(result, phase)).toContain(supportedName);
});

it("extracts an image with all attributes", () => {
const xml = helpers.spliceFeed(
feed,
`<podcast:image href="https://example.com/image.jpg" alt="Test image" aspect-ratio="1/1" type="image/jpeg" width="1400" height="1400" purpose="artwork"/>`
);
const result = helpers.parseValidFeed(xml);

expect(result).toHaveProperty("podcastImage");
expect(result.podcastImage).toHaveProperty("href", "https://example.com/image.jpg");
expect(result.podcastImage).toHaveProperty("alt", "Test image");
expect(result.podcastImage).toHaveProperty("aspectRatio", "1/1");
expect(result.podcastImage).toHaveProperty("type", "image/jpeg");
expect(result.podcastImage).toHaveProperty("width", 1400);
expect(result.podcastImage).toHaveProperty("height", 1400);
expect(result.podcastImage).toHaveProperty("purpose", "artwork");
expect(helpers.getPhaseSupport(result, phase)).toContain(supportedName);
});

it("extracts an image with partial attributes", () => {
const xml = helpers.spliceFeed(
feed,
`<podcast:image href="https://example.com/image.png" type="image/png" width="800"/>`
);
const result = helpers.parseValidFeed(xml);

expect(result).toHaveProperty("podcastImage");
expect(result.podcastImage).toHaveProperty("href", "https://example.com/image.png");
expect(result.podcastImage).toHaveProperty("type", "image/png");
expect(result.podcastImage).toHaveProperty("width", 800);
expect(result.podcastImage).not.toHaveProperty("height");
expect(helpers.getPhaseSupport(result, phase)).toContain(supportedName);
});

it("handles numeric width and height as integers", () => {
const xml = helpers.spliceFeed(
feed,
`<podcast:image href="https://example.com/image.jpg" width="1920" height="1080"/>`
);
const result = helpers.parseValidFeed(xml);

expect(result).toHaveProperty("podcastImage");
expect(result.podcastImage).toHaveProperty("width", 1920);
expect(result.podcastImage).toHaveProperty("height", 1080);
expect(typeof result.podcastImage?.width).toBe("number");
expect(typeof result.podcastImage?.height).toBe("number");
});

it("extracts aspect-ratio attribute", () => {
const xml = helpers.spliceFeed(
feed,
`<podcast:image href="https://example.com/image.jpg" aspect-ratio="16/9"/>`
);
const result = helpers.parseValidFeed(xml);

expect(result).toHaveProperty("podcastImage");
expect(result.podcastImage).toHaveProperty("aspectRatio", "16/9");
});

it("extracts purpose attribute", () => {
const xml = helpers.spliceFeed(
feed,
`<podcast:image href="https://example.com/image.jpg" purpose="artwork social"/>`
);
const result = helpers.parseValidFeed(xml);

expect(result).toHaveProperty("podcastImage");
expect(result.podcastImage).toHaveProperty("purpose", "artwork social");
});

it("extracts alt attribute for accessibility", () => {
const xml = helpers.spliceFeed(
feed,
`<podcast:image href="https://example.com/image.jpg" alt="An antenna emanating signal waves"/>`
);
const result = helpers.parseValidFeed(xml);

expect(result).toHaveProperty("podcastImage");
expect(result.podcastImage).toHaveProperty("alt", "An antenna emanating signal waves");
});

it("handles video type with aspect-ratio", () => {
const xml = helpers.spliceFeed(
feed,
`<podcast:image href="https://example.com/video.mp4" type="video/mp4" aspect-ratio="9/16" width="1200"/>`
);
const result = helpers.parseValidFeed(xml);

expect(result).toHaveProperty("podcastImage");
expect(result.podcastImage).toHaveProperty("href", "https://example.com/video.mp4");
expect(result.podcastImage).toHaveProperty("type", "video/mp4");
expect(result.podcastImage).toHaveProperty("aspectRatio", "9/16");
expect(result.podcastImage).toHaveProperty("width", 1200);
});
});
});
6 changes: 6 additions & 0 deletions src/parser/phase/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import * as phase4 from "./phase-4";
import * as phase5 from "./phase-5";
import * as phase6 from "./phase-6";
import * as phase7 from "./phase-7";
import * as phase8 from "./phase-8";
import * as pending from "./phase-pending";
import { XmlNodeSource } from "./types";

Expand Down Expand Up @@ -92,6 +93,9 @@ const feeds: FeedUpdate[] = [
phase7.podcastChat,
phase7.podcastPublisher,

// Phase 8
phase8.podcastImage,

pending.id,
pending.social,
pending.podcastRecommendations,
Expand Down Expand Up @@ -119,6 +123,8 @@ const items: ItemUpdate[] = [

phase7.podcastChat,

phase8.podcastImage,

pending.podcastRecommendations,
pending.podcastGateway,
];
Expand Down
41 changes: 41 additions & 0 deletions src/parser/phase/phase-8.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import {
ensureArray,
extractOptionalIntegerAttribute,
extractOptionalStringAttribute,
getAttribute,
getKnownAttribute,
} from "../shared";
import type { XmlNode } from "../types";

export type Phase8PodcastImage = {
href: string;
alt?: string;
aspectRatio?: string;
width?: number;
height?: number;
type?: string;
purpose?: string;
};

export const podcastImage = {
phase: 8,
name: "image",
tag: "podcast:image",
nodeTransform: (node: XmlNode | XmlNode[]): XmlNode =>
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
ensureArray(node).find((n) => getAttribute(n, "href")),
supportCheck: (node: XmlNode): boolean => Boolean(getAttribute(node, "href")),
fn(node: XmlNode): { podcastImage: Phase8PodcastImage } {
return {
podcastImage: {
href: getKnownAttribute(node, "href"),
...extractOptionalStringAttribute(node, "alt"),
...extractOptionalStringAttribute(node, "aspect-ratio", "aspectRatio"),
...extractOptionalIntegerAttribute(node, "width"),
...extractOptionalIntegerAttribute(node, "height"),
...extractOptionalStringAttribute(node, "type"),
...extractOptionalStringAttribute(node, "purpose"),
},
};
},
};
5 changes: 5 additions & 0 deletions src/parser/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import type {
import type { Phase5Blocked, Phase5BlockedPlatforms, Phase5SocialInteract } from "./phase/phase-5";
import type { Phase6RemoteItem, Phase6TxtEntry } from "./phase/phase-6";
import type { Phase7Chat, Phase7Publisher } from "./phase/phase-7";
import type { Phase8PodcastImage } from "./phase/phase-8";
import {
PhasePendingPodcastId,
PhasePendingSocial,
Expand Down Expand Up @@ -197,6 +198,8 @@ export interface FeedObject extends BasicFeed {
/** PENDING AND LIKELY TO CHANGE This tag tells the an application what the content contained within the feed IS, as opposed to what the content is ABOUT in the case of a category. */
medium?: Phase4Medium;
podcastImages?: Phase4PodcastImage[];
/** Phase 8: specifies a single image for a podcast at the channel level */
podcastImage?: Phase8PodcastImage;
podcastRecommendations?: PhasePendingPodcastRecommendation[];
// #endregion
}
Expand Down Expand Up @@ -264,6 +267,8 @@ export interface Episode {

// #region Pending Phase
podcastImages?: Phase4PodcastImage[];
/** Phase 8: specifies a single image for a podcast at the episode level */
podcastImage?: Phase8PodcastImage;
podcastRecommendations?: PhasePendingPodcastRecommendation[];
podcastGateway?: PhasePendingGateway;
// #endregion
Expand Down