Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Pillow==11.3.0
colorgram.py==1.2.0
markupsafe==3.0.3
gunicorn==23.0.0
profanityfilter==2.1.0

# Test dependencies for CI/CD
pytest==8.4.2
Expand Down
14 changes: 13 additions & 1 deletion api/templates/callback.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@
<span>Interchange Artist with Song name</span>
</label>
</div>
<div class="col s12 m3">
<label class="row">
<input type="checkbox" class="filled-in" id="profanity-checkbox" />
<span>Censor Profanity</span>
</label>
</div>
</div>

<div class="row center">
Expand Down Expand Up @@ -230,7 +236,8 @@
theme: 'default',
show_offline: false,
background_color: "121212",
interchange:false
interchange:false,
profanity: false
};
var openSong = false;

Expand Down Expand Up @@ -276,6 +283,11 @@
updateUrl();
});

$("#profanity-checkbox").change(function() {
urlParams.profanity = this.checked;
updateUrl();
});

$('#theme-select').change(function() {
// Reset visibility defaults
$('.bar-color').show();
Expand Down
7 changes: 7 additions & 0 deletions api/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from dotenv import load_dotenv, find_dotenv

from util.firestore import get_firestore_db
from util.profanity import profanity_check

load_dotenv(find_dotenv())

Expand Down Expand Up @@ -350,6 +351,7 @@ def catch_all(path):
show_offline = request.args.get("show_offline", default="false") == "true"
interchange = request.args.get("interchange", default="false") == "true"
mode = request.args.get("mode", default="light")
is_enable_profanity = request.args.get("profanity", default="false") == "true"

# Handle invalid request
if not uid:
Expand Down Expand Up @@ -447,6 +449,11 @@ def catch_all(path):
artist_name = item["show"]["publisher"]
song_name = item["name"]

# Handle profanity filtering
if is_enable_profanity:
artist_name = profanity_check(artist_name)
song_name = profanity_check(song_name)

if interchange:
x = artist_name
artist_name = song_name
Expand Down
25 changes: 25 additions & 0 deletions tests/test_util_profanity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import sys
import os

# Add the parent directory to the path to import the util module
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))


def test_profanity_check_clean_text():
"""Test that clean text is returned unchanged."""
from util.profanity import profanity_check

result = profanity_check("Hello World")

assert result == "Hello World"


def test_profanity_check_profane_text():
"""Test that profane text is censored."""
from util.profanity import profanity_check

result = profanity_check("fuck")

# The exact censoring depends on the library, but should be different
assert result != "fuck"
assert "*" in result # Should contain censoring characters
11 changes: 11 additions & 0 deletions util/profanity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from profanityfilter import ProfanityFilter

pf = ProfanityFilter()


def profanity_check(name):

if pf.is_clean(name):
return name

return pf.censor(name)
Loading