Skip to content

Commit

Permalink
Update main.py
Browse files Browse the repository at this point in the history
  • Loading branch information
akku1139 authored Aug 18, 2024
1 parent 393c51c commit 8bd7966
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions scripts/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
outfile = open("./filter.txt", mode="w")

def out(text):
outfile.write(text + "\n")
return outfile.write(text + "\n")

def encodeURI(text):
# Pythonは '_.-~' をデフォルトでエンコードしません
return urllib.parse.quote(text, safe=";,/?:@&=+$!*'()#")

out("! Homepage: https://github.com/akku1139/YouTube-spammer-filter")
out("! Title: YouTube spam comment filter for Japanese")
Expand All @@ -18,9 +22,9 @@ def make(filename, comment, func):
continue
out("www.youtube.com###sections " + func(line.strip()))

make("channels.txt", "spammer channels", lambda line: ("a[href=\"/" + urllib.parse.quote(line.removeprefix("/").removesuffix("\n"), safe="@") + "\"]:upward(6)"))
make("channels.txt", "spammer channels", lambda line: ("a[href=\"/" + encodeURI(line.removeprefix("/")) + "\"]:upward(6)"))

make("channel-regex.txt", "spammer channels (with regex)", lambda line: ("a[href=/\/" + urllib.parse.quote(line.removeprefix("/").removesuffix("\n"), safe="@") + "/]:upward(6)"))
make("channel-regex.txt", "spammer channels (with regex)", lambda line: ("a[href=/\/" + encodeURI(line.removeprefix("/")) + "/]:upward(6)"))

make("words.txt", "spam words", lambda line: ("#content-text>span:has-text(/" + line + "/):upward(5)"))

Expand Down

0 comments on commit 8bd7966

Please sign in to comment.