Skip to content

Commit

Permalink
add last pub date (#56)
Browse files Browse the repository at this point in the history
* add last pub date

* bad file
  • Loading branch information
RyanHirsch authored Oct 3, 2024
1 parent 9db77a9 commit 2ee98d2
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 0 deletions.
79 changes: 79 additions & 0 deletions src/parser/__test__/feed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,85 @@ describe("feed handling", () => {
});
});

describe("lastPubDate", () => {
it("extracts the channel pubDate and sets it to lastPubDate", () => {
const xml = helpers.spliceFeed(
feed,
`
<pubDate>Tue, 18 May 2021 13:49:20 -0000</pubDate>
`
);

const result = parseFeed(xml);
expect(result).toHaveProperty("lastPubDate", new Date("Tue, 18 May 2021 13:49:20 -0000"));
});

it("extracts the item pub date and sets it to lastPubDate", () => {
const xml = helpers.spliceFeed(
feed,
`
<item>
<title>Test</title>
<guid isPermaLink="true">https://example.com/ep0003</guid>
<enclosure url="https://mp3s.nashownotes.com/PC20-17-2020-12-25-Final.mp3" length="76606111" type="audio/mpeg"/>
<pubDate>Tue, 19 May 2021 13:49:20 -0000</pubDate>
</item>
`
);

const result = parseFeed(xml);
expect(result).toHaveProperty("lastPubDate", new Date("Tue, 19 May 2021 13:49:20 -0000"));
});

it("uses the lastest pubDate as the lastPub date when channel and items have a pubDate", () => {
const xml = helpers.spliceFeed(
feed,
`
<pubDate>Tue, 18 May 2021 13:49:20 -0000</pubDate>
<item>
<title>Test</title>
<guid isPermaLink="true">https://example.com/ep0003</guid>
<enclosure url="https://mp3s.nashownotes.com/PC20-17-2020-12-25-Final.mp3" length="76606111" type="audio/mpeg"/>
<pubDate>Wed, 19 May 2021 13:49:20 -0000</pubDate>
</item>
`
);

const result = parseFeed(xml);
expect(result).toHaveProperty("lastPubDate", new Date("Tue, 19 May 2021 13:49:20 -0000"));
});

it("uses the lastest pubDate as the lastPub date when channel and multiple items have a pubDate", () => {
const xml = helpers.spliceFeed(
feed,
`
<pubDate>Tue, 18 May 2021 13:49:20 -0000</pubDate>
<item>
<title>Test</title>
<guid isPermaLink="true">https://example.com/ep0003</guid>
<enclosure url="https://mp3s.nashownotes.com/PC20-17-2020-12-25-Final.mp3" length="76606111" type="audio/mpeg"/>
<pubDate>Tue, 11 May 2022 13:49:20 -0000</pubDate>
</item>
<item>
<title>Test2</title>
<guid isPermaLink="true">https://example.com/ep0004</guid>
<enclosure url="https://mp3s.nashownotes.com/PC20-17-2020-12-26-Final.mp3" length="76606111" type="audio/mpeg"/>
<pubDate>Tue, 25 May 2022 13:49:20 -0000</pubDate>
</item>
<item>
<title>Test</title>
<guid isPermaLink="true">https://example.com/ep0003</guid>
<enclosure url="https://mp3s.nashownotes.com/PC20-17-2020-12-25-Final.mp3" length="76606111" type="audio/mpeg"/>
<pubDate>Mon, 24 13:49:20 -0000</pubDate>
</item>
`
);

const result = parseFeed(xml);
expect(result).toHaveProperty("lastPubDate", new Date("Tue, 25 May 2022 13:49:20 -0000"));
});
});

describe("lastBuildDate", () => {
it("extracts node value", () => {
const xml = helpers.spliceFeed(
Expand Down
20 changes: 20 additions & 0 deletions src/parser/__test__/fixtures/publisher.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<rss xmlns:podcast="https://github.com/Podcastindex-org/podcast-namespace/blob/main/docs/1.0.md" version="2.0">
<channel>
<title>AgileSet Media</title>
<link>https://agilesetmedia.com</link>
<description>AgileSet Media is an unincorporated, unregistered, and unpapered entity of AgileSet LLC for producing and publishing stuff by Mike Neumann. It is based in Texas, USA.</description>
<image>
<url>https://agilesetmedia.com/assets/static/AgileSet-logo-square-sm-144.png</url>
<title>AgileSet Media</title>
<link>https://agilesetmedia.com</link>
<width>144</width>
<height>144</height>
</image>
<podcast:person href="https://mikeneumann.net" group="Creative Direction" role="Director" img="https://itsamood.org/assets/static/MikeNeumann_202310.jpg">Mike Neumann</podcast:person>
<podcast:guid>003af0a0-6a45-55bf-b765-68e3d349551a</podcast:guid>
<podcast:medium>publisher</podcast:medium>
<podcast:remoteItem medium="podcast" feedGuid="469b403f-db2d-574c-9db9-96dbb3f6561c" feedUrl="https://itsamood.org/itsamoodrss.xml"/>
<podcast:remoteItem medium="podcast" feedGuid="72816866-317e-5e48-8895-8193d58e5b57" feedUrl="https://mikesmixtape.com/mikesmixtaperss.xml"/>
<podcast:remoteItem medium="podcast" feedGuid="7a2d292c-8656-5fcf-88d2-31b10e54d7c7" feedUrl="https://mikeneumann.show/themnshowrss.xml"/>
</channel>
</rss>
15 changes: 15 additions & 0 deletions src/parser/__test__/publisher.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { parseFeed } from "..";

import * as helpers from "./helpers";

describe("publisher feed", () => {
it("parses sample publisher feed", async () => {
const xml = await helpers.loadFixture(`publisher.xml`);
const result = parseFeed(xml);

expect(result).toHaveProperty("title", "AgileSet Media");
expect(result).toHaveProperty("medium", "publisher");
expect(result).toHaveProperty("podcastRemoteItems");
expect(result?.podcastRemoteItems).toHaveLength(3);
});
});
2 changes: 2 additions & 0 deletions src/parser/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ export interface BasicFeed {
pubDate?: Date;
/** The last time the content of the channel changed. */
lastBuildDate?: Date;
/** Most recent pubDate found via channel or item pubDates */
lastPubDate?: Date;

itunesType?: ItunesFeedType;
/**
Expand Down
7 changes: 7 additions & 0 deletions src/parser/unified.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ export function unifiedParser(theFeed: XmlNode, type: FeedType, options?: Parser
feedObj.pubDate = feedObj.newestItemPubDate;
}

if (feedObj.newestItemPubDate && feedObj.pubDate) {
feedObj.lastPubDate =
feedObj.newestItemPubDate > feedObj.pubDate ? feedObj.newestItemPubDate : feedObj.pubDate;
} else if (feedObj.pubDate) {
feedObj.lastPubDate = feedObj.pubDate;
}

if (Object.keys(phaseSupport).length > 0) {
feedObj.pc20support = Object.entries(phaseSupport).reduce(
(phases, [phase, kv]) => ({ ...phases, [phase]: Object.keys(kv) }),
Expand Down

0 comments on commit 2ee98d2

Please sign in to comment.