Bug 406855 - Feature request: date from filename
Summary: Feature request: date from filename
Status: RESOLVED FIXED
Alias: None
Product: digikam
Classification: Applications
Component: Plugin-Generic-TimeAdjust (show other bugs)
Version: 6.1.0
Platform: Other Linux
: NOR wishlist
Target Milestone: ---
Assignee: Digikam Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-04-24 18:25 UTC by MarcP
Modified: 2019-05-26 06:47 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In: 6.2.0


Attachments
Date from filename option in "Adjust Time Date" tool (94.84 KB, image/png)
2019-04-24 18:25 UTC, MarcP
Details

Note You need to log in before you can comment on or make changes to this bug.
Description MarcP 2019-04-24 18:25:16 UTC
Created attachment 119615 [details]
Date from filename option in "Adjust Time Date" tool

SUMMARY

I often find myself manually adding a date to pictures which have the date in the filename. For instance, pictures send through the WhatsApp messaging app have the following format: IMG-20110930-WA0000.jpg. Screenshots in Android look like this: Screenshot_20181013-182811~2. And profile pictures "Person Name 20170502_210305.jpg". 

As you can see, the date (and sometimes the time) can be inferred by the filename. So if you want to save that date to the file itself (since they do not have metadata due to privacy reasons), you can either do it manually or using exiftool with the following command:

    exiftool "-datetimeoriginal<filename" "/home/user/Pictures/IMG-20110930-WA0000.jpg"

I actually use a simple bash script to do so, but it would be cool if the 
"Adjust Time Date" tool included an option to automatically extract the date from the filename in a flexible way, as exiftool does.
Comment 1 Maik Qualmann 2019-04-25 21:37:04 UTC
Git commit 9ebd1311087c1bcee0b24ef60a13f82bfc9f7128 by Maik Qualmann.
Committed on 25/04/2019 at 21:35.
Pushed by mqualmann into branch 'master'.

try to get date from filename
FIXED-IN: 6.2.0

M  +2    -1    NEWS
M  +15   -0    core/dplugins/bqm/metadata/timeadjust/timeadjust.cpp
M  +29   -5    core/dplugins/generic/metadata/timeadjust/timeadjustdialog.cpp
M  +4    -0    core/dplugins/generic/metadata/timeadjust/timeadjustdialog.h
M  +64   -0    core/libs/timeadjust/timeadjustcontainer.cpp
M  +3    -0    core/libs/timeadjust/timeadjustcontainer.h
M  +24   -14   core/libs/timeadjust/timeadjustsettings.cpp

https://invent.kde.org/kde/digikam/commit/9ebd1311087c1bcee0b24ef60a13f82bfc9f7128
Comment 2 MarcP 2019-04-26 11:00:33 UTC
Wow, already? I thought it would be quite complicated to implement. I'll try it in the next build. Thanks!
Comment 3 Maik Qualmann 2019-04-26 11:45:41 UTC
I found the idea interesting. Because through images of screenshots or WhatsApp and other programs such file names with date content occur more frequently. Current if there is no time, "00:00:00" is used. Another idea? Of course, a time can still be added in the tool.

Maik
Comment 4 MarcP 2019-04-26 12:10:32 UTC
No, that's great.

I had a phone which used the format "dd-mm-yy hhmm.jpg" (I think motorolas used to do that, with filenames like "08-11-05 2312.jpg") which can be confusing even for a human if you don't know the context. What happens in this case?
Comment 5 MarcP 2019-04-26 12:19:54 UTC
I also found that some nokia phones (e.g. nokia 6120c) used the format ddmmyyyy.jpg, which can also lead to confusion. For instance, I have this picture: 20072008(001).jpg, corresponding to July 20th, 2008, where  (001), (002), etc. are used for successive pictures taken that day.
Comment 6 Maik Qualmann 2019-04-26 12:42:46 UTC
Yes, this format "dd-mm-yy hhmm.jpg" would not be recognized at this time. I'll add it tonight.

This image "20072008(001).jpg" is not a problem. The attempt with "yyyyMMdd" would fail because the month is invalid. The match would be "ddMMyyyy".

