2009 allow special char in tags
This commit is contained in:
parent
cf32e16547
commit
615ebde282
|
@ -10,8 +10,6 @@ import mutagen.oggtheora
|
||||||
import mutagen.oggvorbis
|
import mutagen.oggvorbis
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
from funkwhale_api.tags import models as tags_models
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
NODEFAULT = object()
|
NODEFAULT = object()
|
||||||
# default title used when imported tracks miss the `Album` tag, see #122
|
# default title used when imported tracks miss the `Album` tag, see #122
|
||||||
|
@ -618,38 +616,15 @@ class PermissiveDateField(serializers.CharField):
|
||||||
def extract_tags_from_genre(string):
|
def extract_tags_from_genre(string):
|
||||||
tags = []
|
tags = []
|
||||||
delimiter = "@@@@@"
|
delimiter = "@@@@@"
|
||||||
for d in [" - ", ",", ";", "/"]:
|
for d in [" - ", ", ", ",", "; ", ";", "/"]:
|
||||||
# Replace common tags separators by a custom delimiter
|
# Replace common tags separators by a custom delimiter
|
||||||
string = string.replace(d, delimiter)
|
string = string.replace(d, delimiter)
|
||||||
|
|
||||||
# loop on the parts (splitting on our custom delimiter)
|
# loop on the parts (splitting on our custom delimiter)
|
||||||
for tag in string.split(delimiter):
|
for tag in string.split(delimiter):
|
||||||
tag = tag.strip()
|
|
||||||
for d in ["-"]:
|
|
||||||
# preparation for replacement so that Pop-Rock becomes Pop Rock, then PopRock
|
|
||||||
# (step 1, step 2 happens below)
|
|
||||||
tag = tag.replace(d, " ")
|
|
||||||
if not tag:
|
if not tag:
|
||||||
continue
|
continue
|
||||||
final_tag = ""
|
|
||||||
if not tags_models.TAG_REGEX.match(tag.replace(" ", "")):
|
|
||||||
# the string contains some non words chars ($, €, etc.), right now
|
|
||||||
# we simply skip such tags
|
|
||||||
continue
|
|
||||||
# concatenate the parts and uppercase them so that 'pop rock' becomes 'PopRock'
|
|
||||||
if len(tag.split(" ")) == 1:
|
|
||||||
# we append the tag "as is", because it doesn't contain any space
|
|
||||||
tags.append(tag)
|
tags.append(tag)
|
||||||
continue
|
|
||||||
for part in tag.split(" "):
|
|
||||||
# the tag contains space, there's work to do to have consistent case
|
|
||||||
# 'pop rock' -> 'PopRock'
|
|
||||||
# (step 2)
|
|
||||||
if not part:
|
|
||||||
continue
|
|
||||||
final_tag += part[0].upper() + part[1:]
|
|
||||||
if final_tag:
|
|
||||||
tags.append(final_tag)
|
|
||||||
return tags
|
return tags
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -743,13 +743,13 @@ def test_artist_field_featuring():
|
||||||
[
|
[
|
||||||
("Pop", ["Pop"]),
|
("Pop", ["Pop"]),
|
||||||
("pop", ["pop"]),
|
("pop", ["pop"]),
|
||||||
("Pop-Rock", ["PopRock"]),
|
("Soundtrack - Cute Anime", ["Soundtrack", "Cute Anime"]),
|
||||||
("Pop - Rock", ["Pop", "Rock"]),
|
|
||||||
("Soundtrack - Cute Anime", ["Soundtrack", "CuteAnime"]),
|
|
||||||
("Pop, Rock", ["Pop", "Rock"]),
|
("Pop, Rock", ["Pop", "Rock"]),
|
||||||
("Chanson française", ["ChansonFrançaise"]),
|
("Chanson française", ["Chanson française"]),
|
||||||
("Unhandled❤️", []),
|
(
|
||||||
("tag with non-breaking spaces", []),
|
"tag with non-breaking spaces",
|
||||||
|
["tag\u202fwith\u202fnon-breaking\u202fspaces"],
|
||||||
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
def test_acquire_tags_from_genre(genre, expected_tags):
|
def test_acquire_tags_from_genre(genre, expected_tags):
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Allow special characters in tags (#2009)
|
Loading…
Reference in New Issue