Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Development

Notices

Reply
 
Thread Tools Search this Thread
Old 04-09-2026, 07:31 PM   #1
toadclones
Member
toadclones began at the beginning.
 
Posts: 15
Karma: 42
Join Date: Dec 2023
Device: Kindle Paperwhite 12th Gen
Use existing MTP connection in Plugin script?

Hello, I have a question about everyone's favorite subject, MTP.
I'm trying to fix the Kindle Collections plugin to work with MTP devices(or just rewrite a simpler version). I'm wondering if it's possible for a plugin script to use the existing MTP connection calibre establishes rather than open a new one.
Code:
self.mtp_device = MTP_DEVICE(None)
self.mtp_device.startup()
self.scanner = DeviceScanner()
self.scanner.scan()
cd = self.mtp_device.detect_managed_devices(self.scanner.devices)
if cd is None:
    debug_print('CONNECTED DEVICES IS NONE OH NOOOO')
else:
    self.mtp_device.open(cd, 'test_lib')
    list_shit_idk = self.mtp_device.list('documents')
    debug_print(f'DOCUMENTS?? {list_shit_idk}')
This code fails on self.mtp_device.open. Calibre is already connected so I assume that's why.
toadclones is offline   Reply With Quote
Old 04-09-2026, 10:42 PM   #2
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 46,185
Karma: 29626604
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
There can be only one mtp connection to a device on non windows platforms. Look in gui2/device.py for how to use a device within the calibre gui.
kovidgoyal is offline   Reply With Quote
Advert
Old 04-10-2026, 02:51 AM   #3
toadclones
Member
toadclones began at the beginning.
 
Posts: 15
Karma: 42
Join Date: Dec 2023
Device: Kindle Paperwhite 12th Gen
Thanks! Found the CurrentlyConnectedDevice object.

For anyone else wondering, this works:

Code:
from calibre.devices.interface import currently_connected_device
from calibre.devices.mtp.driver import MTP_DEVICE

if isinstance(currently_connected_device.device, MTP_DEVICE):
    mtp_device: MTP_DEVICE = currently_connected_device.device
    books = mtp_device.books()
    # do whatever else
toadclones is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Script to avoid downloading existing duplicates in calibre dunhill Development 2 04-20-2025 12:08 PM
MTP connection issues aramaziakin Devices 16 01-16-2025 02:05 AM
Plugin test with mtp edward.81 Development 3 08-17-2014 04:32 AM
Script: store calibre ebooks as symlinks to existing lib; advanced CLI import dancal Calibre 0 12-10-2012 07:09 PM
An existing connection was forcibly closed RobFreundlich Recipes 2 06-08-2012 09:24 AM


All times are GMT -4. The time now is 08:37 PM.


MobileRead.com is a privately owned, operated and funded community.