Skip to content

Commit

Permalink
add publisher feed support (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanHirsch authored Sep 12, 2024
1 parent 93cf4fc commit 488b36f
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/parser/phase/__test__/phase-7.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,23 @@ describe("phase 7", () => {
expect(helpers.getPhaseSupport(result, phase)).toContain(supportedName);
});
});
describe("publisher", () => {
const supportedName = "publisher";
it("extracts a valid publisher from the feed", () => {
const chatBlock = `<podcast:publisher>
<podcast:remoteItem medium="publisher" feedGuid="003af0a0-6a45-55bf-b765-68e3d349551a" feedUrl="https://agilesetmedia.com/assets/static/feeds/publisher.xml"/>
</podcast:publisher>`;
const result = helpers.parseValidFeed(spliceFeed(feed, chatBlock));

expect(result.podcastPublisher).toHaveProperty(
"feedGuid",
"003af0a0-6a45-55bf-b765-68e3d349551a"
);
expect(result.podcastPublisher).toHaveProperty(
"feedUrl",
"https://agilesetmedia.com/assets/static/feeds/publisher.xml"
);
expect(helpers.getPhaseSupport(result, phase)).toContain(supportedName);
});
});
});
1 change: 1 addition & 0 deletions src/parser/phase/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ const feeds: FeedUpdate[] = [
phase6.podroll,

phase7.podcastChat,
phase7.podcastPublisher,

pending.id,
pending.social,
Expand Down
2 changes: 2 additions & 0 deletions src/parser/phase/phase-4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ export enum Phase4Medium {
Newsletter = "newsletter",
/** a feed of informally written articles. Similar to newsletter but more informal as in a traditional blog platform style */
Blog = "blog",
/** a feed of podcasts from the same publisher */
Publisher = "publisher",
}
export const medium: FeedUpdate = {
tag: "podcast:medium",
Expand Down
34 changes: 34 additions & 0 deletions src/parser/phase/phase-7.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import invariant from "tiny-invariant";

import { logger } from "../../logger";
import {
ensureArray,
Expand Down Expand Up @@ -72,3 +74,35 @@ export const podcastChat = {
};

addSubTag<Phase4PodcastLiveItem>("liveItem", podcastChat);

function getPublisherRemoteItem(node: XmlNode): XmlNode | undefined {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
const remoteItem = node["podcast:remoteItem"];
return ensureArray(remoteItem).find(
(n) => getAttribute(n, "medium") === "publisher" && getAttribute(n, "feedGuid")
);
}
export type Phase7Publisher = {
feedGuid: string;
feedUrl?: string;
};
export const podcastPublisher = {
phase: 7,
name: "publisher",
tag: "podcast:publisher",
supportCheck: (node: XmlNode): boolean => {
if (Array.isArray(node)) return false;
return Boolean(getPublisherRemoteItem(node));
},
fn(node: XmlNode): { podcastPublisher: Phase7Publisher } {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const publisherItem = getPublisherRemoteItem(node);
invariant(publisherItem);
return {
podcastPublisher: {
feedGuid: getKnownAttribute(publisherItem, "feedGuid"),
...extractOptionalStringAttribute(publisherItem, "feedUrl"),
},
};
},
};
3 changes: 2 additions & 1 deletion src/parser/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import type {
} from "./phase/phase-4";
import type { Phase5Blocked, Phase5BlockedPlatforms, Phase5SocialInteract } from "./phase/phase-5";
import type { Phase6RemoteItem, Phase6TxtEntry } from "./phase/phase-6";
import type { Phase7Chat } from "./phase/phase-7";
import type { Phase7Chat, Phase7Publisher } from "./phase/phase-7";
import {
PhasePendingPodcastId,
PhasePendingSocial,
Expand Down Expand Up @@ -183,6 +183,7 @@ export interface FeedObject extends BasicFeed {
// #endregion
//
chat?: Phase7Chat;
podcastPublisher?: Phase7Publisher;

// #region Pending Phase
/** PENDING AND LIKELY TO CHANGE indicates a listing on multiple platforms, directories, hosts, apps and services. */
Expand Down

0 comments on commit 488b36f

Please sign in to comment.