Trying to split metadata into artist and title #3392
Replies: 3 comments 2 replies
-
@gavin2812
it will result in this: Or, you can fetch original metadata 'Artist - title'
And do with it whatever you like: split it using php e.g:
or split it with js:
|
Beta Was this translation helpful? Give feedback.
-
@gAlleb Thanks for your reply, much appreciated The issue is that I only have both the artist and title in m["title"] and I need to separate them. I'm aware I could manipulate the data outside of the liquidsoap script (using PHP for example) but I want to do it all via the liquidsoap script without any other code. Ideally I just need to be able to split the contents of m["title"] using the - (hyphen) delimiter and obtain two separate variables/strings which contain only the artist and (separately) the song title. |
Beta Was this translation helpful? Give feedback.
-
Hi @gavin2812, Anyway here's the required function. %ifndef string.split.first
def string.split.first(~separator, s)
split_parts = string.split(separator=separator, s)
if list.length(split_parts) == 0 then
error.raise(error.not_found, "String does not contain the separator.")
end
first = list.hd(split_parts)
rest = string.concat(list.tl(split_parts), separator=separator)
(first, rest)
end
%endif
def split_dash(_string)
try
string.split.first(_string, separator=" - ")
catch _ do
(_string, "")
end
end Here are the tests. test = [
"The Folk - Poppers feat. Lizzy Blue - Sky - Heartache - Dancing",
"The Folk-Poppers feat. Lizzy Blue-Sky - Heartache-Dancing",
"The Folk-Poppers - Heartache-Dancing feat. Lizzy Blue-Sky",
"The FolkPoppers feat. Lizzy BlueSky - HeartacheDancing",
"The FolkPoppers",
"HeartacheDancing",
" - HeartacheDancing",
""
]
expected = [
("The Folk", "Poppers feat. Lizzy Blue - Sky - Heartache - Dancing"),
("The Folk-Poppers feat. Lizzy Blue-Sky", "Heartache-Dancing"),
("The Folk-Poppers", "Heartache-Dancing feat. Lizzy Blue-Sky"),
("The FolkPoppers feat. Lizzy BlueSky", "HeartacheDancing"),
("The FolkPoppers", ""),
("HeartacheDancing", ""),
("", "HeartacheDancing"),
("", "")
]
def check(x, y)
if x != y then
print("Failure: got #{x} instead of #{y}")
end
end
result = list.map(split_dash, test)
check(result, expected) |
Beta Was this translation helpful? Give feedback.
-
Hello,
I'm trying to simply split the m["title" into artist and title using the script below, but all I'm getting is the following error (i'm using 2.1.0):
Code:
I've tried with variations such as:
I've also tried this:
Which also gives an error:
Can anyone help with what I'm doing wrong?
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions