02-02-2017, 06:56 PM | #46 | |
Grand Sorcerer
Posts: 24,905
Karma: 47303822
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
|
Quote:
Potentially, there would need to be a trigger for each of these tables. They would probably be "BEFORE INSERT" and fiddle with the various columns in the table which include the file path. The exact trigger wouldn't be hard to work out. |
|
02-03-2017, 01:02 AM | #47 |
Groupie
Posts: 172
Karma: 4282
Join Date: Dec 2016
Location: Hungary
Device: Kobo Aura H2O
|
Thanks, I don't know much about sql triggers, so it seems to be a good time to learn!
Last edited by kido.resuri; 02-03-2017 at 03:55 PM. |
02-03-2017, 03:55 PM | #48 |
Groupie
Posts: 172
Karma: 4282
Join Date: Dec 2016
Location: Hungary
Device: Kobo Aura H2O
|
I read about triggers, and according to that, the database change should be easy to do with sql triggers.
Executing something like this [b]untested[/u] sql script on boot should do the update when virtual sd card is mounted and nickel updates it's library. !WARNING! THE FOLLOWING IS ONLY THEORETICAL! IT WAS NOT TESTED ON A KOBO DEVICE! EDIT: It was tested. Buggy, but maybe safe. This should be saved to a file "/root/library-virtual-sd.trigger" Code:
-- usage: -- $ sqlite3 /mnt/onboard/.kobo/KoboReader.sqlite < library-virtual-sd.trigger DROP TRIGGER IF EXISTS update_library_virtual_content; DROP TRIGGER IF EXISTS update_library_virtual_activity; CREATE TRIGGER IF NOT EXISTS update_library_virtual_content AFTER INSERT ON content BEGIN UPDATE content SET ContentID = REPLACE(ContentID,'/mnt/sd/virtual/','/mnt/onboard/virtualSD/'), BookID = REPLACE(BookID,'/mnt/sd/virtual/','/mnt/onboard/virtualSD/') WHERE rowid = new.rowid; END; CREATE TRIGGER IF NOT EXISTS update_library_virtual_activity AFTER INSERT ON Activity BEGIN UPDATE Activity SET Id = REPLACE(Id,'/mnt/sd/virtual/','/mnt/onboard/virtualSD/') WHERE rowid = new.rowid; END; Code:
sqlite3 /mnt/onboard/.kobo/KoboReader.sqlite < /root/library-virtual-sd.trigger Then mount the sd using the previously discussed method: Code:
mount --bind /mnt/onboard/.mysd/ /mnt/sd/virtual echo sd add /dev/mmcblk1p1 >> /tmp/nickel-hardware-status In this case, /mnt/onboard/.mysd/ is a temp dir for links copies of the new content. It should be cleared on every boot and/or by the script that copy the content to the eReader, so only new content is added to the library. Using a dir in /mnt/onboard/ for the real files should be ok, as the content is already in the library, so nickel shouldn't add them on next USB connection. These are all untested yet. EDIT: I tried the trigger offline, with SQLite Expert Personal, with this insert: Code:
INSERT INTO content (ContentID,BookID,ContentType,MimeType,___UserID) VALUES ('file:///mnt/sd/virtual/testbook2.epub','/mnt/sd/virtual/testbook2.epub',6,'application/epub+zip','adobe_user'); Last edited by kido.resuri; 02-03-2017 at 05:53 PM. Reason: minor modifications |
02-03-2017, 05:28 PM | #49 |
Groupie
Posts: 172
Karma: 4282
Join Date: Dec 2016
Location: Hungary
Device: Kobo Aura H2O
|
I tried it on Kobo. The ebook file needs to be duplicated, symlink can't be used. Sadly, the database caching of nickel prevents it to work properly. The newly added book cannot be opened untill next restart. Needs some more work..
Last edited by kido.resuri; 02-03-2017 at 05:31 PM. |
02-04-2017, 08:53 PM | #50 |
Groupie
Posts: 172
Karma: 4282
Join Date: Dec 2016
Location: Hungary
Device: Kobo Aura H2O
|
So far, so good. I experimented with this method a bit.
First of all, let me explain (if it was not clear yet) why I want to update the database entries for virtual sd card library content. - Content loaded from SD (let it be real or virtual) is only available while the SD is loaded. A vritual SD should be loaded on every boot for its content to be accessible anytime. - When a real SD card is inserted while a virtual one exists, the virtual SD's loaded content should be removed from the library. - Nickel must process the SD each time it is inserted (real or virtual), making it slow startup if the virtual is mounted on every boot (or whenever). - Such content should loose it's Shelf (Collection) associations (I'm not sure about this at all). That's why I'm trying to solve this somehow. As mentioned before, and much earlier in other threads, nickel only reads from the database when it's starting. The update can be easily done with the sql triggers, but nickel will still use the original path, even more, it will use this path to access the database and load the required files - which won't work, as the trigger already updated the values. So currently a reboot is the only solution. Nickel adds an Event table entry after the content is added to the database. This could be used to detect the addition by nickel, but shell scripts can't be run from sql triggers, so there must be some kind of shell script written which queries the changes for each newly added book. Maybe someone else finds another, better method to wait for nickel to finish reading content from the virtual SD card. |
02-05-2017, 04:26 AM | #51 |
Grand Sorcerer
Posts: 24,905
Karma: 47303822
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
|
@kido.resuri: Have you actually looked at what happens when you swap cards?
The way it works is:
If you are simulating an external SD card, you would not want to lose the reading status, bookmarks and collections for books on it. Or as you put in a real card. Last edited by davidfor; 02-05-2017 at 09:04 PM. Reason: spelling and clarity in what happens in the third point. |
02-05-2017, 05:08 AM | #52 |
Groupie
Posts: 172
Karma: 4282
Join Date: Dec 2016
Location: Hungary
Device: Kobo Aura H2O
|
Thanks davidfor, I didn't test what happens when I swap cards, as I don't have a real sd card to test with. The books on sd loosing their collections, reading status, etc. was only a theory, and as i stated, I wasn't that sure about that part. I'm happy that they won't lose these. It should be tested what happens when the virtual SD is still mounted and a real card is inserted.
Anyhow, It would look a bit strange for the user if a real sd is inserted and the "whole" library would disappear (assuming all other books were transfered via the virtual sd method) untill the real sd is removed. I'm not going to use an sd card actually as it is inconvenient on the H2O, but someone else might want to. |
02-05-2017, 09:09 AM | #53 |
Groupie
Posts: 172
Karma: 4282
Join Date: Dec 2016
Location: Hungary
Device: Kobo Aura H2O
|
I'm testing with a real sd card, and it's behavior is not satisfying.
I can't tell how this works on other devices, but on a H2O, it works this way: If I'm adding a real SD card, then it's content is processed by nickel. The new books appear in the library. I put some in collections, open them, make annotations, etc. If I remove the card and later insert it again, the collections, read status and annotations remain. If then I unplug it, and mount a virtual sd to /mnt/sd/ using: Code:
mount --bind /mnt/onboard/.mysd/ /mnt/sd echo sd add /dev/mmcblk1p1 >> /tmp/nickel-hardware-status Code:
umount /mnt/sd/ echo sd remove /dev/mmcblk1p1 >> /tmp/nickel-hardware-status BUT! If I mount the real sd after the virtual, or the virtual after the real, all the read status, annotations, etc. are removed from both the virtual and real sd, so I can't mix them. If I'm mounting the virtual one to any subdir in /mnt/sd/, than both sd's read status, etc. are not kept, also if the virtual sd is not removed before inserting the real sd then the read stats, etc. are removed from both. If I'm updating the database when virtual SD is used, then everything is kept, and treated like any other sideloaded content - after a nickel restart. If anyone else could try these on other devices, please post your experience! Last edited by kido.resuri; 02-05-2017 at 09:11 AM. |
02-05-2017, 06:51 PM | #54 |
Grand Sorcerer
Posts: 24,905
Karma: 47303822
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
|
@kido.resuri: What you described is exactly what you should have expected based on what I described.
And it will work the same on all Kobo devices running the same firmware version. The firmware is the same. The only differences are in the kernel and drivers that are devices specific. And the Touch has some different fonts and graphics. If you unpack the firmware packages for a version and do a file comparison, the files are identical. Having said that, what I wrote is how it has behaved for a long time. But, I did retest as I hadn't been using an external SD card for a while. My tests were largely with a Touch, but I did check them on a Glo and Aura H2O as well. All of them are running 4.2.8432. |
02-05-2017, 07:45 PM | #55 |
Groupie
Posts: 172
Karma: 4282
Join Date: Dec 2016
Location: Hungary
Device: Kobo Aura H2O
|
davidfor, then I misunderstood what you wrote. Thought you meant that the books' reading status, etc. on external SD cards are kept and loaded as each SD card is inserted, so one can safely change cards and keep on reading, etc. Reading your above post again now reveals what you meant. But also that is why I'm working on a workaround solution. I made sql triggers for each table in the database to log every change in the database made by nickel during an SD card insert, to find a way to catch the finish of it. I have it in my mind now, will work on it next if I have time. Basicly a script doing sql query in a loop until the newly added books appear in the database. After that, it will do a reboot, resultin in all new books will be sideloaded on the internal card.
|
02-06-2017, 05:18 AM | #56 |
Grand Sorcerer
Posts: 24,905
Karma: 47303822
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
|
OK, I changed the third point in my post to be a bit clearer.
If you want to allow real SD cards to be used, you will need to move the files. But, Kobo doesn't seem to be putting external slots in the new devices, that might not be worth worrying about. Or write to the real card and let the user eject and insert it to process the books. The other thing to consider is what happens when you connect to a PC. Will the device present the correct drives? Will calibre be able to find the books? |
02-11-2017, 12:48 PM | #57 |
Connoisseur
Posts: 83
Karma: 10
Join Date: Jul 2013
Location: Planet Ocean
Device: Kobo Glo HD, Onyx Boox Note Pro 2, Samsung Galaxy Tab S5e, Pixel 4a
|
thanks so much for all your research and feedback! I'm not sure where I stand with the database stuff - it seems to me hairy to start messing around in there...
let me know if i should change the summary to point to a solution, nevertheless... Right now, I am still using the "fake-usb-connect" hack that pops up a dialog asking the user confirmation. it's ugly, but it works, but technically (the library is re-read) but also, and more interestingly, from a usability perspective: I tell people (in the documentation and in person) that it's a hack, and they just need to tap that and things will work. so it's kind of okay. my next hurdle, at this point, is to fine-tune the *run* trigger, ie. when do i run my sync program. right now it triggers on any udev aactivity: Code:
KERNEL=="eth*", RUN+="/usr/local/bin/wallabako-run" KERNEL=="wlan*", RUN+="/usr/local/bin/wallabako-run" |
10-08-2019, 01:07 PM | #58 |
Connoisseur
Posts: 83
Karma: 10
Join Date: Jul 2013
Location: Planet Ocean
Device: Kobo Glo HD, Onyx Boox Note Pro 2, Samsung Galaxy Tab S5e, Pixel 4a
|
note that the plato author showed me a few tricks that might be useful to others here, and that I want to include in wallabako:
Apparently, there's a file in /tmp/nickel-hardware-status, created in /etc/init.d/rcS that Nickel reads from. A few scripts in the Kobo distro also write to it: /etc/udhcpc.d/default.script /usr/local/Kobo/ntpd.sh /usr/local/Kobo/udev/ac /usr/local/Kobo/udev/plug /usr/local/Kobo/udev/sd The udev scripts are triggered by rules defined in /lib/udev/rules.d/kobo.rules. Plato reads from this FIFO to get notified when the device is plugged to or unplugged from a power source. |
10-08-2019, 01:17 PM | #59 |
BLAM!
Posts: 13,497
Karma: 26047188
Join Date: Jun 2010
Location: Paris, France
Device: Kindle 2i, 3g, 4, 5w, PW, PW2, PW5; Kobo H2O, Forma, Elipsa, Sage, C2E
|
We still haven't found a better way to rescan the Library than to fake an USBMS session, though (as the sdcard bind-mount trick may have some unwanted side-effects for people actually using their sd cards ).
(But on that note, you can now automate the "Connect" click either via a Nickel setting, or via FBInk. See UNCaGED for an example of this very use-case). ---- If you like doing things your way, you can also hook into udev directly, instead of relying on the Nickel FIFO . Last edited by NiLuJe; 10-08-2019 at 01:21 PM. Reason: refs |
Tags |
filesystem, hack, reload, sdcard |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Refresh library | MrX | Calibre | 11 | 06-07-2016 05:45 PM |
Is it no possible to refresh the page automatically in Moon+ Reader? | cicabum | Android Devices | 4 | 10-22-2015 01:23 PM |
Library refresh after editing metadata | kelleybean | Library Management | 2 | 01-13-2015 10:10 AM |
Refresh library view? | Pepin33 | Development | 4 | 08-31-2012 06:18 AM |
7.40 - Automatically refresh the covers | edbro | Calibre | 0 | 01-14-2011 11:02 PM |