Update app.py
Browse files
app.py
CHANGED
|
@@ -13,6 +13,8 @@ def fetch_and_save_m3u():
|
|
| 13 |
response = requests.get(API_URL)
|
| 14 |
response.raise_for_status()
|
| 15 |
stations = response.json()
|
|
|
|
|
|
|
| 16 |
|
| 17 |
# Create temporary file
|
| 18 |
tmp_dir = tempfile.mkdtemp()
|
|
@@ -24,14 +26,15 @@ def fetch_and_save_m3u():
|
|
| 24 |
for station in stations:
|
| 25 |
name = station.get("name", "Unknown")
|
| 26 |
url = station.get("url_resolved", station.get("url",""))
|
| 27 |
-
# Extinf: length -1, display name
|
| 28 |
f.write(f"#EXTINF:-1,{name}\n")
|
| 29 |
f.write(f"{url}\n")
|
| 30 |
|
| 31 |
-
|
|
|
|
| 32 |
|
| 33 |
except Exception as e:
|
| 34 |
-
|
|
|
|
| 35 |
|
| 36 |
# Gradio interface
|
| 37 |
def create_app():
|
|
@@ -40,15 +43,16 @@ def create_app():
|
|
| 40 |
download_button = gr.Button("Экспортировать в M3U")
|
| 41 |
output_file = gr.File(label="Скачать файл .m3u")
|
| 42 |
status = gr.Textbox(label="Статус")
|
|
|
|
| 43 |
|
| 44 |
def on_click():
|
| 45 |
-
file_path, msg = fetch_and_save_m3u()
|
| 46 |
if file_path:
|
| 47 |
-
return file_path, msg
|
| 48 |
else:
|
| 49 |
-
return None, msg
|
| 50 |
|
| 51 |
-
download_button.click(fn=on_click, outputs=[output_file, status])
|
| 52 |
|
| 53 |
return demo
|
| 54 |
|
|
|
|
| 13 |
response = requests.get(API_URL)
|
| 14 |
response.raise_for_status()
|
| 15 |
stations = response.json()
|
| 16 |
+
count = len(stations)
|
| 17 |
+
print(f"Начинаем экспорт {count} радиостанций...")
|
| 18 |
|
| 19 |
# Create temporary file
|
| 20 |
tmp_dir = tempfile.mkdtemp()
|
|
|
|
| 26 |
for station in stations:
|
| 27 |
name = station.get("name", "Unknown")
|
| 28 |
url = station.get("url_resolved", station.get("url",""))
|
|
|
|
| 29 |
f.write(f"#EXTINF:-1,{name}\n")
|
| 30 |
f.write(f"{url}\n")
|
| 31 |
|
| 32 |
+
print(f"Экспорт завершен успешно. Всего записано {count} станций.")
|
| 33 |
+
return file_path, "✔️ Экспорт завершен.", count
|
| 34 |
|
| 35 |
except Exception as e:
|
| 36 |
+
print(f"Ошибка при экспорте: {e}")
|
| 37 |
+
return None, f"❌ Ошибка: {str(e)}", 0
|
| 38 |
|
| 39 |
# Gradio interface
|
| 40 |
def create_app():
|
|
|
|
| 43 |
download_button = gr.Button("Экспортировать в M3U")
|
| 44 |
output_file = gr.File(label="Скачать файл .m3u")
|
| 45 |
status = gr.Textbox(label="Статус")
|
| 46 |
+
count_box = gr.Textbox(label="Количество станций экспортировано")
|
| 47 |
|
| 48 |
def on_click():
|
| 49 |
+
file_path, msg, count = fetch_and_save_m3u()
|
| 50 |
if file_path:
|
| 51 |
+
return file_path, msg, str(count)
|
| 52 |
else:
|
| 53 |
+
return None, msg, "0"
|
| 54 |
|
| 55 |
+
download_button.click(fn=on_click, outputs=[output_file, status, count_box])
|
| 56 |
|
| 57 |
return demo
|
| 58 |
|