Page 1 of 1

Music Video Renaming Based On File Name, please help - new user

Posted: 29 Jun 2017, 22:02
by RandomNinjaAtk
I tried searching and have found some good information but not enough for me to figure this out on my own. Anyways, I want to rename Music Videos based on file name below, most of my videos typically have a name structure of:

artist_name-song_title-source-codec-year-group.ext

I want to rename them to:

Artist Name - Song Title.ext

The purpose of this is for use with Plex or Kodi. So far I've come up with this:

{fn.replaceAll("-", replacement = " - ").replaceAll("_", replacement = " ").upperInitial()}

Which will rename the file to:

Artist Name - Song Title - Source - Codec - Year - Group.ext

My questions are is it possible to wildcard a character in a pattern match? Or is there a good way for me to after the second " - " character appears in the filename to trim or drop all remaining text in the file name?

Thanks for any help.

Re: Music Video Renaming Based On File Name, please help - new user

Posted: 30 Jun 2017, 01:06
by kim
try {fn.split(/-/)[0]+' - '+fn.split(/-/)[1]}

Re: Music Video Renaming Based On File Name, please help - new user

Posted: 30 Jun 2017, 01:10
by kim
or in one go
{(fn.replaceAll('_',' ').split(/-/)[0]+' - '+fn.replaceAll('_',' ').split(/-/)[1]).upperInitial()}

Re: Music Video Renaming Based On File Name, please help - new user

Posted: 30 Jun 2017, 02:43
by rednoah
Indeed, if "-" appears only as separator, but not as part of the artist/title, then you can just split and take.

e.g.

Code: Select all

fn.split(/-/).take(2).join('-')
test case:

Code: Select all

'artist_name-song_title-source-codec-year'.split(/-/).take(2).join('-')

Re: Music Video Renaming Based On File Name, please help - new user

Posted: 30 Jun 2017, 12:53
by RandomNinjaAtk
Thanks for all the suggestions, I'll give them a shot!