From 99d653eece37aa874d5dd47a57c74ed82e9a6409 Mon Sep 17 00:00:00 2001 From: norangebit Date: Tue, 1 Sep 2020 18:22:49 +0200 Subject: [PATCH 1/2] Add automatic conversion in kepub Automatic conversion from epub to kepub of new book on Kobo sync. --- cps/kobo.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cps/kobo.py b/cps/kobo.py index a6dfc3f6..dabfb6b9 100644 --- a/cps/kobo.py +++ b/cps/kobo.py @@ -178,6 +178,10 @@ def HandleSyncRequest(): reading_states_in_new_entitlements = [] for book in changed_entries: + formats = [data.format for data in book.data] + if not 'KEPUB' in formats and config.config_kepubifypath and 'EPUB' in formats: + helper.convert_book_format(book.id, config.config_calibre_dir, 'EPUB', 'KEPUB', current_user.nickname) + kobo_reading_state = get_or_create_reading_state(book.id) entitlement = { "BookEntitlement": create_book_entitlement(book, archived=(book.id in archived_book_ids)), From bdf6052388ede46c99b9cc8bec57f93382881fb0 Mon Sep 17 00:00:00 2001 From: norangebit Date: Thu, 3 Sep 2020 21:57:14 +0200 Subject: [PATCH 2/2] Conversion to kepub when creating a sync token --- cps/kobo_auth.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/cps/kobo_auth.py b/cps/kobo_auth.py index 0f6cd174..f21d1cb6 100644 --- a/cps/kobo_auth.py +++ b/cps/kobo_auth.py @@ -64,10 +64,10 @@ from datetime import datetime from os import urandom from flask import g, Blueprint, url_for, abort, request -from flask_login import login_user, login_required +from flask_login import current_user, login_user, login_required from flask_babel import gettext as _ -from . import logger, ub, lm +from . import logger, config, calibre_db, db, helper, ub, lm from .web import render_title_template try: @@ -148,6 +148,14 @@ def generate_auth_token(user_id): ub.session.add(auth_token) ub.session.commit() + + books = calibre_db.session.query(db.Books).join(db.Data).all() + + for book in books: + formats = [data.format for data in book.data] + if not 'KEPUB' in formats and config.config_kepubifypath and 'EPUB' in formats: + helper.convert_book_format(book.id, config.config_calibre_dir, 'EPUB', 'KEPUB', current_user.nickname) + return render_title_template( "generate_kobo_auth_url.html", title=_(u"Kobo Setup"),