-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathm3uToCommunity.py
36 lines (31 loc) · 961 Bytes
/
m3uToCommunity.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
import re, json, os
m3uLi = []
for file in os.listdir('.'):
if file.split('.')[-1] == 'm3u':
m3uLi.append(open(file).read())
regex = '#EXTINF:.*?(?:tvg-logo="([^"]+)")?,([^\n]+).*\n(.+)'
out = {
"movies_list": []
}
for m3u in m3uLi:
for logo, name, url in re.findall(regex, m3u):
quality = 'HD' if 'hd' in name.lower() else 'SD'
link = {
"url": url,
"quality": quality
}
for n, channel in enumerate(out["movies_list"]):
if channel['title'] == name: # esiste già
out["movies_list"][n]["links"].append(link)
break
else:
dictChannel = {
"title": name,
"year": "",
"thumbnail": logo,
"links": [
link
]
}
out["movies_list"].append(dictChannel)
json.dump(out, open('canali.json', 'w'), indent=4)