Identifying and copying the contents of brackets into other fields without Guess Values

Short story:

Is there a way of copying the contents of parentheses to a field if they contain certain text without using GUESS VALUES?

Long story:

I have embarked on a project of converting a couple of thousand ZX Spectrum “tzx” tape files to FLAC so they can be played into a real machine, and so far so good on that. The problem is the erratic naming of them, which I feel an urge to tidy up, trim and standardise. Move the things I want into certain tag fields - Title, Year, Label (as Artist), Comment, Model - then restructure the file name as:

  • Title (?demo) (Year) (Label) (?Model) (?Comment e.g. if re-release or magazine covertape) (?Tape number/side)

GUESS VALUES only gets me so far, as only the first three items are guaranteed to be in the right place in the filenames as generated. E.g.:

  • Atic Atac (1983) (Ultimate Play The Game).flac

…Is easy. Others with more junk in them are more difficult, and some may have keepers that others don’t, so there will be variable numbers of () and there may be junk parentheses before useful ones, or not:

  • Addams Family, The (Demo) (1992) (Ocean) (128K) (Side A) (Your Sinclair Covertape) [a]

…Is less easy. At the beginning of files like this, I can replace (Demo) with {Demo} so it doesn’t get in the way of GUESS VALUE, then change it back in TITLE - I would rather something more elegant but it’s okay. Some can be identified and removed early in the process by REPLACE, e.g. protection methods like:

  • Bubble Bobble (1987) (Elite) (Speedlock).flac

…as there aren’t many, and I can name them explicitly for removal at the beginning of the process.

There are quite a few with:

  • (Tape 1 of 2)

  • (Tape 2 of 2 Side B) etc

