Merge pull request #822 from sim6/add_kasts_in_clients_documentation
[mygpo.git] / mygpo / directory / search.py
blob48d01c15c49617983ab4b9e2025e04ec6cdbbfac
1 from mygpo.podcasts.models import Podcast
2 from mygpo.utils import is_url, normalize_feed_url
3 from mygpo.data.feeddownloader import PodcastUpdater, NoPodcastCreated
4 from mygpo.search.index import search_podcasts as search
7 def search_podcasts(q):
9 if is_url(q):
10 url = normalize_feed_url(q)
12 try:
13 podcast = Podcast.objects.get(urls__url=url)
14 except Podcast.DoesNotExist:
15 podcast = None
17 updater = PodcastUpdater(url)
19 if not podcast or not podcast.title:
20 try:
21 updater.update_podcast()
22 except NoPodcastCreated as npc:
23 return []
25 try:
26 podcast = Podcast.objects.get(urls__url=url)
27 return [podcast]
28 except Podcast.DoesNotExist:
29 return []
31 return search(q)