podcat: tolerate items without enclosures
This commit is contained in:
parent
e1729fed05
commit
924615b282
1 changed files with 11 additions and 3 deletions
|
@ -115,7 +115,10 @@ def get_item_date(el):
|
||||||
|
|
||||||
def get_audio_from_item(item):
|
def get_audio_from_item(item):
|
||||||
encl = item.find("enclosure")
|
encl = item.find("enclosure")
|
||||||
url = encl.get("url")
|
if encl is not None:
|
||||||
|
url = encl.get("url")
|
||||||
|
else:
|
||||||
|
return None
|
||||||
audio_args = {}
|
audio_args = {}
|
||||||
if item.find("duration") is not None:
|
if item.find("duration") is not None:
|
||||||
duration_parts = item.findtext("duration").split(":")
|
duration_parts = item.findtext("duration").split(":")
|
||||||
|
@ -125,8 +128,11 @@ def get_audio_from_item(item):
|
||||||
if total_seconds:
|
if total_seconds:
|
||||||
audio_args["duration"] = total_seconds
|
audio_args["duration"] = total_seconds
|
||||||
else:
|
else:
|
||||||
for child in item.xpath("group/content"):
|
contents = item.xpath("group/content")
|
||||||
if child.get("url") == url:
|
if not contents:
|
||||||
|
contents = item.xpath("content")
|
||||||
|
for child in contents:
|
||||||
|
if child.get("url") == url and child.get("duration") is not None:
|
||||||
audio_args["duration"] = int(float(child.get("duration")))
|
audio_args["duration"] = int(float(child.get("duration")))
|
||||||
break
|
break
|
||||||
return Audio(url, **audio_args)
|
return Audio(url, **audio_args)
|
||||||
|
@ -137,6 +143,8 @@ def get_urls(tree):
|
||||||
for it in items:
|
for it in items:
|
||||||
# title = it.find("title").text
|
# title = it.find("title").text
|
||||||
audio = get_audio_from_item(it)
|
audio = get_audio_from_item(it)
|
||||||
|
if audio is None:
|
||||||
|
continue
|
||||||
if audio.date is None:
|
if audio.date is None:
|
||||||
audio.date = get_item_date(it)
|
audio.date = get_item_date(it)
|
||||||
yield audio
|
yield audio
|
||||||
|
|
Loading…
Reference in a new issue