View Single Post
Old 07-01-2017, 10:02 AM   #2544
Ruskie_it
Fanatic
Ruskie_it ought to be getting tired of karma fortunes by now.Ruskie_it ought to be getting tired of karma fortunes by now.Ruskie_it ought to be getting tired of karma fortunes by now.Ruskie_it ought to be getting tired of karma fortunes by now.Ruskie_it ought to be getting tired of karma fortunes by now.Ruskie_it ought to be getting tired of karma fortunes by now.Ruskie_it ought to be getting tired of karma fortunes by now.Ruskie_it ought to be getting tired of karma fortunes by now.Ruskie_it ought to be getting tired of karma fortunes by now.Ruskie_it ought to be getting tired of karma fortunes by now.Ruskie_it ought to be getting tired of karma fortunes by now.
 
Posts: 536
Karma: 1000000
Join Date: Dec 2011
Location: Rome, Italy
Device: Kindle PW5, Kindle PW4, Kindle 4 NT
Uhmmm... It is quite hard for me but let's see. I am not sure about literally ANYTHING beyond this line, however let me explain my reasoning.

First I have looked the file kfxmeta.py because it should be where the cover is extracted, but after reading it for a while - and not fully understand all the code - it seems to me that it merely extracts metadata from a passed file, assuming it has one specific format among kfx, kdf or other "derivates", let me use the term. What's important here is that it does not select the file that it is parsing, it merely determines which kind it is and proceeds to extract the cover.

Then, I take for good jhowell's statement that the same code can be used to extract the cover from the kfx file instead of the metadata in .sdr, so the point is: let's see when the kfxmeta.py is called and check if we can make so that it is passed the book .kfx instead of the sidecar, when the sidecar does not exist.

It looks it is called in linkss/bin/cover-extract shell script file, and more precisely here:

Code:
# Check if the book was a KFX...
if [ "${last_read_mime}" == "application/x-kfx-ebook" ] ; then
	# We want the metadata sidecar file, not the book itself...
	last_read_kfx="${last_read_file%.*}.sdr/assets/metadata.kfx"
	# Check that it exists...
	if [ ! -f "${last_read_kfx}" ] ; then
		kh_msg "couldn't open metadata sidecar of last read kfx book '${last_read_file}', aborting..." W q
		return 1
	fi
	# Use KFX Meta.
	# NOTE: See https://www.mobileread.com/forums/showpost.php?p=3261216&postcount=1879 and the posts around it for the rationale behind giving
	#	up and just enforcing PYTHONIOENCODING...
	#	If it ever comes back to bite us on the ass again, a cheap workaround would be to simply kill that barely useful print w/ the infile in it...
	env PYTHONIOENCODING="utf-8" ${PYTHON} ${LINKSS_BINDIR}/kfxmeta.py -c "${last_read_kfx}" "${LINKSS_TMPFS_CACHE}/"
else
	# Use Kindle Unpack
	${PYTHON} ${LINKSS_BINDIR}/kindleunpack.py "${last_read_file}" "${LINKSS_TMPFS_CACHE}/"
fi
So, my dumb idea would be to amend THIS code to this logic:

IF last read book was a kfx book then:
if the metadata sidecar file exists use it. If it doesnt', run the kfxmeta.py script on the kfx book itself.

Yet, I don't really feel comfortable to modify the script to achieve the above.

Last edited by Ruskie_it; 07-01-2017 at 10:14 AM.
Ruskie_it is offline   Reply With Quote