Skip to content

Commit

Permalink
refactor(feed): optimize podcast feed generation and update metadata
Browse files Browse the repository at this point in the history
- Modify episode item building to fetch episode data on-demand
- Update podcast feed metadata (explicit flag and block parameter)
- Adjust documentation build command in Makefile
- Add .idea/caches to gitignore
  • Loading branch information
bendikrb committed Nov 6, 2024
1 parent 63e116e commit 816a3c5
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

# Generated files
.idea/**/contentModel.xml
.idea/caches

# Sensitive or high-churn files
.idea/**/dataSources/
Expand Down
1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion .idea/nrk-psapi.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ format-check:

.PHONY: docs
docs:
$(run) sphinx-build docs docs/_build
$(run) cd docs; make html

.PHONY: setup
setup:
Expand Down
12 changes: 7 additions & 5 deletions nrk_psapi/rss/feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ async def build_episode_chapters(episode: Episode) -> list[EpisodeChapter]:
for index_point in episode.index_points
]

async def build_episode_item(self, episode: Episode, series_data: PodcastSeries) -> Item | None:
async def build_episode_item(self, episode_id: str, series_data: PodcastSeries) -> Item | None:
"""Build a :class:`rfeed.rfeed.Item` for an episode."""

_LOGGER.debug("Building episode item: %s", episode.episode_id)
_LOGGER.debug("Building episode item: %s", episode_id)
episode = await self.api.get_episode(series_data.id, episode_id)
manifest = await self.api.get_playback_manifest(episode.episode_id, podcast=True)
episode_file = manifest.playable.assets[0] or None
if episode_file is None: # pragma: no cover
Expand All @@ -65,7 +66,7 @@ async def build_episode_item(self, episode: Episode, series_data: PodcastSeries)
_LOGGER.debug("File stat: %s", file_stat)

extensions = []
if episode.index_points: # pragma: no cover
if episode.index_points:
chapters_url = f"{self.base_url}/{series_data.id}/{episode.episode_id}/chapters.json"
extensions.append(PodcastChapters(chapters_url, "application/json+chapters"))

Expand Down Expand Up @@ -142,7 +143,8 @@ async def build_podcast_rss(self, podcast_id: str, limit: int | None = None) ->
author="NRK",
# subtitle=(description[:255] + '..') if len(description) > 255 else description,
summary=podcast.series.titles.subtitle,
explicit="clean",
block=True,
explicit=False,
owner=iTunesOwner(
name="NRK",
email="[email protected]",
Expand All @@ -153,7 +155,7 @@ async def build_podcast_rss(self, podcast_id: str, limit: int | None = None) ->
*extensions,
],
items=[
await self.build_episode_item(episode, series_data=podcast.series) for episode in episodes
await self.build_episode_item(episode.episode_id, series_data=podcast.series) for episode in episodes
],
**feed_attrs,
)

0 comments on commit 816a3c5

Please sign in to comment.