[Migration] remove unused oldid.py
[mygpo.git] / mygpo / directory / search.py
blobf8dc3793cfab75190fa845d7b7f95390848cec39
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 if not podcast or not podcast.title:
19 updater = PodcastUpdater()
21 try:
22 updater.update(url)
23 except NoPodcastCreated as npc:
24 return []
26 try:
27 podcast = Podcast.objects.get(urls__url=url)
28 return [podcast]
29 except Podcast.DoesNotExist:
30 return []
32 return search(q)