def example_podcasts(request, format): podcasts = cache.get('example-podcasts', None) try: scale = int(request.GET.get('scale_logo', 64)) except (TypeError, ValueError): return HttpResponseBadRequest('scale_logo has to be a numeric value') if scale not in range(1, 257): return HttpResponseBadRequest('scale_logo has to be a number from 1 to 256') if not podcasts: try: examples = ExamplePodcasts.get('example_podcasts') ids = examples.podcast_ids podcasts = podcasts_by_id(ids) cache.set('example-podcasts', podcasts) except ResourceNotFound: podcasts = [] title = 'gPodder Podcast Directory' domain = RequestSite(request).domain p_data = lambda p: podcast_data(p, domain, scale) return format_podcast_list( podcasts, format, title, json_map=p_data, xml_template='podcasts.xml', request=request, )
def update_published_podcasts(request, username): user = User.get_user(username) if not user: raise Http404 published_podcasts = podcasts_by_id(user.published_objects) update_podcasts.delay([podcast.url for podcast in published_podcasts]) return HttpResponse('Updated:\n' + '\n'.join([p.url for p in published_podcasts]), mimetype='text/plain')
def get_podcasts(self, count=None): user = User.get(self.user) subscriptions = user.get_subscribed_podcast_ids() ids = filter(lambda x: not x in self.blacklist + subscriptions, self.podcasts) if count: ids = ids[:count] return filter(lambda x: x and x.title, podcasts_by_id(ids))
def get_random_list(self, podcasts_per_list=5): random_list = next(random_podcastlists(), None) list_owner = None if random_list: random_list = proxy_object(random_list) random_list.more_podcasts = max(0, len(random_list.podcasts) - podcasts_per_list) random_list.podcasts = podcasts_by_id(random_list.podcasts[:podcasts_per_list]) random_list.user = get_user_by_id(random_list.user) yield random_list
def get_podcasts(self, start=0, end=10): cache_id = 'category-%s-%d-%d' % (self._id, start, end) podcasts = cache.get(cache_id) if podcasts: return podcasts ids = self.podcasts[start:end] podcasts = podcasts_by_id(ids) cache.set(cache_id, podcasts) return podcasts
def merge_podcasts(podcast_ids, num_groups): """ Task to merge some podcasts""" logger.info("merging podcast ids %s", podcast_ids) podcasts = podcasts_by_id(podcast_ids) logger.info("merging podcasts %s", podcasts) actions = Counter() pm = PodcastMerger(podcasts, actions, num_groups) podcast = pm.merge() logger.info("merging result: %s", actions) return actions, podcast
def home(request): if is_publisher(request.user): podcasts = podcasts_by_id(request.user.published_objects) site = RequestSite(request) update_token = request.user.get_token('publisher_update_token') form = SearchPodcastForm() return render(request, 'publisher/home.html', { 'update_token': update_token, 'podcasts': podcasts, 'form': form, 'site': site, }) else: site = RequestSite(request) return render(request, 'publisher/info.html', { 'site': site })
def get_list(request, plist, owner, format): """ Returns the contents of the podcast list """ try: scale = int(request.GET.get('scale_logo', 64)) except (TypeError, ValueError): return HttpResponseBadRequest('scale_logo has to be a numeric value') podcasts = podcasts_by_id(plist.podcasts) domain = RequestSite(request).domain p_data = lambda p: podcast_data(p, domain, scale) title = '{title} by {username}'.format(title=plist.title, username=owner.username) return format_podcast_list(podcasts, format, title, json_map=p_data, jsonp_padding=request.GET.get('jsonp', ''), xml_template='podcasts.xml', request=request)