forked from ozankaraali/QiTV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.py
198 lines (172 loc) · 8.27 KB
/
options.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
from PySide6.QtWidgets import (
QFileDialog,
QPushButton,
QLineEdit,
QDialog,
QLabel,
QFormLayout,
QRadioButton,
QButtonGroup,
QComboBox,
)
class OptionsDialog(QDialog):
def __init__(self, parent=None):
super().__init__(parent)
self.setWindowTitle("Options")
self.layout = QFormLayout(self)
self.config = parent.config
self.selected_provider_index = self.config.get("selected", 0)
self.create_options_ui()
self.load_providers()
def create_options_ui(self):
self.provider_label = QLabel("Select Provider:", self)
self.provider_combo = QComboBox(self)
self.provider_combo.currentIndexChanged.connect(self.load_provider_settings)
self.layout.addRow(self.provider_label, self.provider_combo)
self.add_provider_button = QPushButton("Add Provider", self)
self.add_provider_button.clicked.connect(self.add_new_provider)
self.layout.addWidget(self.add_provider_button)
self.remove_provider_button = QPushButton("Remove Provider", self)
self.remove_provider_button.clicked.connect(self.remove_provider)
self.layout.addWidget(self.remove_provider_button)
self.create_stream_type_ui()
self.url_label = QLabel("Server URL:", self)
self.url_input = QLineEdit(self)
self.layout.addRow(self.url_label, self.url_input)
self.mac_label = QLabel("MAC Address (STB only):", self)
self.mac_input = QLineEdit(self)
self.layout.addRow(self.mac_label, self.mac_input)
self.file_button = QPushButton("Load File", self)
self.file_button.clicked.connect(self.load_file)
self.layout.addWidget(self.file_button)
self.username_label = QLabel("Username:", self)
self.username_input = QLineEdit(self)
self.layout.addRow(self.username_label, self.username_input)
self.password_label = QLabel("Password:", self)
self.password_input = QLineEdit(self)
self.layout.addRow(self.password_label, self.password_input)
self.verify_button = QPushButton("Verify Provider", self)
self.verify_button.clicked.connect(self.verify_provider)
self.layout.addWidget(self.verify_button)
self.verify_result = QLabel("", self)
self.layout.addWidget(self.verify_result)
self.save_button = QPushButton("Save", self)
self.save_button.clicked.connect(self.save_settings)
self.layout.addWidget(self.save_button)
def create_stream_type_ui(self):
self.type_label = QLabel("Stream Type:", self)
self.type_group = QButtonGroup(self)
self.type_STB = QRadioButton("STB", self)
self.type_M3UPLAYLIST = QRadioButton("M3U Playlist", self)
self.type_M3USTREAM = QRadioButton("M3U Stream", self)
self.type_XTREAM = QRadioButton("Xtream", self)
self.type_group.addButton(self.type_STB)
self.type_group.addButton(self.type_M3UPLAYLIST)
self.type_group.addButton(self.type_M3USTREAM)
self.type_group.addButton(self.type_XTREAM)
self.type_STB.toggled.connect(self.update_inputs)
self.type_M3UPLAYLIST.toggled.connect(self.update_inputs)
self.type_M3USTREAM.toggled.connect(self.update_inputs)
self.type_XTREAM.toggled.connect(self.update_inputs)
self.layout.addRow(self.type_label)
self.layout.addRow(self.type_STB)
self.layout.addRow(self.type_M3UPLAYLIST)
self.layout.addRow(self.type_M3USTREAM)
self.layout.addRow(self.type_XTREAM)
def load_providers(self):
self.provider_combo.blockSignals(True)
self.provider_combo.clear()
for i, provider in enumerate(self.config["data"]):
# can we get the first couple ... last couple of characters of the url?
prov = (
provider["url"][:30] + "..." + provider["url"][-15:]
if len(provider["url"]) > 45
else provider["url"]
)
self.provider_combo.addItem(f"{i + 1}: {prov}", userData=provider)
self.provider_combo.blockSignals(False)
self.provider_combo.setCurrentIndex(self.selected_provider_index)
self.load_provider_settings(self.selected_provider_index)
def load_provider_settings(self, index):
if index == -1 or index >= len(self.config["data"]):
return
self.selected_provider_index = index
self.selected_provider = self.config["data"][index]
self.url_input.setText(self.selected_provider.get("url", ""))
self.mac_input.setText(self.selected_provider.get("mac", ""))
self.username_input.setText(self.selected_provider.get("username", ""))
self.password_input.setText(self.selected_provider.get("password", ""))
self.update_radio_buttons()
self.update_inputs()
def update_radio_buttons(self):
provider_type = self.selected_provider.get("type", "")
self.type_STB.setChecked(provider_type == "STB")
self.type_M3UPLAYLIST.setChecked(provider_type == "M3UPLAYLIST")
self.type_M3USTREAM.setChecked(provider_type == "M3USTREAM")
self.type_XTREAM.setChecked(provider_type == "XTREAM")
def update_inputs(self):
self.mac_label.setVisible(self.type_STB.isChecked())
self.mac_input.setVisible(self.type_STB.isChecked())
self.file_button.setVisible(
self.type_M3UPLAYLIST.isChecked() or self.type_M3USTREAM.isChecked()
)
self.url_input.setEnabled(True)
self.username_label.setVisible(self.type_XTREAM.isChecked())
self.username_input.setVisible(self.type_XTREAM.isChecked())
self.password_label.setVisible(self.type_XTREAM.isChecked())
self.password_input.setVisible(self.type_XTREAM.isChecked())
def add_new_provider(self):
new_provider = {"type": "STB", "url": "", "mac": ""}
self.config["data"].append(new_provider)
self.load_providers()
self.provider_combo.setCurrentIndex(len(self.config["data"]) - 1)
def remove_provider(self):
if len(self.config["data"]) == 1:
return
del self.config["data"][self.provider_combo.currentIndex()]
self.load_providers()
self.provider_combo.setCurrentIndex(
min(self.selected_provider_index, len(self.config["data"]) - 1)
)
def save_settings(self):
if self.selected_provider:
self.selected_provider["url"] = self.url_input.text()
if self.type_STB.isChecked():
self.selected_provider["type"] = "STB"
self.selected_provider["mac"] = self.mac_input.text()
elif self.type_M3UPLAYLIST.isChecked():
self.selected_provider["type"] = "M3UPLAYLIST"
elif self.type_M3USTREAM.isChecked():
self.selected_provider["type"] = "M3USTREAM"
elif self.type_XTREAM.isChecked():
self.selected_provider["type"] = "XTREAM"
self.selected_provider["username"] = self.username_input.text()
self.selected_provider["password"] = self.password_input.text()
self.config["selected"] = self.selected_provider_index
self.parent().save_config()
self.parent().load_channels()
self.accept()
def load_file(self):
file_dialog = QFileDialog(self)
file_path, _ = file_dialog.getOpenFileName()
if file_path:
self.url_input.setText(file_path)
self.file_button.setVisible(False)
def verify_provider(self):
self.verify_result.setText("Verifying...")
self.verify_result.repaint()
result = False
if self.type_STB.isChecked():
result = self.parent().do_handshake(
self.url_input.text(), self.mac_input.text(), load=False
)
elif self.type_M3UPLAYLIST.isChecked() or self.type_M3USTREAM.isChecked():
result = self.parent().verify_url(self.url_input.text())
elif self.type_XTREAM.isChecked():
result = self.parent().verify_url(self.url_input.text())
self.verify_result.setText(
"Provider verified successfully."
if result
else "Failed to verify provider."
)
self.verify_result.setStyleSheet("color: green;" if result else "color: red;")