def search_podcasts(q): if is_url(q): url = normalize_feed_url(q) try: podcast = Podcast.objects.get(urls__url=url) except Podcast.DoesNotExist: podcast = None updater = PodcastUpdater(url) if not podcast or not podcast.title: try: updater.update_podcast() except NoPodcastCreated as npc: return [] try: podcast = Podcast.objects.get(urls__url=url) return [podcast] except Podcast.DoesNotExist: return [] return search(q)
def episode_info(request): podcast_url = normalize_feed_url(request.GET.get('podcast', '')) episode_url = normalize_feed_url(request.GET.get('url', '')) # 404 before we query for url, because query would complain # about missing parameters if not podcast_url or not episode_url: raise Http404 episode = episode_for_podcast_url(podcast_url, episode_url) if episode is None: raise Http404 domain = RequestSite(request).domain resp = episode_data(episode, domain) return JsonResponse(resp)
def episode_info(request): podcast_url = normalize_feed_url(request.GET.get('podcast', '')) episode_url = normalize_feed_url(request.GET.get('url', '')) # 404 before we query for url, because query would complain # about missing parameters if not podcast_url or not episode_url: raise Http404 try: query = Episode.objects.filter(podcast__urls__url=podcast_url, urls__url=episode_url) episode = query.select_related('podcast').get() except Episode.DoesNotExist: raise Http404 domain = RequestSite(request).domain resp = episode_data(episode, domain) return JsonResponse(resp)
def podcast_info(request): url = normalize_feed_url(request.GET.get('url', '')) # 404 before we query for url, because query would complain # about missing param if not url: raise Http404 podcast = get_object_or_404(Podcast, urls__url=url) domain = RequestSite(request).domain resp = podcast_data(podcast, domain) return JsonResponse(resp)
def subscribe_url(request): url = request.GET.get('url', None) if not url: raise Http404('http://my.gpodder.org/subscribe?url=http://www.example.com/podcast.xml') url = normalize_feed_url(url) if not url: raise Http404('Please specify a valid url') podcast = Podcast.objects.get_or_create_for_url(url) return HttpResponseRedirect(get_podcast_link_target(podcast, 'subscribe'))
def get_urls(self, body): """ Parse and normalize the URLs from the request """ podcast_url = body.get('podcast', '') episode_url = body.get('episode', '') if not podcast_url: raise RequestException('Podcast URL missing') if not episode_url: raise RequestException('Episode URL missing') update_urls = [] # podcast sanitizing s_podcast_url = normalize_feed_url(podcast_url) if s_podcast_url != podcast_url: update_urls.append((podcast_url, s_podcast_url or '')) # episode sanitizing s_episode_url = normalize_feed_url(episode_url, 'episode') if s_episode_url != episode_url: update_urls.append((episode_url, s_episode_url or '')) return s_podcast_url, s_episode_url, update_urls
def get_urls(self, body): """ Parse and normalize the URLs from the request """ podcast_url = body.get("podcast", "") episode_url = body.get("episode", "") if not podcast_url: raise RequestException("Podcast URL missing") if not episode_url: raise RequestException("Episode URL missing") update_urls = [] # podcast sanitizing s_podcast_url = normalize_feed_url(podcast_url) if s_podcast_url != podcast_url: update_urls.append((podcast_url, s_podcast_url or "")) # episode sanitizing s_episode_url = normalize_feed_url(episode_url, "episode") if s_episode_url != episode_url: update_urls.append((episode_url, s_episode_url or "")) return s_podcast_url, s_episode_url, update_urls
def subscribe_url(request): url = request.GET.get('url', None) if not url: raise Http404( 'http://my.gpodder.org/subscribe?url=http://www.example.com/podcast.xml' ) url = normalize_feed_url(url) if not url: raise Http404('Please specify a valid url') podcast = Podcast.objects.get_or_create_for_url(url).object return HttpResponseRedirect(get_podcast_link_target(podcast, 'subscribe'))
def add_podcast(request): # TODO what if the url doesn't have a valid podcast? url = normalize_feed_url( json.loads(request.body.decode('utf-8')).get('url', '')) # 404 before we query for url, because query would complain # about missing param if not url: raise Http404 try: # podcast exists, redirects Podcast.objects.get(urls__url=url) api_podcast_info_path = reverse('api-podcast-info') return HttpResponseRedirect(f'{api_podcast_info_path}?url={url}') except Podcast.DoesNotExist: # podcast doesn't exist, add new podcast res = update_podcasts.delay([url]) response = HttpResponse(status=202) job_status_path = reverse('api-add-podcast-status', kwargs={"job_id": res.task_id}) response['Location'] = f'{job_status_path}?url={url}' return response
def search_podcasts(q): if is_url(q): url = normalize_feed_url(q) try: podcast = Podcast.objects.get(urls__url=url) except Podcast.DoesNotExist: podcast = None if not podcast or not podcast.title: try: update_podcast(url) except NoPodcastCreated as npc: return [] try: podcast = Podcast.objects.get(urls__url=url) return [podcast] except Podcast.DoesNotExist: return [] return search(q)
def search_podcasts(q, limit=20, skip=0): if is_url(q): url = normalize_feed_url(q) podcast = podcast_for_url(url, create=False) if not podcast or not podcast.title: updater = PodcastUpdater() try: updater.update(url) except NoPodcastCreated as npc: return [], 0 podcast = podcast_for_url(url) if podcast: return [podcast], 1 else: return [], 0 return search(q, skip, limit)
def sanitize_append(url, sanitized_list): urls = normalize_feed_url(url) if url != urls: sanitized_list.append((url, urls or "")) return urls
def sanitize_append(url, sanitized_list): urls = normalize_feed_url(url) if url != urls: sanitized_list.append( (url, urls or '') ) return urls