Page 1 of 1

Parse date from filename, apply to creation date

Posted: 07 Aug 2019, 22:36
by joeyjoejoe99
I've been wrestling with this for a few hours and I just don't get it, so I made an account and am finally joining the forum after it's been so wonderful for me for so long.

I have several hundred media files from my dad that are formatted with the date in the file. Many of them are as follows:
  • Wedding Raw - 15.02.23 - 1080p.mp4
    5th Bday 01 - 16.06.05.mp4
    5th Bday 02 - 16.06.05.mp4
Each of these files have had the created date and modified date overwritten. My goal is to be able to parse the date and apply that date to the 'created date' of the file for each video. So I have been trying to use the date.parse function among other functions found via google to extract the date to then apply it on creation, but no luck.

Here's a snapshot of the return I'm getting. I'm sure the solution is there and probably easy for you all, so any advice is helpful!
Expression yields empty value: No signature of method: static java.util.Date.parse() is applicable for argument types: (String, String) values: [yy.MM.dd, Raw - 15.02.23 - 1080p]
Possible solutions: parse(java.lang.String), wait(), clone(), any(), grep(), putAt(java.lang.String, java.lang.Object)

Hope it all makes sense, thanks in advance!

Re: Parse date from filename, apply to creation date

Posted: 08 Aug 2019, 04:15
by kim

Code: Select all

	def oldDate = fn.match(/\d{2}\.\d{2}\.\d{2}/)
	def newDate = new java.text.SimpleDateFormat("yy.MM.dd").parse(oldDate).format('yyyy.MM.dd')
Wedding Raw - 2015.02.23 - 1080p

Re: Parse date from filename, apply to creation date

Posted: 08 Aug 2019, 08:53
by rednoah
e.g. parse 15.02.23 patterns into Date objects:

Code: Select all


e.g. set last modified date for each file accordingly:

Code: Select all

filebot -mediainfo *.mp4 -exec touch -t "{fn.match(/\d+{2}.\d{2}.\d{2}/).parseDate(/yy.MM.dd/).format(/yyyyMMdd0000/)}" {f}
:idea: We're using the touch command here, so this will work on Linux / Mac / BSD but not Windows. If you're using Windows, you'll have to modify the -exec command to something that works on Windows.