Coloradohusky / ListenBrainz_File_Parser

Parses database files from different music listen tracker applications, and imports them into ListenBrainz
9 stars 1 forks source link

[jellyfin] Parse info from ItemName #1

Closed Coloradohusky closed 1 year ago

Coloradohusky commented 1 year ago

Grab album title and track title from ItemName (artist title is already parsed)

album title:
For example, if we have the string "(e)y(e)s w/o a %brain% (Eternal Home)" it should return "Eternal Home"
Or if we have "Mr. Self Destruct (The Downward Spiral (deluxe edition))" it should return "The Downward Spiral (deluxe edition)"

I'm trying to locate the parenthesis which matches the ending parenthesis in a string.
The parenthesis we want to match will always be the last character in the string, and it will always have a matching parenthesis.
I've tried doing parenthesis matching with Regex, but it gets confused by extra parenthesis (such as (deluxe edition) or (e)y(e)s)
Will look something like def return_within_parenthesis(string): return stuff_within_parenthesis
The strings will not always have balanced parenthesis
I've tried regex but can't figure out how to get it to match the correct parenthesis
Ie, "\(.+\)$" fails on the first example (the Eternal Home example) but works on the Downward Spiral example
Coloradohusky commented 1 year ago

So we have four different ItemName schemes to work with:

No extra parenthesis

NOTE: Don't rely on )), what if album is (this (that) this)

Coloradohusky commented 1 year ago

I'll have to test it more in the morning, but I believe that this works for all cases (except when there are unbalanced parenthesis in the album name)

for test in list_strings:
    song = test[::-1]
    parenthesis = 0
    for i in range(len(song)):
        if (song[i] != ")" and song[i] != "(") and parenthesis == 0:
            print(i)
            print(song[1:i-1][::-1])
            break
        else:
            if song[i] == ")":
                parenthesis = parenthesis + 1
            elif song[i] == "(":
                parenthesis = parenthesis - 1

I.e. The Girl Gets Around (Footloose: The Musical))) and The Girl Gets Around (((Footloose: The Musical) doesn't work, due to the unbalanced parenthesis, but The Girl Gets Around (Foo()tloose(): The Musical()()()()()) works