12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- import os
- import time
- from pod2gen import Podcast, Episode, Media, Person
- from mutagen import mp3
- from datetime import timedelta, datetime as dt
- from dateutil.tz import UTC
- from stat import S_ISREG, ST_CTIME, ST_MODE
- def get_mp3_metadata(file_path):
- track_seconds = round(mp3.MP3(file_path).info.length)
- time_split = time.strftime('%H:%M:%S', time.gmtime(track_seconds)).split(':')
- try:
- description = mp3.MP3(file_path).tags['COMM::eng'].text[0]
- except KeyError:
- try:
- description = mp3.MP3(file_path).tags['TXXX:COMM::eng'].text[0]
- except KeyError:
- description = filename.replace("_", " ")
- return timedelta(hours=int(time_split[0]), minutes=int(time_split[1]), seconds=int(time_split[2])), description
- owner = Person("Example", "email@example.com")
- # Create the Podcast
- p = Podcast(
- name="Rob Beckett and Josh Widdicombe's Parenting Hell",
- description="Rob Beckett and Josh Widdicombe's Parenting Hell",
- website="https://kithub.k-world.me.uk/Karl/RandJPod",
- explicit=False,
- )
- p.image = "https://kithub.k-world.me.uk/Karl/RandJPod/raw/main/cover.jpeg"
- p.owner = owner
- p.locked = True
- p.withhold_from_itunes = True
- file_list = os.listdir("mp3")
- # file_list.pop(0)
- for file in (file_list):
- filename = file[:-4]
- ep_details = filename.split("_")
- file_size = os.stat(f"./mp3/{filename}.mp3").st_size
- file_length, description = get_mp3_metadata(f"./mp3/{filename}.mp3")
- p.add_episode(Episode(
- title=filename.replace("_", " "),
- media=Media(f"https://kithub.k-world.me.uk/Karl/RandJPod/raw/main/mp3/{filename}.mp3", size=file_size),
- summary=description,
- season=int(ep_details[0][1:]),
- episode_number=int(ep_details[1][2:]),
- publication_date = dt.fromtimestamp(os.stat(f"./mp3/{filename}.mp3").st_ctime, tz=UTC)
- ))
- # Generate the RSS feed
- p.rss_file('feed.xml', minimize=True)
|