+ def get_audiobooks(self):
+ ogg_files = {}
+ for m in self.media.filter(type='ogg').order_by().iterator():
+ ogg_files[m.name] = m
+
+ audiobooks = []
+ projects = set()
+ for mp3 in self.media.filter(type='mp3').iterator():
+ # ogg files are always from the same project
+ meta = mp3.extra_info
+ project = meta.get('project')
+ if not project:
+ # temporary fallback
+ project = u'CzytamySłuchając'
+
+ projects.add((project, meta.get('funded_by', '')))
+
+ media = {'mp3': mp3}
+
+ ogg = ogg_files.get(mp3.name)
+ if ogg:
+ media['ogg'] = ogg
+ audiobooks.append(media)
+
+ projects = sorted(projects)
+ return audiobooks, projects
+