forked from kaigedong/cnm3u
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilter_m3u.py
58 lines (46 loc) · 1.28 KB
/
filter_m3u.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
from collections import OrderedDict
whiteList = OrderedDict()
blackList = {}
# 读取白名单
with open("whitelist.txt", 'r') as fin:
for aline in fin:
aline = aline.strip()
if aline != "":
whiteList[aline] = []
# 读取黑名单
with open("blacklist.txt", "r") as fin:
for aline in fin:
aline = aline.strip()
if aline != "":
blackList[aline] = 1
def isInWhite(aStr, nextStr):
for aItem in whiteList:
if aItem in aStr:
whiteList[aItem].append([aStr, nextStr])
return True
return False
def printWhite():
for aWhite in whiteList:
for aItem in whiteList[aWhite]:
print(aItem[0])
print(aItem[1])
def isInBlack(aStr):
for aItem in blackList:
if aItem in aStr:
return True
return False
with open("cn.m3u", 'r') as fin:
allLines = fin.readlines()
fileLength = len(allLines)
index = 0
while index < fileLength-1:
aLine = allLines[index].strip()
nextLine = allLines[index+1].strip()
if aLine.startswith("#"):
if isInBlack(aLine):
pass
elif isInWhite(aLine, nextLine):
pass
# 避免有多个注释行
index += 1
printWhite()