Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Multiple Syntax-patterns for Title Formatting (add dashes to date) (Read 1469 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Multiple Syntax-patterns for Title Formatting (add dashes to date)

```
foobar2000_v1.3.17
win10_x64_v1803.17134.228
```

The DATE tag of media files are meant to be formatted as yyyy-mm-dd (2-dashes, good), but some of mine are formatted as yyyymmdd (no dashes, bad). I was only able to add a single dash instead of having two to make it proper using $insert(%date%,-,4). My issue is trying to have the additional dash be included as well but how do I do that? One thing to note is that fb2k's Title Format differs from Query Syntax where users aren't able to combine syntax via "AND" because output is literal in this case.

# PROBLEM

* Unable to add multiple instances of the Title Formatting Syntax $insert(str,insert,n)
  + My attempt is $insert(%date%,-,4), which doesn't allow room for an additional character to be inserted

Re: Multiple Syntax-patterns for Title Formatting (add dashes to date)

Reply #1
I don't know about query syntax. But in playlist column or format value from other fields you can nest $insert functions.

$insert($insert(%date%,-,4),-,7)

Problem arises if you have dates with varying precision, only the year, month, day, or maybe including time. A quick formatting script I came up erases all dashes, then inserts them again at right intervals.

Code: [Select]
$if(%date%,$puts(d,$replace(%date%,-,))$substr($get(d),1,4)$iflonger($get(d),4,-$substr($get(d),5,6)$iflonger($get(d),6,-$substr($get(d),7,99),),),)

Re: Multiple Syntax-patterns for Title Formatting (add dashes to date)

Reply #2
The proper solution is finding your problematic files and fixing them.

This should get most of them based on what you said:
Code: [Select]
NOT %date% HAS -

Then you can 'right click/properties/automatically fill values'. Select 'Other...' from the dropdown menu and you can then use a combination of $left(%date%,X) and/or $right(%date%,Y) as source, with dashes between them where it's appropiate. For example YYYYMMDD to YYYY-MM-DD:
Code: [Select]
$left(%date%,4)-$right($left(date%,6),2)-$right(%date%,2)

Make sure the files you are editing actually do follow the same format before applying a replacement like this.

Also read the documentation:
https://wiki.hydrogenaud.io/index.php?title=Foobar2000:Title_Formatting_Reference

Re: Multiple Syntax-patterns for Title Formatting (add dashes to date)

Reply #3
I appreciate the two different methods of approaching this, guys. I'll begin by saying that j7n's direct way of doing was straight to the point and it worked. I am now able to change the date format properly. Unfortunately Daeron's way of doing it didn't work for me. Again, my date format is: yyyymmdd. I'm still interested in Daeron's way for future references. In the end I chose j7n's longer syntax  :D

WORKS (see below for a better alternative):
Code: [Select]
$insert($insert(%date%,-,4),-,7)

BROKEN:
Code: [Select]
$left(%date%,4)-$right($left(date%,6),2)-$right(%date%,2)


What's more interesting is j7n's all-in-one slayer of a syntax to surely eliminate incorrect dash placements

Code: [Select]
$if(%date%,$puts(d,$replace(%date%,-,))$substr($get(d),1,4)$iflonger($get(d),4,-$substr($get(d),5,6)$iflonger($get(d),6,-$substr($get(d),7,99),),),)

Re: Multiple Syntax-patterns for Title Formatting (add dashes to date)

Reply #4
Daeron's solution is missing a percent sign before the second reference to date.

I believe that in Automatically Fill Values, you put my pattern under Source>Other (top box), and just %date% in Pattern (lower box), to indicate that the entire new string goes into date. It is the first time I used this new dialog. I was going to recommend the Masstager component, which has the same functionality, but "backwards": Format value from other fields, Destination field name - DATE and Formatting pattern - my pattern.

Since Date is a variable precision value (for example, iTunes MP4 files may contain meaningless time, or you only know the month that an album was released), I think using $right() is not safe. Also Date might not be filled in, which is why I added the first $if().

Re: Multiple Syntax-patterns for Title Formatting (add dashes to date)

Reply #5
Indeed I missed a percent sign, so the correct form would be:
Code: [Select]
$left(%date%,4)-$right($left(%date%,6),2)-$right(%date%,2)
For Pattern you just put %date%.

Using $right() is not "safe", but neither is trying to overengineer some code that checks for length, numbers, number of dashes, etc. What you usually want is a way to quickly filter faulty tracks that are alike and apply a simple change to them. Then move onto the next group and do the appropiate change again. This isn't a shot at j7n's solution, just thinking thinking out loud of how I would approach it.

You can add $if(%date%,,) like j7n said to basically do nothing to files that don't contain a value for DATE, or you can add 'AND %date% PRESENT' to your initial search query. I prefer the latter since it means the files you'll attemp to edit are limited to those deemed faulty and the rest won't clutter your view. You can also easily expand it by adding 'AND "$len(%date%)" IS 4' and so on. I suspect using titleformatting might be better for use with tagging components though, but not sure on that.

With that said fohrums nested $insert() is probably the quickest way to get the actual dash insertion done. Also, I'd look into how those tags even made it into your collection in the first place and would start using some procedure to avoid that in the future (e.g. do some basic tag checking before you add them).