46 lines
1.4 KiB
Python
46 lines
1.4 KiB
Python
import requests
|
|
import xmltodict
|
|
from urllib import request as urlrequest
|
|
|
|
|
|
|
|
def rss_to_dict(url):
|
|
response = requests.get(url)
|
|
data = xmltodict.parse(response.content)
|
|
|
|
#print(data['rss'])
|
|
|
|
title = data['rss']['channel']['title']
|
|
|
|
#Get the keys if needed of debug
|
|
#print(data['rss'].keys())
|
|
|
|
#use first object as it's ordered in a chronological order
|
|
today_object = data['rss']['channel']['item'][0]
|
|
today_title = today_object['title']
|
|
today_podcast_url = data['rss']['channel']['item'][0]['enclosure']['@url']
|
|
|
|
return title,today_title,today_podcast_url
|
|
|
|
def download_news_mp3(url_mp3, filename):
|
|
print("Downloading again: " + filename +" -- " + url_mp3)
|
|
try:
|
|
urlrequest.urlretrieve(url_mp3, filename)
|
|
except:
|
|
print("Can't download " + filename +" -- " + url_mp3 + " == Cancelling")
|
|
return 0
|
|
|
|
def pretty_filename(filename,extension=''):
|
|
filename = filename.replace(' ', '_')
|
|
pretty_filename = filename.replace('/', '_')
|
|
if extension != '':
|
|
extension = str('.'+extension)
|
|
return pretty_filename+extension
|
|
|
|
def main():
|
|
url = "https://feeds.audiomeans.fr/feed/44f6a116-20a6-44c4-98c4-b3e1bdd46dce.xml"
|
|
today_podcast = rss_to_dict(url)
|
|
print(today_podcast)
|
|
download_news_mp3(today_podcast[2],pretty_filename(today_podcast[1],'mp3'))
|
|
|
|
main() |