def serialize(podcast: Podcast, pretty: bool = False) -> str: fg = FeedGenerator() fg.load_extension("podcast") # fg.podcast.itunes_author(podcast.author.name) # fg.podcast.itunes_category("Technology", "Podcasting") # fg.podcast.itunes_explicit("no") # fg.podcast.itunes_complete("no") # fg.podcast.itunes_new_feed_url("http://example.com/new-feed.rss") # fg.podcast.itunes_owner("John Doe", "*****@*****.**") # fg.podcast.itunes_summary("") fg.title(podcast.title) fg.description(podcast.description) fg.author(podcast.author.to_dict()) fg.link(href=podcast.atom_url, rel="self") fg.logo(podcast.logo_url) for episode in podcast.episodes: fe = fg.add_entry() fe.id(podcast.episode_audio_url(episode)) fe.title(episode.title) fe.description(episode.description) fe.enclosure(podcast.episode_audio_url(episode), 0, "audio/mpeg") # fe.author(**podcast.author.to_dict()) # fe.podcast.itunes_author(podcast.author.name) return fg.rss_str(pretty=pretty).decode("utf-8")
def test_episode_media_url(self): podcast = Podcast( title="Test podcast", subtitle="Test podcast subtitle.", description="Test podcast description.", author=self.author, episodes=[self.episode1, self.episode2], base_url="https://example.com", ) self.assertEqual(podcast.episode_audio_url(self.episode1), "https://example.com/1/audio.mp3")
def setUp(self): self.input_path = tempfile.TemporaryDirectory() tmp_dir = self.input_path.name with open(tmp_dir + "/episode1.mp3", "wb") as f: f.write(b"episode_1_mp3_content") with open(tmp_dir + "/episode2.mp3", "wb") as f: f.write(b"episode_2_mp3_content") self.author = Author(name="John Doe", email="*****@*****.**") self.episode1 = Episode( id=1, title="Episode 1", description="Episode 1: test.", audio_file=tmp_dir + "/episode1.mp3", ) self.episode2 = Episode( id=2, title="Episode 2", description="Episode 2: second test.", audio_file=tmp_dir + "/episode2.mp3", ) self.podcast = Podcast( title="Test podcast", subtitle="Test podcast subtitle.", description="Test podcast description.", author=self.author, episodes=[self.episode1, self.episode2], base_url="https://example.com", )
def test_init_podcast(self): podcast = Podcast( title="Test podcast", subtitle="Test podcast subtitle.", description="Test podcast description.", author=self.author, episodes=[self.episode1, self.episode2], base_url="https://example.com", ) self.assertEqual(podcast.title, "Test podcast") self.assertEqual(podcast.subtitle, "Test podcast subtitle.") self.assertEqual(podcast.description, "Test podcast description.") self.assertEqual(podcast.author, self.author) self.assertEqual(podcast.episodes, [self.episode1, self.episode2]) self.assertEqual(podcast.base_url, "https://example.com") self.assertEqual(podcast.atom_url, "https://example.com/podcast.atom") self.assertEqual(podcast.rss_url, "https://example.com/podcast.rss") self.assertEqual(podcast.logo_url, "https://example.com/podcast.jpg")
def __attrs_post_init__(self): podcast_config = yaml.load(self.yaml_str, Loader=yaml.Loader) pc = podcast_config["podcast"] author = Author(name=pc["author"]["name"], email=pc["author"]["email"]) episodes = [] id_count = 1 for episode in pc["episodes"]: episodes.append(Episode(id=id_count, **episode)) id_count += 1 self.podcast = Podcast( title=pc["title"], subtitle=pc["subtitle"], description=pc["description"], author=author, episodes=episodes, base_url=pc["base_url"], )
def setUp(self): self.author = Author(name="John Doe", email="*****@*****.**") self.episode1 = Episode( id=1, title="Episode 1", description="Episode 1: test.", audio_file="episode1.mp3", ) self.episode2 = Episode( id=2, title="Episode 2", description="Episode 2: second test.", audio_file="episode2.mp3", ) self.podcast = Podcast( title="Test podcast", subtitle="Test podcast subtitle.", description="Test podcast description.", author=self.author, episodes=[self.episode1, self.episode2], base_url="https://example.com", )