able to downlaod podcast mp3
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import requests
|
||||
import xmltodict
|
||||
import urllib.request
|
||||
from urllib import request as urlrequest
|
||||
from urllib import parse as urlparse
|
||||
|
||||
from django.template.loader_tags import ExtendsNode
|
||||
|
||||
|
||||
def rss_to_dict(url):
|
||||
response = requests.get(url)
|
||||
data = xmltodict.parse(response.content)
|
||||
#print(data['rss'])
|
||||
title = data['rss']['channel']['title']
|
||||
#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()
|
||||
Reference in New Issue
Block a user