Created
April 11, 2022 23:55
-
-
Save thiagosantos/5d068bc3cdde9eb1773c951241982729 to your computer and use it in GitHub Desktop.
Sum podcast feed duration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Extract duration from episodes suming it, convert it to hours, seconds, max duration episode and min duration. | |
- Install xmltodict | |
python3 -m pip install xmltodict | |
Change feed_url to your own feed url. | |
This Python file could be converted to a script passing args when calling it. | |
""" | |
import urllib | |
import xmltodict | |
import argparse | |
def feed_duration(feed_url: str): | |
file = urllib.request.urlopen(feed_url) | |
data = file.read() | |
file.close() | |
data = xmltodict.parse(data) | |
return [ int(item['itunes:duration']) for item in data['rss']['channel']['item'] ] | |
def main(): | |
feed_url = 'https://anchor.fm/s/fee55e8/podcast/rss' | |
items_duration = feed_duration(feed_url) | |
duration_seconds = sum(items_duration) | |
hours = "{}h{}m{}s".format( str(duration_seconds//3600), str( (duration_seconds%3600)//60) , str( (duration_seconds%3600)%60) ) | |
print ("Episodes : {}\nDuration (seconds): {}\nDuration hours: {}\nMax duration: {}\nMin duration: {}".format( str(len(items_duration)), str(sum(items_duration)), hours, str(max(items_duration)), str(min(items_duration)))) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment