X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/ce23e0cccbe0a08b22592fd589c83c9b80a4d026..89881ffd8c2da92f115f23b002f48b7e626014d0:/src/catalogue/views.py diff --git a/src/catalogue/views.py b/src/catalogue/views.py index 487310663..8d32e64ee 100644 --- a/src/catalogue/views.py +++ b/src/catalogue/views.py @@ -526,6 +526,7 @@ def stream_zip(request, media_format=None, slug=None): for bm in book.media.filter(type=media_format).order_by('index'): yield ( bm.file.path, + bm.get_extra_info_json().get('license'), names + (slugify(bm.part_name),) if bm.part_name else names ) for child in book.get_children(): @@ -533,13 +534,30 @@ def stream_zip(request, media_format=None, slug=None): zs = ZipStream() - for i, (file_path, names) in enumerate(iterate_audiobooks(book, ())): + audiobook_list = list(iterate_audiobooks(book, ())) + + licenses = set() + for i, (file_path, lic, names) in enumerate(audiobook_list): index = i + 1 part_name = '_'.join(names) + if part_name: + part_name = '_' + part_name ext = file_path.rsplit('.', 1)[-1] - zip_name = f'{book.slug}_{index:03d}_{part_name}'[:240] + '.' + ext + if len(audiobook_list) > 1: + zip_name = f'{book.slug}_{index:03d}{part_name}'[:240] + '.' + ext + else: + zip_name = book.slug[:240] + '.' + ext zs.add_path(file_path, zip_name) + lic_name = constants.LICENSES.get(lic, {}).get('locative') + if lic_name: + licenses.add(lic_name) + + readme = render_to_string('catalogue/audiobook_zip_readme.txt', { + 'licenses': licenses, + }) + zs.add(readme, 'informacje.txt') + response = StreamingHttpResponse(zs, content_type='application/zip') response['Content-Disposition'] = f'attachment; filename={slug}_{media_format}.zip' return response