def play_podcast(assistant, player_vlc, instance_vlc, podcast_dic, podcast_index=None):
assistant.speak("Tell me the name of the podcast")
msg = assistant.active_listen()
if msg in podcast_dic.keys():
rss = podcast_dic[msg]
else:
rss = DEFAULT_PODCAST
assistant.speak("There you go!")
res = feedparser.parse(rss)
number_records_in_feed = len(res.entries)
if podcast_index is None:
podcast_index = random.randint(0,len(res.entries) - 1)
if number_records_in_feed < podcast_index:
podcast_index = number_records_in_feed
href = ""
for link in res.entries[podcast_index].links:
if ".mp3" in link.href:
href = link.href
break
if href != "":
media = instance_vlc.media_new(href)
player_vlc.set_media(media)
player_vlc.play()
else:
assistant.speak("I am sorry, but the podcast requested is not available!")
评论列表
文章目录