Reputation: 101
I was looking for a bit of help regarding filtering out particular links (each link by season) from the following results. I'm trying to stick to using this code as much as possible to avoid further issues on applying new code I'm unsure of:
def get_playable_podcast0(soup0):
subjects = []
for content in soup0.find_all('item'):
try:
link = content.find('enclosure')
link = link.get('url')
print("\n\nLink: ", link)
title = content.find('title')
title = title.get_text()
except AttributeError:
continue
item = {
'url': link,
'title': title,
'thumbnail': "(imagelinkhere)",
}
subjects.append(item)
return subjects
def compile_playable_podcast0(playable_podcast0):
items = []
for podcast in playable_podcast0:
items.append({
'label': podcast['title'],
'thumbnail': podcast['thumbnail'],
'path': podcast['url'],
'is_playable': True,
})
return items
I'm trying to filter out the link for each season and the best way to do it is probably using the tag already within the .mp3 link I've been grabbing, link to be parsed and an example here:
<enclosure url="https://cbc.mc.tritondigital.com/..0916.mp3?ttag=season:5" length="34742214" type="audio/mpeg"/>
So in short, how do I tell it to only return only links with a prespecified season?
Upvotes: 0
Views: 102
Reputation: 17368
def filter_season(season_id):
urls = []
for content in soup.find_all('item'):
try:
link = content.find('enclosure')
link = link.get('url')
if link.endswith("ttag=season:{}".format(season_id)):
urls.append(link)
except AttributeError:
continue
return urls
Upvotes: 1