automatic download and inclusion in the podcast feed
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
from defusedxml.ElementTree import fromstring
|
from defusedxml.ElementTree import fromstring
|
||||||
import urllib.request
|
import urllib.request
|
||||||
|
import datetime
|
||||||
|
|
||||||
url = "https://www1.wdr.de/mediathek/audio/zeitzeichen/zeitzeichen-podcast-100.podcast"
|
url = "https://www1.wdr.de/mediathek/audio/zeitzeichen/zeitzeichen-podcast-100.podcast"
|
||||||
|
|
||||||
@@ -14,13 +15,31 @@ def findZander(today):
|
|||||||
if item.tag.find("enclosure") >= 0:
|
if item.tag.find("enclosure") >= 0:
|
||||||
podcasturl = today[n].attrib["url"]
|
podcasturl = today[n].attrib["url"]
|
||||||
|
|
||||||
if author.find("Zander") > 0:
|
if author.find("Zander") >= 0:
|
||||||
print(f"ZanderAlert: {title}\nDownload-URL: {podcasturl}")
|
print(f"ZanderAlert: {title}\nDownload-URL: {podcasturl}")
|
||||||
|
return {"url": podcasturl, "title": title, "full_item": today}
|
||||||
|
return None
|
||||||
|
|
||||||
with urllib.request.urlopen(url) as response:
|
with urllib.request.urlopen(url) as response:
|
||||||
feed = fromstring(response.read())[0]
|
feed = fromstring(response.read())[0]
|
||||||
|
|
||||||
for i in feed:
|
for i in feed:
|
||||||
if i.tag == "item":
|
if i.tag == "item":
|
||||||
findZander(i)
|
metadata = findZander(i)
|
||||||
break
|
break
|
||||||
|
|
||||||
|
# future feature: episode download and feed regeneration
|
||||||
|
|
||||||
|
if metadata is not None:
|
||||||
|
# wdrzeitzeichen_2017-05-16_Voltaire wird verhaftet_16051717_wdr5.mp3
|
||||||
|
day, month, year = datetime.datetime.now().strftime("%d.%m.%Y").split(".")
|
||||||
|
title = metadata["title"]
|
||||||
|
for i in (",", "(", ")"):
|
||||||
|
title = title.replace(i, "")
|
||||||
|
refdate = title.split(" ")[-1].replace(".", "")
|
||||||
|
title = " ".join(title.split(" ")[:-1])
|
||||||
|
|
||||||
|
destination = f"files/wdrzeitzeichen_{year}-{month}-{day}_{title}_{refdate}_wdr5.mp3"
|
||||||
|
urllib.request.urlretrieve(metadata["url"], "test/"+destination)
|
||||||
|
|
||||||
|
import genfeed
|
||||||
|
|||||||
Reference in New Issue
Block a user