10-14-2013, 07:18 PM | #1 |
Addict
Posts: 265
Karma: 724240
Join Date: Aug 2013
Device: KyBook
|
viewing file on device with no epub extension
Hi, I am experimenting with accessing my 'ole reader' app on my iPhone so I can view what books are on the device.
So far so good. After a lot of puzzling and wall banging I now have the reading part working up to a point. There is however one snag. This app has an option to disable file sharing via the iTunes share folder. As a result it does not place downloaded epubs in the share folder, but only keeps a copy in the internal library, which is also accessible as a sub folder struct in that same share folder, so no problem there because I can also access the internal copy. However, the files are stored without an extension. And, when building a booklist I need to store a physical path to the book on the device in the book object. But if I use the path as is, then when I do a (V)iew Book in the device view, the get_file function also receives a path to a temp outfile without extension. The result is that instead of the book being opened by Calibre, I get shown an 'Open With' dialog. Of course if iTunes file sharing is turned on, I can store the filename as found in the share folder, and then viewing the book is no problem. Even so, with file sharing enabled, there is still the possibility that a file might not exist in the share folder so I would still need to revert to the internal library and right back to the View issue I can get around this problem when sending the books from the device to Calibre because that happens to call 'prepare_addable_books' which is overlayed in my code so I can tack on the epub extension at this point. But for the life of me I have no idea what the (V)iew Book calls as then it directly lands in the get_file without any of the other overlayed def's (new to python, are they called functions like in other languages?) being called first according to the trace if I run in debug mode The problem is that once I end up in get_file, the physical file is already created and awaiting to be written to, so I cannot add an extension because the name property is read only How do I get around this? Last edited by At_Libitum; 10-14-2013 at 07:29 PM. |
10-14-2013, 11:08 PM | #2 |
creator of calibre
Posts: 43,860
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
If you want to see what the call stack is when you are in a function, use
import traceback traceback.print_stack() |
Advert | |
|
10-15-2013, 05:40 AM | #3 |
Addict
Posts: 265
Karma: 724240
Join Date: Aug 2013
Device: KyBook
|
Thanks for the suggestion
[...snipped...] EDIT: hmmm...Ah, you meant directly within get_file...done and I can of course force an error to get maybe more info... calibre, version 1.6.0 ERROR: Error: Error communicating with device global name 'out' is not defined Traceback (most recent call last): File "site-packages\calibre\gui2\device.py", line 85, in run File "site-packages\calibre\gui2\device.py", line 611, in _view_book File "C:\Users\Ruud\AppData\Local\Temp\calibrePortableT emp\calibre_jhvgtv\ijx9jo_ios_local_db\reader_over lays.py", line 820, in get_file NameError: global name 'out' is not defined So it seems I need to redefine _view_book. Last edited by At_Libitum; 10-15-2013 at 07:22 AM. |
10-15-2013, 05:46 AM | #4 |
creator of calibre
Posts: 43,860
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
IIRC you cannot override that behavior in a device interface plugin, the view_device_book() function in actions/view.py is called directly with the path supplied by the driver.
You could probably stick the extension on the paths returned by the driver and strip the extension where needed in the driver. |
10-15-2013, 07:28 AM | #5 | |
Addict
Posts: 265
Karma: 724240
Join Date: Aug 2013
Device: KyBook
|
Quote:
Let me explain, I am playing with the iOS Reader plugin. So basically mangling a copy of one of the included reader overlays. In that reader overlay code I see def's which also occur in device.py so I thought I would just need to include a local copy of 'def _view_book()' just like the overlay code has local copies for upload_book(), delete_books() , get_file() etc. ? Please keep in mind I am a novice in Python, and the language still has many mysteries for me |
|
Advert | |
|
10-15-2013, 08:30 AM | #6 |
Comparer of the Ephemeris
Posts: 1,496
Karma: 424697
Join Date: Mar 2009
Device: iPad
|
@At_libitum, the iOS reader applications plugin uses its own internal architecture independent of calibre. Any method beginning with an underscore is a local method. Methods beginning with a letter are required by calibre's plugin architecture.
_view_book() is a local method - you would need to replace it or modify it in your overlay. G |
10-15-2013, 08:36 AM | #7 | |
Addict
Posts: 265
Karma: 724240
Join Date: Aug 2013
Device: KyBook
|
Quote:
Last edited by At_Libitum; 10-15-2013 at 08:46 AM. |
|
10-15-2013, 08:45 AM | #8 |
Comparer of the Ephemeris
Posts: 1,496
Karma: 424697
Join Date: Mar 2009
Device: iPad
|
If you're trying to replace the functionality of view_books() in device.py, you should create a view_books() method in your overlay. From that point, you would presumably call your own local _view_book() method.
G |
10-15-2013, 08:46 AM | #9 | |
Addict
Posts: 265
Karma: 724240
Join Date: Aug 2013
Device: KyBook
|
Quote:
EDIT: Seems I am overlooking something. I have included a local 1:1 copy of view_book() from device.py and a version of _view_book() which checks if there's an extension on the outfile name. Neither of which triggers when pressing V in device view, keypress still goes to device.py Last edited by At_Libitum; 10-15-2013 at 09:14 AM. |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Found books with different file extension | spynumber | Conversion | 1 | 09-03-2013 08:00 PM |
Struggling with .mbp file extension. | Zatx | Kindle Fire | 6 | 02-21-2012 01:14 PM |
Troubleshooting file extension | gerry7 | Amazon Kindle | 1 | 05-25-2011 06:55 AM |
ASCM File extension, wont opened in Adobe Digital Edition | diokdin | Other formats | 4 | 12-21-2009 06:07 AM |