Append labels (as words) and tags to file names (selected)

Discuss and share scripts and script files...
AugerJ
Posts: 39
Joined: 19 Jul 2016 06:27

Append labels (as words) and tags to file names (selected)

Post by AugerJ » 14 Jul 2017 23:33

Hello. I hope I've chosen the forum section right.
Since there's no Mac version of XYplorer and I have a lot of info in tags by now,
I'm interested in possibility to add this info to file names.
For example, the file

File Name.ext

with label 'Blue'
and with a tag 'main part from 5m47s'
would look like this:

File Name [Blue; main part from 5m47s].ext

still with label 'Blue'
and with a tag 'main part from 5m47s'
(they shouldn't be removed).

(Space and square braces — so I know it's from label and tag.)

For selected files only — so you can "update" the new file names without rewriting the old ones.

Does such script exist or can it be made?

Thanks.

highend
Posts: 8302
Joined: 06 Feb 2011 00:33

Re: Append labels (as words) and tags to file names (selected)

Post by highend » 14 Jul 2017 23:58

Does only work with at least v18.00.0021 or newer...

Files without label AND tags are NOT renamed!
If you want to change that, change

Code: Select all

        if (!$label && !$tags) { continue; }
        else { renameitem("* [$label; $tags]", $file); }
to

Code: Select all

        renameitem("* [$label; $tags]", $file);

Code: Select all

    end (compare(<xyver>, "18.00.0021", "v") == -1), "You need at least v18.00.0021 of XYplorer, aborted!";

    foreach($file, <get "SelectedItemsPathNames" <crlf>>, <crlf>, "e") {
        // Ignore folders
        if (exists($file) == 2) { continue; }

        $label = tagitems("label", , $file, 2);
        $tags  = tagitems("tags", , $file);

        if (!$label && !$tags) { continue; }
        else { renameitem("* [$label; $tags]", $file); }
    }
One of my scripts helped you out? Please donate via Paypal or highend (at) web (dot) de

AugerJ
Posts: 39
Joined: 19 Jul 2016 06:27

Re: Append labels (as words) and tags to file names (selected)

Post by AugerJ » 15 Jul 2017 01:27

Hi, highend, and thank you.

AugerJ
Posts: 39
Joined: 19 Jul 2016 06:27

Re: Append labels (as words) and tags to file names (selected)

Post by AugerJ » 15 Jul 2017 06:10

If there's a dot ( . ) somewhere in a tag, the script considers the rest as an extension.
For example,

File Name.ext

with a tag: 8.1
becomes

File Name [8.1]

1] replaces the extension.

Image

By the way, It's good that the divider ( ; ) is always present, for clarity.

Only dots mess things up...

highend
Posts: 8302
Joined: 06 Feb 2011 00:33

Re: Append labels (as words) and tags to file names (selected)

Post by highend » 15 Jul 2017 07:47

Code: Select all

    end (compare(<xyver>, "18.00.0021", "v") == -1), "You need at least v18.00.0021 of XYplorer, aborted!";

    foreach($file, <get "SelectedItemsPathNames" <crlf>>, <crlf>, "e") {
        // Ignore folders
        if (exists($file) == 2) { continue; }

        $label = tagitems("label", , $file, 2);
        $tags  = tagitems("tags", , $file);

        if (!$label && !$tags) { continue; }
        else {
            $base = gpc($file, "base");
            $ext  = gpc($file, "ext");
            renameitem("$base [$label; $tags].$ext", $file);
        }
    }
One of my scripts helped you out? Please donate via Paypal or highend (at) web (dot) de

AugerJ
Posts: 39
Joined: 19 Jul 2016 06:27

Re: Append labels (as words) and tags to file names (selected)

Post by AugerJ » 15 Jul 2017 08:40

Heavy! Thank you very much!

highend
Posts: 8302
Joined: 06 Feb 2011 00:33

Re: Append labels (as words) and tags to file names (selected)

Post by highend » 15 Jul 2017 08:49

Btw, the original code could be changed to

Code: Select all

        if (!$label && !$tags) { continue; }
        else { renameitem("* [$label; $tags].?", $file); }
and should work as well...
One of my scripts helped you out? Please donate via Paypal or highend (at) web (dot) de

AugerJ
Posts: 39
Joined: 19 Jul 2016 06:27

Re: Append labels (as words) and tags to file names (selected)

Post by AugerJ » 16 Jul 2017 16:02

Hello again )
Can this action be reversed?

File Name [this to label; this to tags].ext

Some of the file names contain square braces, but not ; symbol between those braces,
so the script shouldn't be mistaken.

