Skip to content

Commit 6e2a0ad

Browse files
committed
Initial Commit.
1 parent a7ac4d6 commit 6e2a0ad

File tree

11 files changed

+955
-0
lines changed

11 files changed

+955
-0
lines changed

README.rst

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
adblock-decoder
2+
===============
3+
4+
A set of tools for the decoding and conversion of AdBlock and filter lists.
5+
The decoder itself is part of the PyFunceble project.
6+
7+
Installation
8+
------------
9+
10+
::
11+
12+
$ pip install --user adblock-decoder
13+
14+
Tools
15+
-----
16+
17+
:code:`adblock2hosts`
18+
^^^^^^^^^^^^^^^^^^^^^
19+
20+
A tool to convert adblock or filter lists to hosts format.
21+
22+
Usage
23+
"""""
24+
25+
::
26+
27+
usage: adblock2hosts [-h] [--aggressive] [--ip IP] [-o OUTPUT] input_file
28+
29+
An AdBlock2hosts converter.
30+
31+
positional arguments:
32+
input_file The input file to work with.
33+
34+
optional arguments:
35+
-h, --help show this help message and exit
36+
--aggressive [USE AT YOUR OWN RISK AS IT IS EXPERIMENTAL] Activates the extraction of everything regardless of the interpretation of AdBlock/UBlock.
37+
--ip IP Sets the IP to use while generating the hosts file.
38+
-o OUTPUT, --output OUTPUT
39+
The file to write to.
40+
41+
Crafted with ♥ by Nissar Chababy (Funilrys)!
42+
43+
:code:`adblock2plain`
44+
^^^^^^^^^^^^^^^^^^^^^
45+
46+
A tool to convert adblock or filter lists to plain text format.
47+
48+
49+
Usage
50+
"""""
51+
52+
::
53+
54+
usage: adblock2plain [-h] [--aggressive] [-o OUTPUT] input_file
55+
56+
An AdBlock2plain (text) converter.
57+
58+
positional arguments:
59+
input_file The input file to work with.
60+
61+
optional arguments:
62+
-h, --help show this help message and exit
63+
--aggressive [USE AT YOUR OWN RISK AS IT IS EXPERIMENTAL] Activates the extraction of everything regardless of the interpretation of AdBlock/UBlock.
64+
-o OUTPUT, --output OUTPUT
65+
The file to write to.
66+
67+
Crafted with ♥ by Nissar Chababy (Funilrys)!
68+
69+
70+
License
71+
-------
72+
73+
::
74+
75+
MIT License
76+
77+
Copyright (c) 2020 PyFunceble
78+
Copyright (c) 2020 Nissar Chababy
79+
80+
Permission is hereby granted, free of charge, to any person obtaining a copy
81+
of this software and associated documentation files (the "Software"), to deal
82+
in the Software without restriction, including without limitation the rights
83+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
84+
copies of the Software, and to permit persons to whom the Software is
85+
furnished to do so, subject to the following conditions:
86+
87+
The above copyright notice and this permission notice shall be included in all
88+
copies or substantial portions of the Software.
89+
90+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
91+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
92+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
93+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
94+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
95+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
96+
SOFTWARE.

adblock_decoder/__init__.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
"""
2+
The tool to check the availability or syntax of domains, IPv4, IPv6 or URL.
3+
4+
::
5+
6+
7+
██████╗ ██╗ ██╗███████╗██╗ ██╗███╗ ██╗ ██████╗███████╗██████╗ ██╗ ███████╗
8+
██╔══██╗╚██╗ ██╔╝██╔════╝██║ ██║████╗ ██║██╔════╝██╔════╝██╔══██╗██║ ██╔════╝
9+
██████╔╝ ╚████╔╝ █████╗ ██║ ██║██╔██╗ ██║██║ █████╗ ██████╔╝██║ █████╗
10+
██╔═══╝ ╚██╔╝ ██╔══╝ ██║ ██║██║╚██╗██║██║ ██╔══╝ ██╔══██╗██║ ██╔══╝
11+
██║ ██║ ██║ ╚██████╔╝██║ ╚████║╚██████╗███████╗██████╔╝███████╗███████╗
12+
╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝ ╚═════╝╚══════╝╚═════╝ ╚══════╝╚══════╝
13+
14+
This project is part of the PyFunceble project and infrastructure.
15+
16+
Author:
17+
Nissar Chababy, @funilrys, contactTATAfunilrysTODTODcom
18+
19+
Special thanks:
20+
https://pyfunceble.github.io/special-thanks.html
21+
22+
Contributors:
23+
https://pyfunceble.github.io/contributors.html
24+
25+
Project link:
26+
https://github.com/funilrys/PyFunceble
27+
28+
Project documentation:
29+
https://pyfunceble.readthedocs.io/en/dev/
30+
31+
Project homepage:
32+
https://pyfunceble.github.io/
33+
34+
License:
35+
::
36+
37+
38+
MIT License
39+
40+
Copyright (c) 2019, 2020 PyFunceble
41+
Copyright (c) 2017, 2018, 2019, 2020 Nissar Chababy
42+
43+
Permission is hereby granted, free of charge, to any person obtaining a copy
44+
of this software and associated documentation files (the "Software"), to deal
45+
in the Software without restriction, including without limitation the rights
46+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
47+
copies of the Software, and to permit persons to whom the Software is
48+
furnished to do so, subject to the following conditions:
49+
50+
The above copyright notice and this permission notice shall be included in all
51+
copies or substantial portions of the Software.
52+
53+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
54+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
55+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
56+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
57+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
58+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
59+
SOFTWARE.
60+
"""
61+
62+
VERSION = "1.0.0"

