Skip to content

Commit

Permalink
add podcast seasons to the top level feed object (#57)
Browse files Browse the repository at this point in the history
* add podcast seasons to the top level feed object

* appease the linter

* type woes
  • Loading branch information
RyanHirsch authored Oct 8, 2024
1 parent 286fca3 commit 01070ef
Show file tree
Hide file tree
Showing 6 changed files with 2,709 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"rimraf": "^3.0.2",
"ts-node-dev": "^1.1.6",
"tsconfig-paths": "^3.9.0",
"typescript": "^5.1.6"
"typescript": "^5.6.2"
},
"dependencies": {
"dotenv": "^10.0.0",
Expand Down
2,648 changes: 2,648 additions & 0 deletions src/parser/__test__/fixtures/real-world/themnshow.xml

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions src/parser/__test__/seasons.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { parseFeed } from "..";

import * as helpers from "./helpers";

describe("seasons handling", () => {
it("parses sample publisher feed", async () => {
const xml = await helpers.loadFixture(`real-world/themnshow.xml`);
const result = parseFeed(xml);

expect(result).toHaveProperty("podcastSeasons");
});

it("produces a sorted keyed seaons object", async () => {
const xml = await helpers.loadFixture(`real-world/themnshow.xml`);
const result = parseFeed(xml);

expect(result).toHaveProperty("podcastSeasons", {
1: {
name: "Breakfasts with Dr. Tim",
number: 1,
},
2: {
name: "Supper with Dr. Tim",
number: 2,
},
});
});
});
2 changes: 2 additions & 0 deletions src/parser/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ export interface BasicFeed {
}

export interface FeedObject extends BasicFeed {
podcastSeasons?: Record<number, Phase2SeasonNumber>;

// #region Phase 1
podcastOwner?: string;
/**
Expand Down
27 changes: 26 additions & 1 deletion src/parser/unified.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,40 @@ import mergeDeepRight from "ramda/src/mergeDeepRight";
import { logger } from "../logger";

import { ensureArray } from "./shared";
import type { Episode, FeedObject, FeedType, PhaseUpdate, XmlNode } from "./types";
import type { BasicFeed, Episode, FeedObject, FeedType, PhaseUpdate, XmlNode } from "./types";
import { updateFeed, updateItem } from "./phase";
import { handleItem, isValidItem } from "./item";
import { handleFeed } from "./feed";
import type { Phase4Value } from "./phase/phase-4";
import { Phase2SeasonNumber } from "./phase/phase-2";

export type ParserOptions = {
allowMissingGuid?: boolean;
};

function handlePodcastSeasons(feedObj: BasicFeed) {
const tempSeasons = [] as Array<Phase2SeasonNumber>;
// eslint-disable-next-line no-restricted-syntax
for (const { podcastSeason } of feedObj.items) {
if (podcastSeason) {
const existingValue = tempSeasons.find((x) => x.number === podcastSeason.number);
if (existingValue && !existingValue.name && podcastSeason.name) {
existingValue.name = podcastSeason.name;
} else if (!existingValue) {
tempSeasons.push(podcastSeason);
}
}
}
if (tempSeasons.length > 0) {
return {
podcastSeasons: tempSeasons
.sort((a, b) => a.number - b.number)
.reduce((agg, curr) => ({ ...agg, [curr.number]: curr }), {}),
};
}
return undefined;
}

export function unifiedParser(theFeed: XmlNode, type: FeedType, options?: ParserOptions) {
const epochDate = new Date(0);
if (typeof theFeed.rss.channel === "undefined") {
Expand Down Expand Up @@ -104,5 +128,6 @@ export function unifiedParser(theFeed: XmlNode, type: FeedType, options?: Parser
return {
podcastBlocked: "no",
...feedObj,
...handlePodcastSeasons(feedObj),
} as FeedObject;
}
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5226,10 +5226,10 @@ typedarray-to-buffer@^3.1.5:
dependencies:
is-typedarray "^1.0.0"

typescript@^5.1.6:
version "5.1.6"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.1.6.tgz#02f8ac202b6dad2c0dd5e0913745b47a37998274"
integrity sha512-zaWCozRZ6DLEWAWFrVDz1H6FVXzUSfTy5FUMWsQlU8Ym5JP9eO4xkTIROFCQvhQf61z6O/G6ugw3SgAnvvm+HA==
typescript@^5.6.2:
version "5.6.2"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.6.2.tgz#d1de67b6bef77c41823f822df8f0b3bcff60a5a0"
integrity sha512-NW8ByodCSNCwZeghjN3o+JX5OFH0Ojg6sadjEKY4huZ52TqbJTJnDo5+Tw98lSy63NZvi4n+ez5m2u5d4PkZyw==

uglify-js@^3.1.4:
version "3.13.1"
Expand Down

0 comments on commit 01070ef

Please sign in to comment.