def conversion_data(ctx, rd, book_id): from calibre.ebooks.conversion.config import ( NoSupportedInputFormats, get_input_format_for_book, get_sorted_output_formats) db = get_library_data(ctx, rd)[0] if not ctx.has_id(rd, db, book_id): raise BookNotFound(book_id, db) try: input_format, input_formats = get_input_format_for_book(db, book_id) except NoSupportedInputFormats: input_formats = [] else: if rd.query.get('input_fmt') and rd.query.get('input_fmt').lower() in input_formats: input_format = rd.query.get('input_fmt').lower() if input_format in input_formats: input_formats.remove(input_format) input_formats.insert(0, input_format) input_fmt = input_formats[0] if input_formats else 'epub' output_formats = get_sorted_output_formats(rd.query.get('output_fmt')) ans = { 'input_formats': [x.upper() for x in input_formats], 'output_formats': output_formats, 'profiles': profiles(), 'conversion_options': get_conversion_options(input_fmt, output_formats[0], book_id, db), 'title': db.field_for('title', book_id), 'authors': db.field_for('authors', book_id), 'book_id': book_id } return ans
def conversion_data(ctx, rd, book_id): from calibre.ebooks.conversion.config import (NoSupportedInputFormats, get_input_format_for_book, get_sorted_output_formats, load_specifics) db = get_library_data(ctx, rd)[0] if not ctx.has_id(rd, db, book_id): raise BookNotFound(book_id, db) try: input_format, input_formats = get_input_format_for_book(db, book_id) except NoSupportedInputFormats: input_formats = [] else: if input_format in input_formats: input_formats.remove(input_format) input_formats.insert(0, input_format) ans = { 'input_formats': [x.upper() for x in input_formats], 'output_formats': get_sorted_output_formats(), 'conversion_defaults': conversion_defaults(), 'conversion_specifics': load_specifics(db, book_id), 'title': db.field_for('title', book_id), 'authors': db.field_for('authors', book_id), } return ans