GUESS VALUE seems to work here using:

  • %dummy% (Tape %tapeno%

Unfortunately, getting:

  • (48K-128K)

  • (128K)

  • (16K)

…into a MODEL field is troublesome. I can modify these in the filename to (model 24K-128K), (model 128K) etc to make them easier to find; however, GUESS VALUES has trouble with this, maybe there is too much other noise in brackets. I would also like to put instances of “re-release” or e.g. “Crash Covertape” into %COMMENT%.

I have been using ChatGPT to solve problems with mixed success, but if it doesn’t get it right first time, it goes around in very small circles for an alternative.

The solution that has come closest is:

  • FORMAT VALUE

  • TAPENO

    • $regexp(%_FILENAME%,'.*\[(Tape [^]]*)\].*',$1)

…This will populate the TAPENO field if the filename contains e.g. (Tape 1 Side A), with “1 Side A”, which I can work with. However, when there IS no (Tape ***) in the filename, the entire filename crosses into TAPENO and I haven’t the know-how to debug it, I can only kind of see what’s going on. Neither can ChatGPT, it just gives the same solution over and over.

Thanks for reading all this!

I doubt that your problems are actually rooted in "Guess values" but in the fact that your source string (the filename?) has no unified pattern.
Also, the separators for different types of information are not unique.
So I think that you would have to create individual format strings for each pattern.
I would try the patterns in Convert>Filename-Tag first.

Yeah, that is the problem, the filenames have information bracketed in organised order but they aren't present if they aren't needed. I don't blame Guess Values, it's just the most commonly cited resolution to bracket separation. It does get the process started pretty well though, but only gets me so far. Convert>filename>tag has the same issue, they could only be done one at a time I think.

I would suggest to Filter F3 for the most common occurence of a pattern - for example for files that contains TAPENO in the filename.

Then use your Action(s) only for this filtered list of files.

Then you could filter again for those files that NOT contain TAPENO and adjust your Actions according to your remaining titles.

As @ohrenkino already hinted above: Sometimes the effort required for a regular expression covering “all” variants is simply too great - or not possible at all.

Thank you both for your help - the filter might work well with a scattering of specialised actions - I had high hopes for that bit of code but I cannot fix it, so that might be the way to go... Cheers :slight_smile:

Guess value has its virtues if you have sets of parameters in e.g. brackets and you can determine which set of brackets should be treated as something different and therefore get its own special separator. But this still defines a general pattern.
If there is no general pattern you cannot define a matching format string.
The only way out is to filter for files with a common pattern, treat those and then filter for the next pattern.

That was critical advice and here is a good first step.

One of the most annoying problems that you face is the many parentheses in the file names. Most of these are unnecessary and they complicate the conversions. For example your output file name:

Atic Atac (1983) (Ultimate Play The Game).flac

can be shortened to simply:

Atic Atac (1983) Ultimate Play The Game.flac

with no loss of anything useful. That will make the output Tag to Filename naming pattern:

%artist% (%year%) %title%

Similarly you could "regularize" the input file names to make them more suitable for Filename to Tag operations. Here our goal would be "no parentheses in the new tags". Instead, we will use only space hyphen space for all delimiters. Three Replace operations on an input file name can do this.

Apparently you only gave us one raw file name to work with:

Addams Family, The (Demo) (1992) (Ocean) (128K) (Side A) (Your Sinclair Covertape) [a].flac

For that I suggest batch Replace operations on the filenames, in this order:

Find ") (" and replace with " - " (space hyphen space)
Find "(" and replace with "- " (hyphen space unless "(" is the first character in the file name. In that case, delete it before running the Replace operations)
Find ")" and replace with " -" (space hyphen unless ")" is the last character in the file name. In that case, delete it before running the Replace operations)

That will leave you with this file name:

Addams Family, The Demo - 1992 - Ocean - 128K - Side A - Your Sinclair Covertape [a].flac

This is much more suitable for Filename to Tag conversion.

To skip over certain fields you can insert the %dummy% variable in the conversion mask. To consolidate adjacent fields simply omit the delimiter between them and leave only a space.

You said that some names use a different field order or lack certain fields. Once you have identified those, you will be able create a naming mask to suit each file group. Then, as @Ohrenkino said, you can use the F3 filter to isolate each group for processing with its own mask.

I haven't tried to tackle all of the issues that you mention, but once you have removed parentheses from the source files, I suspect that those issues will become a lot clearer and easier to deal with. And you can easily add back parentheses to the naming strings when and if they are really needed.

The good thing about "Guess value" is the generating format string that allows regular expressions to get parts of a string that follow a pattern determined not by e.g. the number of brackets.
$regexp('Addams Family, The (Demo) (1992) (Ocean) (128K) (Side A) (Your Sinclair Covertape) [a].','(.*) \((\d+)\) \((.*?)\) \((\d+K)\) \((.*?)\) \((.*?)\)','$1==$2==$3==$4==$5==$6')
Which would result in this string:
"Addams Family, The (Demo)==1992==Ocean==128K==Side A==Your Sinclair Covertape [a].
which you could translate into
%artist%==%year%==%producer%==%dummy%==%track%==%album%
(or whereever the data should end up).
But it still relies on this particular pattern:
A string==a number==a string==a number plus K==a string==a string
If any of the parts in that pattern is left out, the pattern does not match any more and the result will be the original string.
So, all the special loops and frenzies from the past have to be taken separately to import the data in a structured way.

Appreciate all the thought put into this, thanks guys.

And yes, the problem isn't making one file name readable, it's the fact there are 18000 files with only common root of name/year/label at the start of their naming convention, then free swim with anything the original compiler thought was pertinent. Not really free swim, there is an order to which they appear but they aren't always there.I only gave one example, but it was one of the longest with the most absurd detail I could see. Assessing a filename-tag structure for file around every permuatation is just out of the question with this mess, but maybe the filter solution will cut that right down. I'm going on holidays though and I will try when I get back.

I would stress I have inherited this issue, I didn't design it, but also that works fine for the collection of .tzx files being read by a human. I am doing something I don't think has been done before, with potential for the Spectrum Next and the new USB powered The Spectrum, as well as adding the cassette art, instructions etc.

It makes me itch that ChatGPT was able to copy over the content of a bracket set using a keyword but not NOT fill it with the filename if wasn't there. That would have solved everything.

Thanks again to everyone for the help!