adblock_decoder/cli.py

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
"""
2+
The tool to check the availability or syntax of domains, IPv4, IPv6 or URL.
3+
4+
::
5+
6+
7+
██████╗ ██╗ ██╗███████╗██╗ ██╗███╗ ██╗ ██████╗███████╗██████╗ ██╗ ███████╗
8+
██╔══██╗╚██╗ ██╔╝██╔════╝██║ ██║████╗ ██║██╔════╝██╔════╝██╔══██╗██║ ██╔════╝
9+
██████╔╝ ╚████╔╝ █████╗ ██║ ██║██╔██╗ ██║██║ █████╗ ██████╔╝██║ █████╗
10+
██╔═══╝ ╚██╔╝ ██╔══╝ ██║ ██║██║╚██╗██║██║ ██╔══╝ ██╔══██╗██║ ██╔══╝
11+
██║ ██║ ██║ ╚██████╔╝██║ ╚████║╚██████╗███████╗██████╔╝███████╗███████╗
12+
╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝ ╚═════╝╚══════╝╚═════╝ ╚══════╝╚══════╝
13+
14+
This project is part of the PyFunceble project and infrastructure.
15+
16+
Provides the CLI entrypoints.
17+
18+
Author:
19+
Nissar Chababy, @funilrys, contactTATAfunilrysTODTODcom
20+
21+
Special thanks:
22+
https://pyfunceble.github.io/special-thanks.html
23+
24+
Contributors:
25+
https://pyfunceble.github.io/contributors.html
26+
27+
Project link:
28+
https://github.com/funilrys/PyFunceble
29+
30+
Project documentation:
31+
https://pyfunceble.readthedocs.io/en/dev/
32+
33+
Project homepage:
34+
https://pyfunceble.github.io/
35+
36+
License:
37+
::
38+
39+
40+
MIT License
41+
42+
Copyright (c) 2019, 2020 PyFunceble
43+
Copyright (c) 2017, 2018, 2019, 2020 Nissar Chababy
44+
45+
Permission is hereby granted, free of charge, to any person obtaining a copy
46+
of this software and associated documentation files (the "Software"), to deal
47+
in the Software without restriction, including without limitation the rights
48+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
49+
copies of the Software, and to permit persons to whom the Software is
50+
furnished to do so, subject to the following conditions:
51+
52+
The above copyright notice and this permission notice shall be included in all
53+
copies or substantial portions of the Software.
54+
55+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
56+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
57+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
58+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
59+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
60+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
61+
SOFTWARE.
62+
"""
63+
64+
import argparse
65+
66+
from colorama import Fore, Style
67+
68+
from .core import AdBlock2Hosts, AdBlock2Plain
69+
70+
71+
def adblock2plain():
72+
"""
73+
Provides the CLI entrypoint of the adblock2plain tool.
74+
"""
75+
76+
if __name__ == "adblock_decoder.cli":
77+
parser = argparse.ArgumentParser(
78+
description="An AdBlock2plain (text) converter.",
79+
epilog=f"Crafted with {Fore.RED}{Style.BRIGHT}{Style.RESET_ALL} "
80+
f"by {Fore.YELLOW}{Style.BRIGHT}Nissar Chababy (Funilrys){Style.RESET_ALL}!",
81+
add_help=True,
82+
)
83+
84+
parser.add_argument(
85+
"input_file",
86+
type=argparse.FileType("r"),
87+
help="The input file to work with.",
88+
)
89+
90+
parser.add_argument(
91+
"--aggressive",
92+
action="store_true",
93+
help="[USE AT YOUR OWN RISK AS IT IS EXPERIMENTAL] Activates the extraction "
94+
"of everything regardless of the interpretation of AdBlock/UBlock.",
95+
)
96+
97+
parser.add_argument(
98+
"-o", "--output", type=argparse.FileType("w"), help="The file to write to."
99+
)
100+
101+
args = parser.parse_args()
102+
103+
AdBlock2Plain(
104+
args.input_file, args.aggressive, output=args.output
105+
).process_conversion()
106+
107+
108+
def adblock2host():
109+
"""
110+
Provides the CLI entrypoint of the adblock2hosts tool.
111+
"""
112+
113+
if __name__ == "adblock_decoder.cli":
114+
parser = argparse.ArgumentParser(
115+
description="An AdBlock2hosts converter.",
116+
epilog=f"Crafted with {Fore.RED}{Style.BRIGHT}{Style.RESET_ALL} "
117+
f"by {Fore.YELLOW}{Style.BRIGHT}Nissar Chababy (Funilrys){Style.RESET_ALL}!",
118+
add_help=True,
119+
)
120+
121+
parser.add_argument(
122+
"input_file",
123+
type=argparse.FileType("r"),
124+
help="The input file to work with.",
125+
)
126+
127+
parser.add_argument(
128+
"--aggressive",
129+
action="store_true",
130+
help="[USE AT YOUR OWN RISK AS IT IS EXPERIMENTAL] Activates the extraction "
131+
"of everything regardless of the interpretation of AdBlock/UBlock.",
132+
)
133+
134+
parser.add_argument(
135+
"--ip",
136+
type=str,
137+
help="Sets the IP to use while generating the hosts file.",
138+
default="0.0.0.0",
139+
)
140+
141+
parser.add_argument(
142+
"-o", "--output", type=argparse.FileType("w"), help="The file to write to."
143+
)
144+
145+
args = parser.parse_args()
146+
147+
AdBlock2Hosts(
148+
args.input_file, args.aggressive, output=args.output, ip=args.ip
149+
).process_conversion()

