chore:service

This commit is contained in:
guorong.zheng 2024-11-27 16:57:12 +08:00
parent 899503136b
commit 654b6fc5f1
11 changed files with 108 additions and 78 deletions

View file

@ -44,8 +44,8 @@ RUN if [ "$LITE" = False ]; then apt-get install -y --no-install-recommends chro
&& apt-get clean && rm -rf /var/lib/apt/lists/*
RUN (crontab -l ; \
echo "0 22 * * * python $APP_WORKDIR/main.py scheduled_task"; \
echo "0 10 * * * python $APP_WORKDIR/main.py scheduled_task") | crontab -
echo "0 22 * * * python $APP_WORKDIR/main.py &"; \
echo "0 10 * * * python $APP_WORKDIR/main.py &") | crontab -
EXPOSE 8000

View file

@ -5,6 +5,7 @@ verify_ssl = true
[scripts]
dev = "python main.py"
service = "python service/app.py"
ui = "python tkinter_ui/tkinter_ui.py"
docker_run = "docker run -v ./config:/iptv/config -v ./output:/iptv/output -d -p 8000:8000 guovern/iptv"
docker_run_lite = "docker run -v ./config:/iptv_lite/config -v ./output:/iptv_lite/output -d -p 8000:8000 guovern/iptv:lite"

View file

@ -135,10 +135,18 @@ pip install pipenv
pipenv install --dev
```
启动更新:
```python
pipenv run dev
```
启动服务:
```python
pipenv run service
```
### 方式三GUI 软件
1. 下载[IPTV 更新软件](https://github.com/Guovin/IPTV/releases),打开软件,点击更新,即可完成更新

View file

@ -135,10 +135,18 @@ pip install pipenv
pipenv install --dev
```
Start update:
```python
pipenv run dev
```
Start service:
```python
pipenv run service
```
### Method 3: GUI Software
1. Download [IPTV update software](https://github.com/Guovin/IPTV/releases), open the software, click update to complete the update

View file

@ -182,10 +182,18 @@ pip install pipenv
pipenv install --dev
```
启动更新:
```python
pipenv run dev
```
启动服务:
```python
pipenv run service
```
### 方式三GUI 软件
1. 下载[IPTV 更新软件](https://github.com/Guovin/IPTV/releases),打开软件,点击更新,即可完成更新

View file

@ -179,10 +179,18 @@ pip install pipenv
pipenv install --dev
```
Start update:
```python
pipenv run dev
```
Start service:
```python
pipenv run service
```
### Method 3: GUI Software
1. Download [IPTV update software](https://github.com/Guovin/IPTV/releases), open the software, click update to complete the update.

View file

@ -12,6 +12,6 @@ done
service cron start
python $APP_WORKDIR/main.py
python $APP_WORKDIR/main.py &
gunicorn -w 4 -b 0.0.0.0:8000 main:app
python -m gunicorn service.app:app -b 0.0.0.0:8000 --timeout=1000

71
main.py
View file

@ -1,6 +1,6 @@
import asyncio
from utils.config import config
import utils.constants as constants
from service.app import run_service
from utils.channel import (
get_channel_items,
append_total_data,
@ -14,7 +14,6 @@ from utils.tools import (
get_pbar_remaining,
get_ip_address,
convert_to_m3u,
get_result_file_content,
process_nested_dict,
format_interval,
check_ipv6_support,
@ -30,53 +29,14 @@ from updates.online_search import get_channels_by_online_search
import os
from tqdm import tqdm
from time import time
from flask import Flask, render_template_string
import sys
import atexit
import pickle
import copy
app = Flask(__name__)
atexit.register(cleanup_logging)
@app.route("/")
def show_index():
return get_result_file_content()
@app.route("/txt")
def show_result():
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")
def show_log():
user_log_file = "output/" + (
"user_result.log" if os.path.exists("config/user_config.ini") else "result.log"
)
if os.path.exists(user_log_file):
with open(user_log_file, "r", encoding="utf-8") as file:
content = file.read()
else:
content = constants.waiting_tip
return render_template_string(
"<head><link rel='icon' href='{{ url_for('static', filename='images/favicon.ico') }}' type='image/x-icon'></head><pre>{{ content }}</pre>",
content=content,
)
class UpdateSource:
def __init__(self):
@ -237,6 +197,8 @@ class UpdateSource:
True,
url=f"{get_ip_address()}" if open_service else None,
)
if open_service:
run_service()
except asyncio.exceptions.CancelledError:
print("Update cancelled!")
@ -256,33 +218,8 @@ class UpdateSource:
self.pbar.close()
def scheduled_task():
if __name__ == "__main__":
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
update_source = UpdateSource()
loop.run_until_complete(update_source.start())
def run_service():
try:
if not os.environ.get("GITHUB_ACTIONS"):
ip_address = get_ip_address()
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:
print(f"❌ Service start failed: {e}")
if __name__ == "__main__":
if len(sys.argv) == 1 and config.open_service:
loop = asyncio.new_event_loop()
async def run_service_async():
loop.run_in_executor(None, run_service)
asyncio.run(run_service_async())
scheduled_task()

64
service/app.py Normal file
View file

@ -0,0 +1,64 @@
import os
import sys
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
import utils.constants as constants
from utils.config import config
app = Flask(__name__)
@app.route("/")
def show_index():
return get_result_file_content()
@app.route("/txt")
def show_txt():
return get_result_file_content(file_type="txt")
@app.route("/m3u")
def show_m3u():
return get_result_file_content(file_type="m3u")
@app.route("/content")
def show_content():
return get_result_file_content(show_content=True)
@app.route("/log")
def show_log():
user_log_file = "output/" + (
"user_result.log" if os.path.exists("config/user_config.ini") else "result.log"
)
if os.path.exists(user_log_file):
with open(user_log_file, "r", encoding="utf-8") as file:
content = file.read()
else:
content = constants.waiting_tip
return render_template_string(
"<head><link rel='icon' href='{{ url_for('static', filename='images/favicon.ico') }}' type='image/x-icon'></head><pre>{{ content }}</pre>",
content=content,
)
def run_service():
try:
if not os.environ.get("GITHUB_ACTIONS"):
ip_address = get_ip_address()
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:
print(f"❌ Service start failed: {e}")
if __name__ == "__main__":
run_service()

View file

@ -7,7 +7,7 @@ from tkinter import messagebox
from PIL import Image, ImageTk
from utils.config import config
from utils.tools import resource_path
from main import UpdateSource, run_service
from main import UpdateSource
import asyncio
import threading
import webbrowser
@ -33,6 +33,7 @@ if not ("TCL_LIBRARY" in environ and "TK_LIBRARY" in environ):
environ["TCL_LIBRARY"] = str(next(tk_path.glob("tcl8.*")))
environ["TK_LIBRARY"] = str(next(tk_path.glob("tk8.*")))
class TkinterUI:
def __init__(self, root):
with open(resource_path("version.json"), "r", encoding="utf-8") as f:
@ -126,15 +127,10 @@ class TkinterUI:
def on_run_update(self):
loop = asyncio.new_event_loop()
async def run_service_async():
loop.run_in_executor(None, run_service)
def run_loop():
asyncio.set_event_loop(loop)
loop.run_until_complete(self.run_update())
if config.open_service:
asyncio.run(run_service_async())
self.thread = threading.Thread(target=run_loop, daemon=True)
self.thread.start()

View file

@ -95,4 +95,4 @@ foodie_url = "http://www.foodieguide.com/iptvsearch/"
foodie_hotel_url = "http://www.foodieguide.com/iptvsearch/hoteliptv.php"
waiting_tip = "🔍️正在更新,请耐心等待更新完成..."
waiting_tip = "🔍️未找到结果文件,若已启动更新,请耐心等待更新完成..."