Full example¶
This example is located at pod2gen/__main__.py
in the package, and is run
as part of the testing routines.
1def main():
2 """Create an example podcast and print it or save it to a file."""
3 # There must be exactly one argument, and it is must end with rss
4 if len(sys.argv) != 2 or not (sys.argv[1].endswith("rss")):
5 # Invalid usage, print help message
6 # print_enc is just a custom function which functions like print,
7 # except it deals with byte arrays properly.
8 print_enc("Usage: %s ( <file>.rss | rss )" % "python -m pod2gen")
9 print_enc("")
10 print_enc(
11 " rss -- Generate RSS test output and print it to stdout."
12 )
13 print_enc(
14 " <file>.rss -- Generate RSS test teed and write it to file.rss."
15 )
16 print_enc("")
17 exit()
18
19 # Remember what type of feed the user wants
20 arg = sys.argv[1]
21
22 from pod2gen import (
23 AlternateMedia,
24 Category,
25 Funding,
26 License,
27 Location,
28 Media,
29 Person,
30 Podcast,
31 Soundbite,
32 Trailer,
33 Transcript,
34 htmlencode,
35 )
36
37 # Initialize the feed
38 p = Podcast()
39 p.name = "Testfeed"
40 p.authors.append(Person("Lars Kiesow", "lkiesow@uos.de"))
41 p.website = "http://example.com"
42 p.copyright = "cc-by"
43 p.description = "This is a cool feed!"
44 p.is_serial = True
45 p.language = "de"
46 p.location = Location("Austin, TX", osm="R113314", geo="geo:30.2672,97.7431")
47 p.feed_url = "http://example.com/feeds/myfeed.rss"
48 p.add_funding(Funding("Support the show!", "https://www.example.com/donations"))
49 p.add_funding(Funding("Become a member!", "https://www.example.com/members"))
50 p.category = Category("Leisure", "Aviation")
51 p.explicit = False
52 p.complete = False
53 p.new_feed_url = "http://example.com/new-feed.rss"
54 p.owner = Person("John Doe", "john@example.com")
55 p.locked = False
56 p.xslt = "http://example.com/stylesheet.xsl"
57
58 e1 = p.add_episode()
59 e1.id = "http://lernfunk.de/_MEDIAID_123#1"
60 e1.title = "First Element"
61 e1.season = 1
62 e1.season_name = "Volume 1"
63 e1.episode_number = 1
64 e1.episode_name = "First episode"
65 e1.chapters_json = "https://example.com/episode1/chapters.json"
66 e1.summary = htmlencode(
67 """Lorem ipsum dolor sit amet, consectetur adipiscing elit. Tamen
68 aberramus a proposito, et, ne longius, prorsus, inquam, Piso, si ista
69 mala sunt, placet. Aut etiam, ut vestitum, sic sententiam habeas aliam
70 domesticam, aliam forensem, ut in fronte ostentatio sit, intus veritas
71 occultetur? Cum id fugiunt, re eadem defendunt, quae Peripatetici,
72 verba <3."""
73 )
74 e1.link = "http://example.com"
75 e1.authors = [Person("Lars Kiesow", "lkiesow@uos.de")]
76 e1.publication_date = datetime.datetime(2014, 5, 17, 13, 37, 10, tzinfo=tz.UTC)
77 e1.media = Media(
78 "http://example.com/episodes/loremipsum.mp3",
79 454599964,
80 duration=datetime.timedelta(hours=1, minutes=32, seconds=19),
81 )
82 e1.add_soundbite(Soundbite(1234.5, 42.25, text="Why the Podcast Namespace Matters"))
83 e1.add_soundbite(Soundbite(73.0, 60))
84 transcript1 = Transcript(
85 "https://examples.com/transcript_sample.txt",
86 "text/html",
87 language="es",
88 is_caption=True,
89 )
90 e1.add_transcript(transcript1)
91 transcript2 = Transcript(
92 "https://examples.com/transcript_sample_2.txt", "text/html"
93 )
94 e1.add_transcript(transcript2)
95 e1.location = Location(
96 "Dreamworld (Queensland)", geo="geo:-27.86159,153.3169", osm="W43678282"
97 )
98 persons = [
99 Person(
100 name="Becky Smith",
101 group="visuals",
102 role="Cover Art Designer",
103 href="https://example.com/artist/beckysmith",
104 img="http://example.com/images/alicebrown.jpg",
105 ),
106 Person(
107 email="mslimbeji@gmail.com",
108 group="writing",
109 role="guest writer",
110 href="https://www.wikipedia/slimbeji",
111 img="http://example.com/images/slimbeji.jpg",
112 ),
113 ]
114 e1.persons = persons
115 e1.episode_number = 1
116 p.persons = persons
117
118 trailers = [
119 Trailer(
120 text="Coming April 1st, 2021",
121 url="https://example.org/trailers/teaser",
122 pubdate=datetime.datetime(2021, 8, 15, 8, 15, 12, 0, tz.UTC),
123 length=12345678,
124 type="audio/mp3",
125 season=2,
126 )
127 ]
128 p.trailers = trailers
129
130 license = License(
131 "my-podcast-license-v1", "https://example.org/mypodcastlicense/full.pdf"
132 )
133 e1.license = license
134 p.license = license
135 p.generate_guid()
136
137 am = AlternateMedia(
138 "audio/mp4",
139 43200000,
140 bitrate=128000,
141 height=1080,
142 lang="en-US",
143 title="Standard",
144 rel="Off stage",
145 codecs="mp4a.40.2",
146 default=False,
147 encryption="sri",
148 signature="sha384-ExVqijgYHm15PqQqdXfW95x+Rs6C+d6E/ICxyQOeFevnxNLR/wtJNrNYTjIysUBo",
149 )
150 am.sources = {
151 "https://example.com/file-0.mp3": None,
152 "ipfs://QmdwGqd3d2gFPGeJNLLCshdiPert45fMu84552Y4XHTy4y": None,
153 "https://example.com/file-0.torrent": "application/x-bittorrent",
154 }
155 e1.add_alternate_media(am)
156
157 # Should we just print out, or write to file?
158 if arg == "rss":
159 # Print
160 print_enc(p.rss_str())
161 elif arg.endswith("rss"):
162 # Write to file
163 p.rss_file(arg, minimize=True)