View Single Post
Old 01-15-2016, 03:52 AM   #5
kacir
Wizard
kacir ought to be getting tired of karma fortunes by now.kacir ought to be getting tired of karma fortunes by now.kacir ought to be getting tired of karma fortunes by now.kacir ought to be getting tired of karma fortunes by now.kacir ought to be getting tired of karma fortunes by now.kacir ought to be getting tired of karma fortunes by now.kacir ought to be getting tired of karma fortunes by now.kacir ought to be getting tired of karma fortunes by now.kacir ought to be getting tired of karma fortunes by now.kacir ought to be getting tired of karma fortunes by now.kacir ought to be getting tired of karma fortunes by now.
 
kacir's Avatar
 
Posts: 3,463
Karma: 10684861
Join Date: May 2006
Device: PocketBook 360, before it was Sony Reader, cassiopeia A-20
Quote:
Originally Posted by kensmosis View Post
Is there an easy way to get calibre to use the unix timestamps for added files when setting the date, published date, and/or modified date fields?
there is way.
THE Unix way (TM)

As the true Unix way this is going to be accomplished by using several simple tools step-by-step.

1. You have file called john_doe_-_book title.pdf that has the filesystem date set to the desired date.

2. You write a shell script that is going to rename this file to the 2015.01.02---john_doe_-_book title.pdf format.

2.A. I personally would make a directory listing to the file, like this
Code:
cd dir_with_files
ls -l -D%Y%m%d > list_of_files.txt
and then create a vim script that would edit the list_of_files.txt to create a shell script with lines looking like this:
Code:
cp "john_doe_-_book title.pdf" "2015.01.02---john_doe_-_book title.pdf.pdf"
You can also get creative with awk or other tool of your prefference.

2.B. If this was frequently recurring job, I would spend some time creating a script that would rename the files with a command similar to this:
Code:
for f in *; do mv "$f" "$(date -d@$(stat --printf='%Y' "$f") +%Y%m%d%H%M%S)-$f"; done
. The net is full of examples of how to add creation date to the file name, but this is not what you want, you want to pull the date the file was originally created. It is possible to find examples of your desired functionality (*). There might even be a gui tool for Ubuntu, because people often want to rename *.jpeg files from the camera. Krename is one example, Thunar is another. Krename pulls creation date from exif info inside jpeg, but it might be possible to persuade it to look at the file date. Have a look http://ftp.uni-stuttgart.de/gentoo-d...ame-3.0.12.pdf

3. Use Calibre with drag & drop to add files. Configure the Calibre Prefferences, Adding books to use template
Code:
^(?P<published>((?!\s-\s).)+)---(?P<author>((?!\s-\s).)+)\s-\s?(?P<title>[^(]+)(?:\(.*\))?
3.A. If you want to know what are the magic tags, such as ?P<published> for allowed fields, just hover your mouse over the text box next to the field in the Test section of calibre configuration dialog for Prefferences -> Adding books


Do not hesitate to ask when the above instructions are not enough. I do not know your level of expertise ;-)


(*) here are a few examples I was able to find in a hurry:
http://www.arj.no/2015/08/03/add-dat...les-in-ubuntu/
http://askubuntu.com/questions/51179...o-the-filename
http://stackoverflow.com/questions/4...o-date-created

EDIT:
I have replaced
ls -l > list_of_files.txt
in my example with
ls -l -D%Y%m%d > list_of_files.txt
to get date format that is easier to process further
You can also play with the stat command to bet the date for the file instead of ls

Last edited by kacir; 01-15-2016 at 06:04 AM.
kacir is offline   Reply With Quote