-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
105 lines (82 loc) · 3.08 KB
/
main.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
#!/usr/bin/env python
from select import select
import sys
import PySimpleGUI as sg
import m3u_helper
from threading import Thread
from concurrent.futures import ThreadPoolExecutor
POOL_SIZE = 50
class Tree_Data(sg.TreeData):
def __init__(self):
super().__init__()
def move(self, key1, key2):
if key1 == '':
return False
node = self.tree_dict[key1]
parent1_node = self.tree_dict[node.parent]
parent1_node.children.remove(node)
parent2_node = self.tree_dict[key2]
parent2_node.children.append(node)
return True
def load(self,file):
LST_M3U_ITEMS = m3u_helper.parse_m3u(file)
def sub(args):
try:
gname= args[0]
category= args[1]
self.Insert('', gname, gname,values=[len(category)])
for l in category:
self.Insert(gname, l[4], l[4],values=[l[5]])
except:
pass
with ThreadPoolExecutor(max_workers=POOL_SIZE) as executor:
args = ((k,category)for k,category in LST_M3U_ITEMS.items())
args = list(args)
executor.map(sub,args)
def delete(self, key):
if key == '':
return False
node = self.tree_dict[key]
self.tree_dict[node.parent].children.remove(node)
return True
def export(self,file):
selected = ['#EXTM3U']
for cat in self.tree_dict[''].children:
if len(self.tree_dict[cat.key].children)>0:
for s in self.tree_dict[cat.key].children:
val = s.values[0]
if not isinstance(val,int):
selected.append(val)
with open(f"{file}.m3u", "w") as outfile:
outfile.write("\n".join(selected))
treedata = Tree_Data()
starting_path = sg.popup_get_file('File to load')
if not starting_path:
sys.exit(0)
treedata.load(starting_path)
layout = [[sg.Text('Browse channels')],
[sg.Tree(data=treedata,
headings=['Size', ],
auto_size_columns=True,
select_mode=sg.TABLE_SELECT_MODE_EXTENDED,
num_rows=20,
col0_width=40,
key='-TREE-',
show_expanded=False,
enable_events=True,
expand_x=True,
expand_y=True,
),],
[sg.Button('Delete'),sg.Button('Export'), sg.Button('Cancel')]]
window = sg.Window('M3U Editor', layout, resizable=True, finalize=True)
while True: # Event Loop
event, values = window.read()
if event in (sg.WIN_CLOSED, 'Cancel'):
break
if event in ('Export'):
save = sg.popup_get_text('Save file')
treedata.export(save)
if event in ('Delete'):
with ThreadPoolExecutor(max_workers=POOL_SIZE) as executor:
executor.map(lambda n:treedata.delete(n),values['-TREE-'])
window['-TREE-'].Update(values=treedata)