Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configurable auto-conversion on upload #3020

Open
wants to merge 7 commits into
base: Develop
Choose a base branch
from

Conversation

subtlepseudonym
Copy link

@subtlepseudonym subtlepseudonym commented Mar 15, 2024

Add configurable auto-conversion on upload

This change adds a step to the upload process that kicks off a conversion task if config_auto_convert_to_format is set to a valid format. To make configuring this relatively easy, a dropdown has been added to Basic Configuration>Feature Configuration, populated by Allowed Upload Fileformats.

It's been noted in an issue comment that this functionality may be slated for eventual inclusion as a plugin rather than the implementation given in this patch. If that's the case, I'm happy to close this PR.

Relevant Issues

@marie6324
Copy link

Hey, I'm trying to implement this on my existing install and keep getting the below. Running current master under the linuxservers docker image. Any thoughts?

[2024-04-19 10:30:25,902] ERROR {cps:1414} Exception on /admin/config [GET]
Traceback (most recent call last):
  File "/lsiopy/lib/python3.10/site-packages/flask/app.py", line 2190, in wsgi_app
    response = self.full_dispatch_request()
  File "/lsiopy/lib/python3.10/site-packages/flask/app.py", line 1486, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/lsiopy/lib/python3.10/site-packages/flask/app.py", line 1484, in full_dispatch_request
    rv = self.dispatch_request()
  File "/lsiopy/lib/python3.10/site-packages/flask/app.py", line 1469, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
  File "/lsiopy/lib/python3.10/site-packages/flask_login/utils.py", line 290, in decorated_view
    return current_app.ensure_sync(func)(*args, **kwargs)
  File "/app/calibre-web/cps/admin.py", line 98, in inner
    return f(*args, **kwargs)
  File "/app/calibre-web/cps/admin.py", line 248, in configuration
    return render_title_template("config_edit.html",
  File "/app/calibre-web/cps/render_template.py", line 114, in render_title_template
    return render_template(instance=config.config_calibre_web_title, sidebar=sidebar, simple=simple,
  File "/lsiopy/lib/python3.10/site-packages/flask/templating.py", line 151, in render_template
    return _render(app, template, context)
  File "/lsiopy/lib/python3.10/site-packages/flask/templating.py", line 132, in _render
    rv = template.render(context)
  File "/lsiopy/lib/python3.10/site-packages/jinja2/environment.py", line 1301, in render
    self.environment.handle_exception()
  File "/lsiopy/lib/python3.10/site-packages/jinja2/environment.py", line 936, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "/app/calibre-web/cps/templates/config_edit.html", line 1, in top-level template code
    {% extends "layout.html" %}
  File "/app/calibre-web/cps/templates/layout.html", line 167, in top-level template code
    {% block body %}{% endblock %}
  File "/app/calibre-web/cps/templates/config_edit.html", line 119, in block 'body'
    <option value="{{ format }}"{% if config.config_auto_convert_to_format.lower() == format.lower() %} selected{% endif %}>{{ format }}</option>
  File "/lsiopy/lib/python3.10/site-packages/jinja2/utils.py", line 83, in from_obj
    if hasattr(obj, "jinja_pass_arg"):
jinja2.exceptions.UndefinedError: 'None' has no attribute 'lower'

@subtlepseudonym
Copy link
Author

Hey, I'm trying to implement this on my existing install and keep getting the below. Running current master under the linuxservers docker image. Any thoughts?

Looks like I missed the case where the new config is unset. 665056c should cover it.

@marie6324
Copy link

That looks to have resolved it! Thanks for the quick turnaround.

Any thoughts on potentially allowing the convert formats to be a multiple choice? Example is Kindle and iBooks where the former wants MOBI while the latter (appears to) perform(s) better with EPUB.

@subtlepseudonym
Copy link
Author

Any thoughts on potentially allowing the convert formats to be a multiple choice? Example is Kindle and iBooks where the former wants MOBI while the latter (appears to) perform(s) better with EPUB.

Sorry for leaving you on read so long. I've updated the config field to accept a comma-delimited list of formats. I tested with auto-conversion to epub and pdf (from mobi) on my system and both jobs queued successfully.

@marie6324
Copy link

Confirmed that this works, and works beautifully. Now we just need to get it merged in. hint hint maintainers :)

@marie6324
Copy link

@OzzieIsaacs I've been using this feature for a couple months now without issue. What would it take to get the PR merged into master, or at least a feature branch parallel to the current master?

@jkrobin
Copy link

jkrobin commented Nov 21, 2024

@subtlepseudonym Love that you've done this patch, Connor, and hope it will be incorporated into the master at some point.

Until then, I was wondering if you might be able to point me (a git novice...or less) toward a good reference on how to incorporate your auto convert into my local instance of calibre-web, which I've had running for years and which was installed via docker compose.

Thanks for any info you can provide!

@subtlepseudonym
Copy link
Author

I'm running v0.6.21-ls257 via linuxserver, but on other versions, your mileage may vary.

  1. Clone linuxserver/docker-calibre-web
  2. Download calibre-web.tar.gz from my v0.6.22 release and move it into the docker-calibre-web directory
  3. In linuxserver/docker-calibre-web/Dockerfile, remove the curl command and add a COPY command as shown in the patch below
  4. Build the docker image
    a. cd linuxserver/docker-calibre-web
    b. docker build --file Dockerfile --tag calibre-web:0.6.22-dev .
  5. Update your compose manifest with the new tag

Let me know if you run into any trouble.

Dockerfile patch

diff --git a/Dockerfile b/Dockerfile
index e53f1c5..27467a3 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -11,6 +11,7 @@ ARG CALIBREWEB_RELEASE
 LABEL build_version="Linuxserver.io version:- ${VERSION} Build-date:- ${BUILD_DATE}"
 LABEL maintainer="notdriz"

+COPY ./calibre-web.tar.gz /tmp/calibre-web.tar.gz
 RUN \
   echo "**** install build packages ****" && \
   apt-get update && \
@@ -33,9 +34,6 @@ RUN \
     CALIBREWEB_RELEASE=$(curl -sX GET "https://api.github.com/repos/janeczku/calibre-web/releases/latest" \
     | awk '/tag_name/{print $4;exit}' FS='[""]'); \
   fi && \
-  curl -o \
-    /tmp/calibre-web.tar.gz -L \
-    https://github.com/janeczku/calibre-web/archive/${CALIBREWEB_RELEASE}.tar.gz && \
   mkdir -p \
     /app/calibre-web && \
   tar xf \

@jkrobin
Copy link

jkrobin commented Nov 21, 2024

@subtlepseudonym Thanks very much for your instructions, Connor! I should be able to take some time this evening to do the build.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants