forked from Guovin/iptv-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
multicast.py
154 lines (136 loc) · 5.41 KB
/
multicast.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
153
154
import tkinter as tk
from tkinter import ttk
from utils.config import config, resource_path
from select_combobox import SelectCombobox
import os
class MulticastUI:
def init_ui(self, root):
"""
Init multicast UI
"""
frame_multicast_multicast = tk.Frame(root)
frame_multicast_multicast.pack(fill=tk.X)
self.open_multicast_label = tk.Label(
frame_multicast_multicast, text="开启组播源:", width=9
)
self.open_multicast_label.pack(side=tk.LEFT, padx=4, pady=8)
self.open_multicast_var = tk.BooleanVar(
value=config.getboolean("Settings", "open_multicast", fallback=True)
)
self.open_multicast_checkbutton = ttk.Checkbutton(
frame_multicast_multicast,
variable=self.open_multicast_var,
onvalue=True,
offvalue=False,
command=self.update_open_multicast,
)
self.open_multicast_checkbutton.pack(side=tk.LEFT, padx=4, pady=8)
frame_multicast_mode = tk.Frame(root)
frame_multicast_mode.pack(fill=tk.X)
self.open_multicast_mode_label = tk.Label(
frame_multicast_mode, text="工作模式:", width=9
)
self.open_multicast_mode_label.pack(side=tk.LEFT, padx=4, pady=8)
self.open_multicast_tonkiang_var = tk.BooleanVar(
value=config.getboolean(
"Settings", "open_multicast_tonkiang", fallback=True
)
)
self.open_multicast_tonkiang_checkbutton = ttk.Checkbutton(
frame_multicast_mode,
variable=self.open_multicast_tonkiang_var,
onvalue=True,
offvalue=False,
command=self.update_open_multicast_tonkiang,
text="Tonkiang",
)
self.open_multicast_tonkiang_checkbutton.pack(side=tk.LEFT, padx=4, pady=8)
self.open_multicast_fofa_var = tk.BooleanVar(
value=config.getboolean("Settings", "open_multicast_fofa", fallback=True)
)
self.open_multicast_fofa_checkbutton = ttk.Checkbutton(
frame_multicast_mode,
variable=self.open_multicast_fofa_var,
onvalue=True,
offvalue=False,
command=self.update_open_multicast_fofa,
text="FOFA",
)
self.open_multicast_fofa_checkbutton.pack(side=tk.LEFT, padx=4, pady=8)
frame_multicast_region_list = tk.Frame(root)
frame_multicast_region_list.pack(fill=tk.X)
frame_multicast_region_list = tk.Frame(root)
frame_multicast_region_list.pack(fill=tk.X)
self.region_list_label = tk.Label(
frame_multicast_region_list, text="组播地区:", width=9
)
self.region_list_label.pack(side=tk.LEFT, padx=4, pady=8)
rtp_path = resource_path("config/rtp")
regions = list(
{"全部"}.union(
filename.rsplit(".", 1)[0].split("_", 1)[0]
for filename in os.listdir(rtp_path)
if filename.endswith(".txt") and "_" in filename
)
)
if "全部" in regions:
regions.remove("全部")
regions.insert(0, "全部")
region_selected_values = [
value.strip()
for value in config.get(
"Settings", "multicast_region_list", fallback="全部"
).split(",")
if value.strip()
]
self.region_list_combo = SelectCombobox(
frame_multicast_region_list,
values=regions,
selected_values=region_selected_values,
height=10,
command=self.update_region_list,
)
self.region_list_combo.pack(
side=tk.LEFT, padx=4, pady=8, expand=True, fill=tk.BOTH
)
frame_multicast_page_num = tk.Frame(root)
frame_multicast_page_num.pack(fill=tk.X)
self.page_num_label = tk.Label(
frame_multicast_page_num, text="获取页数:", width=9
)
self.page_num_label.pack(side=tk.LEFT, padx=4, pady=8)
self.page_num_entry = tk.Entry(frame_multicast_page_num)
self.page_num_entry.pack(side=tk.LEFT, padx=4, pady=8)
self.page_num_entry.insert(
0, config.getint("Settings", "multicast_page_num", fallback=3)
)
self.page_num_entry.bind("<KeyRelease>", self.update_page_num)
def update_open_multicast(self):
config.set("Settings", "open_multicast", str(self.open_multicast_var.get()))
def update_open_multicast_tonkiang(self):
config.set(
"Settings",
"open_multicast_tonkiang",
str(self.open_multicast_tonkiang_var.get()),
)
def update_open_multicast_fofa(self):
config.set(
"Settings", "open_multicast_fofa", str(self.open_multicast_fofa_var.get())
)
def update_region_list(self, event):
config.set(
"Settings",
"multicast_region_list",
",".join(self.region_list_combo.selected_values),
)
def update_page_num(self, event):
config.set("Settings", "multicast_page_num", self.page_num_entry.get())
def change_entry_state(self, state):
for entry in [
"open_multicast_checkbutton",
"open_multicast_tonkiang_checkbutton",
"open_multicast_fofa_checkbutton",
"region_list_combo",
"page_num_entry",
]:
getattr(self, entry).config(state=state)