Skip to content

Commit

Permalink
Merge pull request #710 from Guovin/dev
Browse files Browse the repository at this point in the history
feat:app_port config
  • Loading branch information
Guovin authored Dec 19, 2024
2 parents 19c1105 + 9f59ba2 commit ba7794d
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ https://cdn.jsdelivr.net/gh/Guovin/iptv-api@gd/source.json
| open_url_info | 开启显示接口说明信息,用于控制是否显示分辨率、接口协议类型等信息,为$符号后的内容,播放软件使用该信息对接口进行描述 | True |
| open_use_cache | 开启使用本地缓存数据,适用于查询请求失败场景(仅针对酒店源与组播源) | True |
| open_use_old_result | 开启使用历史更新结果(包含模板与结果文件的接口),合并至本次更新中 | True |
| app_port | 页面服务端口,用于控制页面服务的端口号 | 8000 |
| final_file | 生成结果文件路径 | output/result.txt |
| hotel_num | 结果中偏好的酒店源接口数量 | 4 |
| hotel_page_num | 酒店地区获取分页数量 | 1 |
Expand Down
1 change: 1 addition & 0 deletions README_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ https://cdn.jsdelivr.net/gh/Guovin/iptv-api@gd/source.json
| open_url_info | Enable display of API description information, used to control whether to show resolution, API protocol type, etc., the content after the $ symbol, playback software uses this information to describe the API | True |
| open_use_cache | Enable the use of local cache data, applicable to the query request failure scenario (only for hotel sources and multicast sources) | True |
| open_use_old_result | Enable the use of historical update results (including the interface for template and result files) and merge them into the current update | True |
| app_port | Page service port, used to control the port number of the page service | 8000 |
| final_file | Generated result file path | output/result.txt |
| hotel_num | The number of preferred hotel source interfaces in the results | 4 |
| hotel_page_num | Number of pages to retrieve for hotel regions | 1 |
Expand Down
2 changes: 2 additions & 0 deletions config/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ open_url_info = True
open_use_cache = True
# 开启使用历史更新结果(包含模板与结果文件的接口),合并至本次更新中; 可选值: True, False | Enable to use historical update results (including interfaces of templates and result files), merged into this update; Optional values: True, False
open_use_old_result = True
# 页面服务端口,用于控制页面服务的端口号; 默认值: 8000 | Page service port, used to control the port number of the page service; Default value: 8000
app_port = 8000
# 生成结果文件路径; 默认值: output/result.txt | Generate result file path; Default value: output/result.txt
final_file = output/result.txt
# 结果中偏好的酒店源接口数量 | Preferred number of hotel source interfaces in the result
Expand Down
1 change: 1 addition & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
| open_url_info | 开启显示接口说明信息,用于控制是否显示分辨率、接口协议类型等信息,为$符号后的内容,播放软件使用该信息对接口进行描述 | True |
| open_use_cache | 开启使用本地缓存数据,适用于查询请求失败场景(仅针对酒店源与组播源) | True |
| open_use_old_result | 开启使用历史更新结果(包含模板与结果文件的接口),合并至本次更新中 | True |
| app_port | 页面服务端口,用于控制页面服务的端口号 | 8000 |
| final_file | 生成结果文件路径 | output/result.txt |
| hotel_num | 结果中偏好的酒店源接口数量 | 4 |
| hotel_page_num | 酒店地区获取分页数量 | 1 |
Expand Down
1 change: 1 addition & 0 deletions docs/config_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
| open_url_info | Enable display of API description information, used to control whether to show resolution, API protocol type, etc., the content after the $ symbol, playback software uses this information to describe the API | True |
| open_use_cache | Enable the use of local cache data, applicable to the query request failure scenario (only for hotel sources and multicast sources) | True |
| open_use_old_result | Enable the use of historical update results (including the interface for template and result files) and merge them into the current update | True |
| app_port | Page service port, used to control the port number of the page service | 8000 |
| final_file | Generated result file path | output/result.txt |
| hotel_num | The number of preferred hotel source interfaces in the results | 4 |
| hotel_page_num | Number of pages to retrieve for hotel regions | 1 |
Expand Down
3 changes: 2 additions & 1 deletion service/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
sys.path.append(os.path.dirname(sys.path[0]))
from flask import Flask, render_template_string
from utils.tools import get_result_file_content, get_ip_address, resource_path
from utils.config import config
import utils.constants as constants

app = Flask(__name__)
Expand Down Expand Up @@ -52,7 +53,7 @@ def run_service():
print(f"🚀 M3u api: {ip_address}/m3u")
print(f"🚀 Txt api: {ip_address}/txt")
print(f"✅ You can use this url to watch IPTV 📺: {ip_address}")
app.run(host="0.0.0.0", port=os.environ.get("APP_PORT") or 8000)
app.run(host="0.0.0.0", port=config.app_port)
except Exception as e:
print(f"❌ Service start failed: {e}")

Expand Down
13 changes: 13 additions & 0 deletions tkinter_ui/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ def init_ui(self, root):
)
self.open_service_checkbutton.pack(side=tk.LEFT, padx=4, pady=8)

self.app_port_label = tk.Label(
frame_default_open_update_column2, text="端口:", width=3
)
self.app_port_label.pack(side=tk.LEFT, padx=4, pady=8)
self.app_port_entry = tk.Entry(frame_default_open_update_column2, width=8)
self.app_port_entry.pack(side=tk.LEFT, padx=4, pady=8)
self.app_port_entry.insert(0, config.app_port)
self.app_port_entry.bind("<KeyRelease>", self.update_app_port)

frame_default_open_cache = tk.Frame(root)
frame_default_open_cache.pack(fill=tk.X)
frame_default_open_cache_column1 = tk.Frame(frame_default_open_cache)
Expand Down Expand Up @@ -370,6 +379,9 @@ def update_open_update(self):
def update_open_service(self):
config.set("Settings", "open_service", str(self.open_update_var.get()))

def update_app_port(self, event):
config.set("Settings", "app_port", self.app_port_entry.get())

def update_open_use_old_result(self):
config.set(
"Settings", "open_use_old_result", str(self.open_use_old_result_var.get())
Expand Down Expand Up @@ -452,6 +464,7 @@ def change_entry_state(self, state):
for entry in [
"open_update_checkbutton",
"open_service_checkbutton",
"app_port_entry",
"open_use_old_result_checkbutton",
"open_use_cache_checkbutton",
"open_request_checkbutton",
Expand Down
4 changes: 4 additions & 0 deletions utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ def online_search_page_num(self):
def open_empty_category(self):
return self.config.getboolean("Settings", "open_empty_category", fallback=True)

@property
def app_port(self):
return os.environ.get("APP_PORT") or self.config.getint("Settings", "app_port", fallback=8000)

def load(self):
"""
Load the config
Expand Down
9 changes: 5 additions & 4 deletions utils/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,14 +336,15 @@ def get_ip_address():
Get the IP address
"""
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
ip = "127.0.0.1"
try:
s.connect(("10.255.255.255", 1))
IP = s.getsockname()[0]
except Exception:
IP = "127.0.0.1"
ip = s.getsockname()[0]
except:
ip = "127.0.0.1"
finally:
s.close()
return f"http://{IP}:{os.environ.get("APP_PORT") or 8000}"
return f"http://{ip}:{config.app_port}"


def convert_to_m3u():
Expand Down

0 comments on commit ba7794d

Please sign in to comment.