Rename based on text inside the file

I'm trying for a rename preset to extract a text from inside the file and add it to the filename.

I have imdb.url files that include a link to iMDB. Inside the files are text like this

[{000214A0-0000-0000-C000-000000000046}]
Prop3=19,11
[InternetShortcut]
IDList=
URL=https://www.imdb.com/title/tt7905466/

I want to extract tt7905466 and rename the file to imdb.tt7905466.url

This might be a good starting point. It adds the first line of each file to the names:

1 Like

Thank you. It was not easy but after several hours I added this

var found = -1;
if (tf != null) {
if (!tf.AtEndOfStream) {
while (found == -1) {
line = tf.ReadLine();
found = line.search("imdb.com/title/tt");
}
line = line.substr(found + 15,9);
}

2 Likes

Alternatively you could regex the id from the metadata:

function OnGetNewName(getNewNameData) {

    if (getNewNameData.item.Metadata.other.target_type != 'url') return;

    var temp = String(getNewNameData.item.Metadata.other.target);
    var tempExt = getNewNameData.newname_ext;

    temp = temp.replace(/.*\/title\/(.*?)(\/|$)/g, '$1');

    return 'imdb.' + temp + tempExt;

}
1 Like