adblock_decoder/core/__init__.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
"""
2+
The tool to check the availability or syntax of domains, IPv4, IPv6 or URL.
3+
4+
::
5+
6+
7+
██████╗ ██╗ ██╗███████╗██╗ ██╗███╗ ██╗ ██████╗███████╗██████╗ ██╗ ███████╗
8+
██╔══██╗╚██╗ ██╔╝██╔════╝██║ ██║████╗ ██║██╔════╝██╔════╝██╔══██╗██║ ██╔════╝
9+
██████╔╝ ╚████╔╝ █████╗ ██║ ██║██╔██╗ ██║██║ █████╗ ██████╔╝██║ █████╗
10+
██╔═══╝ ╚██╔╝ ██╔══╝ ██║ ██║██║╚██╗██║██║ ██╔══╝ ██╔══██╗██║ ██╔══╝
11+
██║ ██║ ██║ ╚██████╔╝██║ ╚████║╚██████╗███████╗██████╔╝███████╗███████╗
12+
╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝ ╚═════╝╚══════╝╚═════╝ ╚══════╝╚══════╝
13+
14+
This project is part of the PyFunceble project and infrastructure.
15+
16+
Provides the different core.
17+
18+
Author:
19+
Nissar Chababy, @funilrys, contactTATAfunilrysTODTODcom
20+
21+
Special thanks:
22+
https://pyfunceble.github.io/special-thanks.html
23+
24+
Contributors:
25+
https://pyfunceble.github.io/contributors.html
26+
27+
Project link:
28+
https://github.com/funilrys/PyFunceble
29+
30+
Project documentation:
31+
https://pyfunceble.readthedocs.io/en/dev/
32+
33+
Project homepage:
34+
https://pyfunceble.github.io/
35+
36+
License:
37+
::
38+
39+
40+
MIT License
41+
42+
Copyright (c) 2019, 2020 PyFunceble
43+
Copyright (c) 2017, 2018, 2019, 2020 Nissar Chababy
44+
45+
Permission is hereby granted, free of charge, to any person obtaining a copy
46+
of this software and associated documentation files (the "Software"), to deal
47+
in the Software without restriction, including without limitation the rights
48+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
49+
copies of the Software, and to permit persons to whom the Software is
50+
furnished to do so, subject to the following conditions:
51+
52+
The above copyright notice and this permission notice shall be included in all
53+
copies or substantial portions of the Software.
54+
55+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
56+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
57+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
58+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
59+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
60+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
61+
SOFTWARE.
62+
"""
63+
64+
from .adblock2hosts import AdBlock2Hosts
65+
from .adblock2plain import AdBlock2Plain

0 commit comments

Comments
 (0)