Maik
Comment 7 Maik Qualmann 2019-04-26 22:12:15 UTC
Git commit c0ee7dc6d208fb9afc4509479bb084559d39b566 by Maik Qualmann.
Committed on 26/04/2019 at 22:11.
Pushed by mqualmann into branch 'master'.

add file name date format from Motorola phone

M  +20   -3    core/libs/timeadjust/timeadjustcontainer.cpp

https://invent.kde.org/kde/digikam/commit/c0ee7dc6d208fb9afc4509479bb084559d39b566
Comment 8 MarcP 2019-04-27 18:26:50 UTC
For the sake of completeness, I've found that pictures taken with a Nokia C6-00 had this format: ddmmyyyy[xxx].jpg, such as: 01032012020.jpg, corresponding to the 1st of March, 2012, and the last there digits correspond to the number of pictures taken that day. 

That phone recorded Exif information in the pictures, so changing the date shouldn't be necessary, but just in case you wanted to test with this format.
Comment 9 Maik Qualmann 2019-04-28 18:18:07 UTC
Git commit b0f560f8982d67dea435f86762340941f58dee2b by Maik Qualmann.
Committed on 28/04/2019 at 18:17.
Pushed by mqualmann into branch 'master'.

add case for date from filename

M  +2    -0    core/libs/timeadjust/timeadjustcontainer.cpp

https://invent.kde.org/kde/digikam/commit/b0f560f8982d67dea435f86762340941f58dee2b
Comment 10 Nicofo 2019-04-29 20:13:19 UTC
Sorry to interfere in this bug report ;)
I have also old pictures without exif whose name contain the date, but the date format varies a lot.
After a rapid research I have:
yyyy_mmdd
yyyy_mmdd_hhmmss
dd_mm (no year)
dd_mm yy
etc... (I'm sure other users could easily add few more)

Also if I have for 'dd_mm' e.g. 03_05, I wonder how you could automatically detect if the format is dd_mm or mm_dd ?

So, instead of modifying the code each time a new file format is detected, it should be good if it was possible to manually tell what is the date format in the file name. E.g. a popup where you can manually enter the date template.

Just an idea...
Comment 11 Maik Qualmann 2019-04-29 20:40:27 UTC
Git commit a11cbd3b7505187e23024d73c6532b41c9e0c56f by Maik Qualmann.
Committed on 29/04/2019 at 20:39.
Pushed by mqualmann into branch 'master'.

add cases for date from filename

M  +9    -6    core/libs/timeadjust/timeadjustcontainer.cpp

https://invent.kde.org/kde/digikam/commit/a11cbd3b7505187e23024d73c6532b41c9e0c56f
Comment 12 Maik Qualmann 2019-04-29 20:49:36 UTC
To support the variant without a year I do not see as meaningful. This should definitely remain an automatic function. I have a long list of test files, where you already think about which date is hidden behind it and yet the function recognizes the date correctly. You will certainly find a combination that is detected incorrectly. ((:-))

Maik
Comment 13 MarcP 2019-05-02 21:54:06 UTC
Hey, I've been playing with this new functions, and works great! It detected virtually all date formats I found in my pictures.

Btw, one of the formats that could not detect, though, was the date used by early Android phones: "yyyy-mm-dd hh.mm.ss.jpg" (e.g.: 2009-11-07 00.50.29.jpg). Anyway, it's not really a problem because those pictures already included the date in the metadata.
Comment 14 Maik Qualmann 2019-05-03 06:04:02 UTC
Git commit 1251c037fec4499e0f9828b2bbf6acee23e0926c by Maik Qualmann.
Committed on 03/05/2019 at 06:03.
Pushed by mqualmann into branch 'master'.

accepts the point as a time separator

M  +5    -4    core/libs/timeadjust/timeadjustcontainer.cpp

https://invent.kde.org/kde/digikam/commit/1251c037fec4499e0f9828b2bbf6acee23e0926c
Comment 15 MarcP 2019-05-25 23:47:04 UTC
It's me again.

I found two pictures whose date was not detected correctly from the filename:

14-09-04_1918.jpg -> 9/4/1918 0:00:00
14-09-04_1937.jpg -> 9/4/1937 0:00:00

I guess it automatically assumes that "19xx" is the year. Again, not a big deal.