|
|
#1 |
|
Member
![]() 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}')
|
|
|
|
|
|
#2 |
|
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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.
|
|
|
|
| Advert | |
|
|
|
|
#3 |
|
Member
![]() 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
|
|
|
|
![]() |
|
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 |