Skip to content

Instantly share code, notes, and snippets.

@catharsisjelly
Last active December 14, 2021 18:11
Show Gist options
  • Save catharsisjelly/bb3f4d1036730d0bb14aa437328e985e to your computer and use it in GitHub Desktop.
Save catharsisjelly/bb3f4d1036730d0bb14aa437328e985e to your computer and use it in GitHub Desktop.
A small python script to display the total duration of all podcasts in any giiven
#!/usr/bin/env python
import xml.dom.minidom
import time
import sys
def getEpisodeLength(item):
seconds = 0
durationTag = item.getElementsByTagName('itunes:duration')
hoursMinsSecs = durationTag[0].firstChild.data.split(':')
seconds += int(hoursMinsSecs[-1])
seconds += int(hoursMinsSecs[-2]) * 60 # Minutes
if (len(hoursMinsSecs) == 3):
seconds += int(hoursMinsSecs[-3]) * 3600 # Hours
return seconds
def secondsToTime(inputSeconds):
day = inputSeconds // (24 * 3600)
inputSeconds = inputSeconds % (24 * 3600)
hour = inputSeconds // 3600
inputSeconds %= 3600
minutes = inputSeconds // 60
inputSeconds %= 60
seconds = inputSeconds
print ("Actual time: %dd %dh %dm %ds" % (day, hour, minutes, seconds))
totalSecs = 0
yearTotal = 0
year = None
if (len(sys.argv) > 1):
year = int(sys.argv[1])
doc = xml.dom.minidom.parse('feed.xml')
items = doc.getElementsByTagName('item')
for item in items:
pubDateTag = item.getElementsByTagName('pubDate')
isoDateTime = pubDateTag[0].firstChild.data # Thu, 21 Nov 2019 21:12:08 +0000
tdObject = time.strptime(isoDateTime[:16], '%a, %d %b %Y')
episodeLength = getEpisodeLength(item)
totalSecs += episodeLength
if (year and tdObject[0] == year):
yearTotal += episodeLength
if (year):
print ("Showing totals for %d" % year)
print ("Total time: %d seconds for %d" % (yearTotal, year))
secondsToTime(yearTotal)
print ("Total time: %d seconds" % (totalSecs))
secondsToTime(totalSecs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment