Skip to content

Commit

Permalink
feat:two result(#581)
Browse files Browse the repository at this point in the history
  • Loading branch information
Guovin committed Nov 26, 2024
1 parent 6f051aa commit 5ead198
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 14 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,9 @@ docker run -v /etc/docker/config:/iptv_lite/config -v /etc/docker/output:/iptv_l
3. 更新结果:

- 接口地址:ip:8000
- 接口详情:ip:8000/result
- M3u 接口:ip:8000/m3u
- Txt 接口:ip:8000/txt
- 接口内容:ip:8000/content
- 测速日志:ip:8000/log

## 🗓️ 更新日志
Expand Down
4 changes: 3 additions & 1 deletion README_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,9 @@ docker run -v /etc/docker/config:/iptv_lite/config -v /etc/docker/output:/iptv_l
3. Update results:

- API address: ip:8000
- API details: ip:8000/result
- M3u api:ip:8000/m3u
- Txt api:ip:8000/txt
- API content: ip:8000/content
- Speed test log: ip:8000/log

## 🗓️ Changelog
Expand Down
20 changes: 16 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,19 @@ def show_index():
return get_result_file_content()


@app.route("/result")
@app.route("/txt")
def show_result():
return get_result_file_content(show_result=True)
return get_result_file_content(file_type="txt")


@app.route("/m3u")
def show_result():
return get_result_file_content(file_type="m3u")


@app.route("/content")
def show_result():
return get_result_file_content(show_content=True)


@app.route("/log")
Expand Down Expand Up @@ -257,8 +267,10 @@ def run_service():
try:
if not os.environ.get("GITHUB_ACTIONS"):
ip_address = get_ip_address()
print(f"📄 Result detail: {ip_address}/result")
print(f"📄 Log detail: {ip_address}/log")
print(f"📄 Result content: {ip_address}/content")
print(f"📄 Log content: {ip_address}/log")
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=8000)
except Exception as e:
Expand Down
23 changes: 15 additions & 8 deletions utils/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,18 +410,25 @@ def convert_to_m3u():
print(f"✅ Result m3u file generated at: {m3u_file_path}")


def get_result_file_content(show_result=False):
def get_result_file_content(show_content=False, file_type=None):
"""
Get the content of the result file
"""
user_final_file = resource_path(config.final_file)
if os.path.exists(user_final_file):
if config.open_m3u_result:
user_final_file = os.path.splitext(user_final_file)[0] + ".m3u"
if show_result == False:
return send_file(user_final_file, as_attachment=True)
with open(user_final_file, "r", encoding="utf-8") as file:
content = file.read()
result_file = (
os.path.splitext(user_final_file)[0] + f".{file_type}"
if file_type
else user_final_file
)
if os.path.exists(result_file):
if file_type == "txt" or not config.open_m3u_result:
with open(result_file, "r", encoding="utf-8") as file:
content = file.read()
elif config.open_m3u_result:
if not file_type:
result_file = os.path.splitext(user_final_file)[0] + ".m3u"
if show_content == False:
return send_file(result_file, as_attachment=True)
else:
content = constants.waiting_tip
return render_template_string(
Expand Down

0 comments on commit 5ead198

Please sign in to comment.