05-25-2018, 03:05 PM | #1 |
Grand Sorcerer
Posts: 6,224
Karma: 16536676
Join Date: Sep 2009
Location: UK
Device: Kobo: KA1, ClaraHD, Forma, Libra2, Clara2E. PocketBook: TouchHD3
|
container.mi and unicode
I'm in the process of creating a User Interface plugin as a calibre version of Doitsu's new Sigil plugin (convert selected epub text files to MP3 using the MS Windows Speech API and the LAME encoder).
I'm still doing initial testing so am still running my .py scripts via calibre-debug in a Windows .bat file rather than via plugin. Consequently, I don't have access to the calibre library metadata ATMO so am trying to extract the few items I want from the container.mi object. My problem is in understanding whether a container.mi field contains unicode or something else. For example this print statement Code:
print('authors:', container.mi.authors, '\ntitle:', container.mi.title) Code:
authors: [u'Yrsa Sigur\xf0ard\xf3ttir'] title: A ‘unicode’ title Yrsa Sigurðardóttir Please can you advise how I should be accessing the container.mi data to make sure I always end up with unicode? I could do what the Sigil plugin does and extract the data directly from container.opf but I'm sure container.mi has already done a far more robust job of that than anything I could come up with. The metadata will be used to populate the MP3 tags. I can attach a small test epub if necessary. Last edited by jackie_w; 05-25-2018 at 03:12 PM. Reason: better example |
05-25-2018, 03:56 PM | #2 |
Grand Sorcerer
Posts: 6,224
Karma: 16536676
Join Date: Sep 2009
Location: UK
Device: Kobo: KA1, ClaraHD, Forma, Libra2, Clara2E. PocketBook: TouchHD3
|
After further investigation the contents of container.mi may not be my problem. The problem may arise when supplying the args to LAME.exe/subprocess.
I definitely have a problem that Sigil is correctly populating unicode MP3 tags, but when I supply what looks like the same args to LAME.exe/subprocess via calibre I get messed up unicode MP3 tags. I'll come back when I have a better question to ask. |
Advert | |
|
05-25-2018, 11:24 PM | #3 |
creator of calibre
Posts: 44,566
Karma: 24495948
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
subprocess in python 2 on windows cannot handle unicode arguments if you are using a non-utf-8 version of windows. You will need to use CreateProcess see gui2/open_with.py for an example fo doing that.
|
05-26-2018, 07:03 PM | #4 |
Grand Sorcerer
Posts: 6,224
Karma: 16536676
Join Date: Sep 2009
Location: UK
Device: Kobo: KA1, ClaraHD, Forma, Libra2, Clara2E. PocketBook: TouchHD3
|
Thanks for pointing me in the right direction.
This low-level OS stuff is way out of my comfort zone. It's taken me forever and a lot of googling to work through it but I think I finally have something which can run lame.exe, handles unicode MP3 tags and produces a returncode using Code:
retcode = win32event.WaitForSingleObject(process_handle, win32event.INFINITE)
|
05-27-2018, 12:10 AM | #5 |
creator of calibre
Posts: 44,566
Karma: 24495948
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
1. They are documented here: https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx You should use DEFAULT_ERROR_MODE. You dont need DETACHED_PROCESS
2. Yes that's fine 3. Yes the point of using CreateProcessW is that it uses the unicode windows API which passes all data between the system and the application in utf-16 encoding, regardless of the codepage that windows itself uses 4. Lets cross that bridge when you come to it. Basically the easiest way would be to simply redirect the stdout/stderr of the process to a file. Then after the process finishes read the contents of the file. |
Advert | |
|
05-27-2018, 11:19 AM | #6 | ||
Grand Sorcerer
Posts: 6,224
Karma: 16536676
Join Date: Sep 2009
Location: UK
Device: Kobo: KA1, ClaraHD, Forma, Libra2, Clara2E. PocketBook: TouchHD3
|
Quote:
Quote:
|
||
05-27-2018, 11:33 AM | #7 |
creator of calibre
Posts: 44,566
Karma: 24495948
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
No, IIRC win32process uses the correct Createprocess call internally when passed unicode arguments.
|
05-27-2018, 11:49 AM | #8 |
Grand Sorcerer
Posts: 6,224
Karma: 16536676
Join Date: Sep 2009
Location: UK
Device: Kobo: KA1, ClaraHD, Forma, Libra2, Clara2E. PocketBook: TouchHD3
|
OK, I'm glad about that. Thanks for your help
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
missing container.xml error | George H | Editor | 5 | 11-26-2022 10:43 AM |
Recreating Container.xhtml | SigilBear | Sigil | 42 | 06-27-2017 06:32 PM |
container.xml problems | SigilBear | Sigil | 4 | 06-11-2017 10:43 PM |
Container methods, various scenarios | jackie_w | Development | 15 | 11-09-2015 03:32 PM |
META-INF/container error | afpeter | ePub | 9 | 07-23-2013 02:04 AM |