-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathgenerator.py
More file actions
60 lines (43 loc) · 1.79 KB
/
Copy pathgenerator.py
File metadata and controls
60 lines (43 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""Blocklist Generator
This script will take a blocklist.txt file and turn it into multiple different blocklist formats
"""
from typing import *
import os
import sys
# Universal header for all generated files
file_header = """
--- YouTube Ad Blocklist ---
This project was created and is maintained by: Evan Pratten (@ewpratten)
More information at: https://github.com/Ewpratten/youtube_ad_blocklist
"""
def generateIPV4Hosts(block_list: List[str]) -> List[str]:
return [f"# {line}" for line in file_header.split("\n")]+[f"0.0.0.0 {entry}" for entry in block_list]
def generateIPV6Hosts(block_list: List[str]) -> List[str]:
return [f"# {line}" for line in file_header.split("\n")]+[f"::/0 {entry}" for entry in block_list]
def generateDomainsList(block_list: List[str]) -> List[str]:
return [f"# {line}" for line in file_header.split("\n")]+[entry for entry in block_list]
def generateDNSMASQList(block_list: List[str]) -> List[str]:
return [f"# {line}" for line in file_header.split("\n")]+[f"server=/{entry}/" for entry in block_list]
# All generators
generator_list: dict = {
"hosts.ipv4.txt": generateIPV4Hosts,
"hosts.ipv6.txt": generateIPV6Hosts,
"domains.txt":generateDomainsList,
"dnsmasq.txt":generateDNSMASQList
}
def main() -> int:
# Load the block list to a newline-seperated list
entries = []
with open("blocklist.txt", "r") as fp:
entries = fp.read().split("\n")
fp.close()
# Create the output dir
os.makedirs("output", exist_ok=True)
# Run every generator
for gen in generator_list:
print(f"Running generator: {gen}")
with open(f"output/{gen}", "w") as fp:
fp.write("\n".join(generator_list[gen](entries)))
fp.close()
if __name__ == "__main__":
sys.exit(main())