-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.py
152 lines (115 loc) · 5.95 KB
/
start.py
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import os
import urllib.request
urls = [
"https://raw.githubusercontent.com/AdguardTeam/AdguardFilters/master/BaseFilter/sections/adservers.txt",
"https://raw.githubusercontent.com/AdguardTeam/AdguardFilters/master/BaseFilter/sections/adservers_firstparty.txt",
"https://raw.githubusercontent.com/AdguardTeam/AdguardFilters/master/MobileFilter/sections/adservers.txt",
"https://raw.githubusercontent.com/AdguardTeam/AdguardFilters/master/MobileFilter/sections/antiadblock.txt",
"https://raw.githubusercontent.com/AdguardTeam/AdguardFilters/master/MobileFilter/sections/general_url.txt",
"https://raw.githubusercontent.com/AdguardTeam/AdguardFilters/master/SpywareFilter/sections/mobile.txt",
"https://raw.githubusercontent.com/AdguardTeam/AdguardFilters/master/SpywareFilter/sections/tracking_servers.txt",
"https://raw.githubusercontent.com/AdguardTeam/AdguardFilters/master/SpywareFilter/sections/tracking_servers_firstparty.txt"
]
file_name = "AdsBlockList_user_edit.txt"
script_directory = os.path.dirname(os.path.abspath(__file__))
file_path = os.path.join(script_directory, file_name)
def clean_line(line):
if line.startswith('-'):
line = line[1:].lstrip()
symbols = ['!', '$', '#', '[', ']', '&', '%']
cut_index = len(line)
for symbol in symbols:
index = line.find(symbol)
if index != -1:
cut_index = min(cut_index, index)
cleaned_line = line[:cut_index].strip()
cleaned_line = cleaned_line.replace('|', '').replace('^', '').replace('*', '').replace('@', '')
return cleaned_line
def fetch_and_clean_url(url):
try:
response = urllib.request.urlopen(url)
content = response.read().decode('utf-8').splitlines()
cleaned_lines = set()
for line in content:
cleaned_line = clean_line(line)
if cleaned_line:
cleaned_lines.add(cleaned_line)
return cleaned_lines
except Exception as e:
print("")
print(f"An error occurred while processing {url}: {e}")
return set()
combined_list = set()
for url in urls:
combined_list.update(fetch_and_clean_url(url))
def read_list_from_file(filename):
try:
with open(filename, 'r') as file:
return set(line.strip() for line in file if line.strip())
except Exception as e:
print("")
print(f"An error occurred while reading {filename}: {e}")
return set()
default_http = [
'/ads', '.ads.', '-ads.', '.ad.', '/ad.', 'advert', '.gstatic.com', '.admob.com', '.analytics.localytics.com',
'.greystripe.com', 'inmobi.com', 'admax.nexage.com', 'my.mobfox.com', '.plus1.wapstart.ru', '.madnet.ru',
'.inmobi.com', '.mp.mydas.mobi', 'millennialmedia.com', '.g.doubleclick.net', '.appsdt.com', 'run.admost.com',
'mobile.admost.com', 'amazon-adsystem.com', '.appnext.com', '.flurry.com', 'googlesyndication.com', 'google.com/dfp',
'inmobicdn.net', 'moatads', '.mopub.com', 'unityads.unity3d.com', 'adc3-launch', 'adcolony.com',
'mobile-static.adsafeprotected', 'applovin.com', 'applvn.com', 'appnext.hs', 'live.chartboost.com',
'www.dummy.com', '.api.vungle.com', 'pubnative.net', 'supersonicads.com', 'info.static.startappservice.com',
'init.startappservice.com', 'req.startappservice.com', 'imp.startappservice.com', 'sb.scorecardresearch.com',
'crashlytics.com', 'udm.scorecardresearch.com', 'adz.wattpad.com', 'ad.api.kaffnet.com', 'dsp.batmobil.net',
'61.145.124.238', 'alta.eqmob.com', 'graph.facebook.', 't.appsflyer.com', 'net.rayjump.com', '.yandex.net',
'appodeal.com', 'amazonaws.com', '.baidu.com', '.tapas.net', '.duapps.com', 'smaato.', 'ad-mail.ru',
'yandexadexchange.', 'yandex.com', 'tapjoyads.com', 'tapjoy.com'
]
default_strings = [
'com.google.android.gms.ads.identifier.service.START', 'ads.mopub.com', 'doubleclick.net',
'googleadservices.com', 'googlesyndication.com'
]
include_default_http = input("Do you want to include LuckyPatcher defaults? (y/n): ").strip().lower()
add_additionals = input("Do you want to include additional_urls.txt file contents? (y/n): ").strip().lower()
add_facebook = input("Do you want to block facebook.com? (y/n): ").strip().lower()
duplicate_http_to_strings = input("Do you want to duplicate everything from [http] into [ALL_STRINGS])? (y/n): ").strip().lower()
fuckfacebook = read_list_from_file('facebook_urls.txt')
additionals = read_list_from_file('additional_urls.txt')
def http_fix(file_path):
with open(file_path, 'r') as file:
content = file.read()
if 'http' in content.lower():
content = content.replace('http\n', '').replace('https\n', '') #removes http and https rows from the final file
try:
with open(file_path, 'w') as file:
file.write("[http]\n")
if include_default_http == 'y':
for line in default_http:
file.write(line + '\n')
if add_facebook == 'y':
for line in fuckfacebook:
file.write(line + '\n')
if add_additionals == 'y':
for line in additionals:
file.write(line + '\n')
for line in sorted(combined_list):
file.write(line + '\n')
file.write('\n' * 4)
file.write("[ALL_STRINGS]\n")
if include_default_http == 'y':
for line in default_strings:
file.write(line + '\n')
if add_facebook == 'y':
for line in fuckfacebook:
file.write(line + '\n')
if duplicate_http_to_strings == 'y':
for line in sorted(combined_list):
file.write(line + '\n')
print("")
print(f"File successfully saved at: {file_path}")
http_fix(file_path)
except Exception as e:
print("")
print(f"error: {e}")
print("")
print("")
input("Press Enter to exit...")