P. S. Ah, this script would require version 18 as well?..
It seems, (more 3D looking) version 14 has some troubles reading tag.dat created by version 18...
Or can I just open the *dat it some text editor, select all except for the version info and copy and paste it into the *dat for version 14?
Last edited by AugerJ on 16 Jul 2017 16:12, edited 1 time in total.

highend
Posts: 8302
Joined: 06 Feb 2011 00:33

Re: Append labels (as words) and tags to file names (selected)

Post by highend » 16 Jul 2017 16:04

Show a few of those names, especially those with additional square brackets

Full names, after the tagging + labeling script renamed the original ones

And by reversed, you mean
that tag + label is created and the [from label; from tag]
is removed from the file name?
One of my scripts helped you out? Please donate via Paypal or highend (at) web (dot) de

AugerJ
Posts: 39
Joined: 19 Jul 2016 06:27

Re: Append labels (as words) and tags to file names (selected)

Post by AugerJ » 16 Jul 2017 16:24

highend wrote:Show a few of those names, especially those with additional square brackets

Full names, after the tagging + labeling script renamed the original ones
[ENG] Iris 1.5 Parody @ SNL Korea [Grey; )].mp4
And by reversed, you mean
that tag + label is created and the [from label; from tag]
is removed from the file name?
No, it should stay.
"Labels" and "tags" in the file names — for another system (e.g. Mac OS)
and "proper" labels and tags — for the current system.

AugerJ
Posts: 39
Joined: 19 Jul 2016 06:27

Re: Append labels (as words) and tags to file names (selected)

Post by AugerJ » 16 Jul 2017 16:47

There are file names like these:
[Fancam] 100522 Sunny SNSD - Intro+Run Devil Run [Grey; distorted heavily].mp4

(10.08.08) Bouquet Ep.03 (Super Junior, Miss A) [ENG SUB] [Grey; )].mp4

[15.09.18] 베스티 - Excuse Me(평촌1번가 문화의거리 축제) by 헤임달 [Grey; ].mp4

or

[15.09.18] 베스티 - Excuse Me[평촌1번가 문화의거리 축제] by 헤임달 [Grey; ].mp4

Examples with square braces:
[60fps]
[4K]

Mostly dates
like [131229]
the fancam word
and
[ENG SUB]

And some names in Korean.

highend
Posts: 8302
Joined: 06 Feb 2011 00:33

Re: Append labels (as words) and tags to file names (selected)

Post by highend » 16 Jul 2017 16:59

As long as the square brackets don't contain the semicolon it should work:

Code: Select all

    end (compare(<xyver>, "18.00.0021", "v") == -1), "You need at least v18.00.0021 of XYplorer, aborted!";

    $labels = regexmatches(readfile("<xydata>\tag.dat", , 2000), "^((.+?)\|\|(.+?)){7,}$");
    $labels = trim(regexreplace($labels, "\|\|[A-F0-9]{6};?", "|"), "|");

    foreach($file, <get "SelectedItemsPathNames" <crlf>>, <crlf>, "e") {
        // Ignore folders
        if (exists($file) == 2) { continue; }

        // Find [<label name>;<tag>]
        $base = gpc($file, "base");
        $match = regexreplace(regexmatches($base, "\[[^]]*;[^]]*\]"), "\[|\]");
        if (!$match) { continue; }

        // Get label index from label name + tag
        $labelName = trim(gettoken($match, 1, ";"));
        $labelIndex = gettokenindex($labelName, $labels);
        $tag = trim(gettoken($match, 2, ";"));

        // Label + tag item
        if ($labelIndex) { tagitems("label", $labelIndex, $file); }
        if ($tag) { tagitems("tags", $tag, $file); }
    }
One of my scripts helped you out? Please donate via Paypal or highend (at) web (dot) de

AugerJ
Posts: 39
Joined: 19 Jul 2016 06:27

Re: Append labels (as words) and tags to file names (selected)

Post by AugerJ » 16 Jul 2017 17:26

It works for tags, not for labels.

AugerJ
Posts: 39
Joined: 19 Jul 2016 06:27

Re: Append labels (as words) and tags to file names (selected)

Post by AugerJ » 16 Jul 2017 17:47

Anyway, tags are the important part,
because, if not by running a script,
I can search (Booliean):
Blue;
then select all and assign the label
etc.
It wouldn't take too long.

So, thank you for your help.

highend
Posts: 8302
Joined: 06 Feb 2011 00:33

Re: Append labels (as words) and tags to file names (selected)

Post by highend » 16 Jul 2017 18:08

Labels are working fine here...

Which XY version?
Show me the file name where a label isn't set
Open your tag.dat file and show me the line
after "Labels:"
One of my scripts helped you out? Please donate via Paypal or highend (at) web (dot) de

Post Reply