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

[FEATURE] Calibre Sync #510

Open
Silther opened this issue Nov 28, 2024 · 5 comments
Open

[FEATURE] Calibre Sync #510

Silther opened this issue Nov 28, 2024 · 5 comments
Labels
enhancement New feature or request

Comments

@Silther
Copy link

Silther commented Nov 28, 2024

Is your feature request related to a problem?

Currently it is quit tedious to upload your books individually to stump.
A nicer way is having a calibre plugin that syncs your eBooks to the server (maybe even metadata changes)

Describe the solution you'd like

As an inspiration you could look at BookFusion which is generally closed source but has an open source calibre plugin and works really great.

Additional context

Add any other context or screenshots about the feature request here.

@Silther Silther added the enhancement New feature or request label Nov 28, 2024
@aaronleopold
Copy link
Collaborator

aaronleopold commented Dec 4, 2024

Hey 👋 I'm not sure I fully understand the use-case here

Currently it is quit tedious to upload your books individually to stump.
A nicer way is having a calibre plugin that syncs your eBooks to the server

Is this to say that your book collection exists outside of whatever is the host machine for your Stump instance? And that you'd like a plugin developed which will sync the library from a remote machine to the host?

I'm unfamiliar with BookFusion, so maybe I am misunderstanding the ask!

@Silther
Copy link
Author

Silther commented Dec 5, 2024

Is this to say that your book collection exists outside of whatever is the host machine for your Stump instance? And that you'd like a plugin developed which will sync the library from a remote machine to the host?

Yes,
I currently manage my library with Calibre and want to use stump as my multi device reading solution.
As I have +300 books it is quit tedious to uploud each book manually.

The proposed plugin would upload all the books via the the api and after that check if the metadata changes and than sync those changes to.

@aaronleopold
Copy link
Collaborator

aaronleopold commented Dec 5, 2024

Okay, so I grokked it correctly. To be honest, what you're describing feels less like a plugin and more like a standalone sync tool. This is pretty achievable with the Stump SDK, which can be used in some Node app which can run on your remote machine to push the books to your host (i.e., your Stump instance). I think this would be a pretty solid example to build as a means of showing off the SDK though! It would effectively be something like:

import { Api } from '@stump/sdk'
import chokidar from 'chokidar'

const sdk = new Api({
  baseURL: process.env.STUMP_URL,
  authMethod: 'token',
  apiKey: process.env.STUMP_API_TOKEN
})

const checkForBook = async (path: string) => {
  try {
    await sdk.media.getByPath(path)
    return true
  } catch (e) {
    if (e.response.status === 404) {
      return false
    } else {
      throw e
    }
  }
}

// Setup a watcher on your root directory to watch for changes. On first start, we would also
// check for any files that are not in the Stump library and upload them

const watcher = chokidar.watch('/path/to/your/root', {
  ignored: /(^|[\/\\])\../, 
  persistent: true
})

watcher.on('add', async (path) => {
  const exists = await checkForBook(path)
  if (!exists) {
    // Note: The logic here would be more complex, e.g. if you need to create a series, but this is the basic idea
    await sdk.upload.uploadBook(path)
  }
})

watcher.on('change', async (path) => {
  // Some more advanced logic to determine if we should re-upload? Currently not supported.
})

I don't know your familiarity with programming, but would happily help make this happen. Otherwise, I'll try to find some time to get the ball rolling in my spare time

Edit to add that I realized in my example the paths wouldn't match, so a different query would have to be made

@Silther
Copy link
Author

Silther commented Dec 5, 2024

I don't know your familiarity with programming, but would happily help make this happen.

I'm currently learning computer science and would be happy to help, but as I have some other projects there is no ETA. (And I have not much experience with SDKs yet.)

So if there is no hurry I would love to do it.

@aaronleopold
Copy link
Collaborator

No rush on my end! I was eager to get the idea from brain into code, so started a working branch here: https://github.com/stumpapp/stump/tree/al/integration/book-sync. I likely won't have time to work on it much, but if at any point you want to help/take over, I can help guide you through the code

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

No branches or pull requests

2 participants