replace sanitizing rules with gPodder's normalize_feed_url()
[mygpo.git] / mygpo / directory / search.py
blobff74f5f1e9e0ea659abf8c6ec28b923270ca298e
1 from mygpo.utils import is_url, normalize_feed_url
2 from mygpo.data.feeddownloader import PodcastUpdater, NoPodcastCreated
3 from mygpo.cache import cache_result
4 from mygpo.db.couchdb.podcast import podcast_for_url, search
7 @cache_result(timeout=60*60)
8 def search_podcasts(q, limit=20, skip=0):
10 if is_url(q):
11 url = normalize_feed_url(q)
13 podcast = podcast_for_url(url, create=False)
15 if not podcast or not podcast.title:
17 updater = PodcastUpdater()
19 try:
20 updater.update(url)
21 except NoPodcastCreated as npc:
22 return [], 0
24 podcast = podcast_for_url(url)
25 if podcast:
26 return [podcast], 1
27 else:
28 return [], 0
31 return search(q, skip, limit)