View Single Post
Old 08-24-2018, 02:59 PM   #5
bodiccea
Member
bodiccea began at the beginning.
 
Posts: 11
Karma: 10
Join Date: Aug 2018
Device: samsung tablet 8", kitkai
date metadata

I found a temporary solution.

I added a custom column {#brtime} of type date and built from other values.
Its template is "{timestamp:format_date(yyyyMMddhhmm)}". The issue is {timestamp} is book change, not metadata. For me changing metadata is changing book too.

My "Saving books to disk" template is (one subdir per book language).
{languages}/{#brtime}-{author_sort} - {series:|(| } {series_index:0>2s|#|) - }{title}

Is looks like for instance:
-rw-rw-r-- 1 br br 390974 Aug 24 20:11 201508150000-du Maurier,Daphné - Rebecca.epub

In calibre, Modified column is 20180224021402 (metadata change).
The date in red is book modification time {timestamp} of Calibre (strangely hhmm are 0000 for all of them).
I made a script which gets this date, renames correctly, and changes its "modification time".

Better than a situation where all books were dated Aug 2018.

The script (bash):
----------------------------------------------------------------------
#! /bin/bash
#
# finds all epubs in first level subdirs, which should have the format:
# 201402150000-Arnaud,G.J. - (La Compagnie des Glaces #08) - La Compagnie de la Banquise.epub
#
# the first date is inclusion of file in calibre.
# We will save it, suppress it from filename, and change modification time of book with this time.
#
# br, Jul 24, 2018

# first we find files corresponding to the pattern [0-9]{12}-.*\.epub in direct subdirectories,
# in case we added a single book, we do not want to do something stupid

find . -maxdepth 2 -regextype sed -type f -regex '\.\/[a-z-]*/*[0-9]\{12\}-.*\.epub$' -print | \
while read fullname
do
dirname=$(dirname "$fullname")
basename=$(basename "$fullname")
date=$(echo "$basename" | cut -c 1-12)
file=$(echo "$basename" | cut -c 14-)
newname="$dirname/$file"
mv "$fullname" "$newname"
touch -t $date "$newname"
echo processed "$fullname"
done

exit 0
----------------------------------------------------------------------

Next step, as I regular backup, I think I can find correct {last_modified} information. If the CLI Calibre permits to get/set this field, I believe I could restore everything to a normal status. I could also find information in some Calibre dates... In that case, I will change everything and choose the latest of meta-data and book last change.

Last edited by bodiccea; 08-24-2018 at 03:10 PM. Reason: typos
bodiccea is offline   Reply With Quote