1 # This file is part of Wolne Lektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
4 from django.contrib.sites.models import Site
5 from django.contrib.syndication.views import Feed
6 from django.urls import reverse
8 from catalogue import models
11 def absolute_url(url):
12 return "http://%s%s" % (Site.objects.get_current().domain, url)
15 class AudiobookFeed(Feed):
16 description = "Audiobooki ostatnio dodane do serwisu Wolne Lektury."
21 'daisy': 'application/zip',
25 'all': 'WolneLektury.pl - audiobooki we wszystkich formatach',
26 'mp3': 'WolneLektury.pl - audiobooki w formacie MP3',
27 'ogg': 'WolneLektury.pl - audiobooki w formacie Ogg Vorbis',
28 'daisy': 'WolneLektury.pl - audiobooki w formacie DAISY',
31 def get_object(self, request, type):
32 return {'type': type, 'all': 'all' in request.GET}
34 def title(self, args):
35 return self.titles[args['type']]
38 return reverse('audiobook_feed', args=(args['type'],))
40 def items(self, args):
41 objects = models.BookMedia.objects.order_by('-uploaded_at')
42 objects = objects.filter(book__findable=True)
44 objects = objects.filter(type__in=('mp3', 'ogg', 'daisy'))
46 objects = objects.filter(type=args['type'])
48 objects = objects[:50]
51 def item_title(self, item):
54 def item_categories(self, item):
55 return sorted(item.book.authors().values_list('name', flat=True))
57 def item_description(self, item):
59 extra_info = item.get_extra_info_json()
60 artist = extra_info.get('artist_name', None)
61 if artist is not None:
62 lines.append('Czyta: %s' % artist)
63 director = extra_info.get('director_name', None)
64 if director is not None:
65 lines.append('Reżyseria: %s' % director)
66 return '<br/>\n'.join(lines)
68 def item_link(self, item):
69 return item.book.get_absolute_url()
71 def item_guid(self, item):
72 return absolute_url(item.file.url)
74 def item_enclosure_url(self, item):
75 return absolute_url(item.file.url)
77 def item_enclosure_length(self, item):
80 def item_enclosure_mime_type(self, item):
81 return self.mime_types[item.type]
83 def item_pubdate(self, item):
84 return item.uploaded_at