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: Title Formatting: How to automaticly identify different strings and remove them? (Read 362 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Title Formatting: How to automaticly identify different strings and remove them?

Hello,

I've been trying to create two lines of code related to "Title Formatting" for a few days now, but I just can't seem to get it to work.

The following background exists:
I have a playlist in foobar2000 in which only radio streams are added. All these individual streams I have included by means of m-TAGS. Now the problem is that some of these streams store additional information in the columns "Title" and "Artist" (e.g. year of release, name of the radio station), which I don't want to have there.

Therefore, it would be nice if this additional unwanted informations are automatically detected and - if present - trimmed. Thus - if it would succeed - only the title and the artist would be contained in the respective column.


The following structure is exemplary for the metadata of the problematic radio streams, as soon as I have started them:
1. title: SONGNAME, YEAR (e.g. "Song, 2019")
2. artist: RADIOSTATION ARTIST (e.g. "RADIO Station | Artist")


My programming attempts so far look like this:
I have entered both codes in the fields provided in the preferences. (Path: Display --> Columns UI -> Playlist view --> Tab "Columns")

1. title:"$left(%title%,$sub($len(%title%),6))"
On the surface, this code works. It actually truncates the radio streams in question so that only the title of the song is in the field provided. However, this code also truncates all other radio streams, which are not problematic by themselves, by the trailing six characters each. I am obviously missing a control at this point that allows trimming only for song titles that have ", YEAR" at the end.
Unfortunately, I don't know how to integrate this control mechanism.

2. artist: "$if(%album artist%,$replace(%album artist%,'RADIO Station | ',),)"
This code also seems to work. However, as soon as I use a radio station with an already slightly different name (e.g. "RADIO StationY | "), this code does not work either. With this code, an "OR" reference would probably have to be integrated, in which all strings with incorrect artist names are listed. But maybe there is a more elegant solution, which automates the whole process a bit more, without me having to add an incorrect string every time.


In the meantime I've reached the end of my modest knowledge, so I'm hoping for some help here.

Thanks a lot!

Greetings
SpezNas

Re: Title Formatting: How to automaticly identify different strings and remove them?

Reply #1
1. You can try something like that below (if I have understood you correctly). It should deal with various formats for trailing year with radio streams.
Code: [Select]
$if($strstr(%path%,'://'),$cut(%title%,$sub($if3($strstr(%title%, - 19),$strstr(%title%, - 20),$strstr(%title%, -19),$strstr(%title%, -20),$strstr(%title%,  19),$strstr(%title%,  20),$strstr(%title%, 19),$strstr(%title%, 20),$strstr(%title%, '('19),$strstr(%title%, '('20),$strstr(%title%, '['19),$strstr(%title%, '['20)),1)),%title%)
Hopefully it should be specific enough as is else you'll need extra checks to test if the match is at the end of the string. .

2. I may not have fully understood. But if | (pipe) is always present in the problematical radio streams you can get index position of | & return all to right (then $trim if needed), e.g. try:
Code: [Select]
$if($strstr(%path%,'://'),$puts(pipe,$strstr(%album artist%,|))$if($get(pipe),$trim($right(%album artist%,$sub($len(%album artist%),$get(pipe))))),%album artist%)

If pipe isn't always present then may be you can get the original radio name somehow and replace that.

$strstr(%path%,'://') is used to help identify radio streams & make the snippets more efficient: this may be adequate else you'll need to use a different more specific identifier.

Re: Title Formatting: How to automaticly identify different strings and remove them?

Reply #2
Thank you for your great code, WilB! With my modest knowledge, I couldn't have even begun to create these lines on my own.

You captured my difficulties very well. However, I could have actually illustrated my intention even better. I will add this improved illustration of my problem below.


Problem statement:
I. "Title" column:
1. Remove unwanted string ", YEAR":
General structure: SONGNAME, YEAR --> SONGNAME, YEAR --> SONGNAME
Example (remove unwanted string): "Lalalala, 2019" --> "Lalalala, 2019" --> "Lalalala"

2. Make no change if ", YEAR" does not exist:
General structure:
SONGNAME_OKAY --> SONGNAME_OKAY
Example (Make no change): "Lalalala 2" --> "Lalalala 2"
--------------------
II. "Artist" column: 
1. Remove unwanted string "RADIOSTATION":
General structure: RADIOSTATION ARTIST --> RADIOSTATION ARTIST--> ARTIST
Example (remove unwanted string): "RADIO Station | John Doe" --> "RADIO Station | John Doe" --> "John Doe"

2. Make no change if "RADIOSTATION" does not exist:
General structure: ARTIST --> ARTIST
Example (Make no change): "John Doe" --> "John Doe"


Your codes programmed for me:
I. Your second code:
The code you programmed for my second problem (in the "Artist" column) works perfectly. It detects the problematic strings and removes the parts that should be removed. All other strings are not changed. The additional control mechanism to identify a radio stream is great. Since I have organized my streams in m-TAGS so far, I changed the parameter ("://") to the corresponding folder path.


If pipe isn't always present then may be you can get the original radio name somehow and replace that.
For my current situation, the second line of code works great, since all of my currently problematic radio streams have the "pipe" in the "Artist" column.
Nevertheless, is there a relatively straightforward way to extend the code if – for example – I wanted to additionally exclude specific radio stations?

II. Your first code:
The code you programmed for my first problem works almost perfectly. However, after running the code, the problematic strings always leave a "," at the end of the song title (e.g. SONGNAME, YEAR --> SONGNAME, YEAR --> SONGNAME,). I tried to solve the problem myself and added something to your code, but unfortunately I failed again and the comma is still at the end of the song titles.


Greetings,
SpezNas

Re: Title Formatting: How to automaticly identify different strings and remove them?

Reply #3
1. Removal of trailing year. You can add a comma to the $strstr check. It has to be in single quotes: ','
I've added it to the main one you want below.
Code: [Select]
$if($strstr(%path%,'://'),$cut(%title%,$sub($if3($strstr(%title%, - 19),$strstr(%title%, - 20),$strstr(%title%, -19),$strstr(%title%, -20),$strstr(%title%,  19),$strstr(%title%,  20),$strstr(%title%,',' 19),$strstr(%title%,',' 20),$strstr(%title%, 19),$strstr(%title%, 20),$strstr(%title%, '('19),$strstr(%title%, '('20),$strstr(%title%, '['19),$strstr(%title%, '['20)),1)),%title%)

2. Removal of radio station name. Seeing as you are using m-TAGS, it should be straightforward to use a custom_tag. Call it what you like. It may be easier to JUST add the custom_tag to the problematical radio streams you want to run the code for. Set it's value to say 1. Then the code simply checks for the presence of the tag. It shouldn't require anything else to check if it's a radio stream. So you can try something like:
Code: [Select]
$if(%custom_tag%,$trim($right(%album artist%,$sub($len(%album artist%),$strstr(%album artist%,|)))),%album artist%)

 
SimplePortal 1.0.0 RC1 © 2008-2021