Parse date from filename, apply to creation date

Support for macOS users and the Mac App Store package
Post Reply
joeyjoejoe99
Posts: 1
Joined: 07 Aug 2019, 22:10

Parse date from filename, apply to creation date

Post by joeyjoejoe99 » 07 Aug 2019, 22:36

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!
Image
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!

kim
Power User
Posts: 802
Joined: 15 May 2014, 16:17

Re: Parse date from filename, apply to creation date

Post by kim » 08 Aug 2019, 04:15

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')
	fn.replace(oldDate,newDate)
}
output:
Wedding Raw - 2015.02.23 - 1080p

User avatar
rednoah
The Source
Posts: 16546
Joined: 16 Nov 2011, 08:59
Location: Taipei
Contact:

Re: Parse date from filename, apply to creation date

Post by rednoah » 08 Aug 2019, 08:53

e.g. parse 15.02.23 patterns into Date objects:

Code: Select all

fn.match(/\d+{2}.\d{2}.\d{2}/).parseDate('yy.MM.dd')

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.
:idea: Please read the FAQ and How to Request Help.

Post Reply