Spaces:
Paused
Paused
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from streamlit_player import st_player
|
| 3 |
+
|
| 4 |
+
# Function to parse the .m3u file
|
| 5 |
+
def parse_m3u(file_path):
|
| 6 |
+
streams = []
|
| 7 |
+
with open(file_path, 'r') as file:
|
| 8 |
+
lines = file.readlines()
|
| 9 |
+
for i in range(len(lines)):
|
| 10 |
+
line = lines[i].strip()
|
| 11 |
+
if line.startswith("#EXTINF"):
|
| 12 |
+
name = line.split(",")[-1].strip()
|
| 13 |
+
url = lines[i + 1].strip()
|
| 14 |
+
streams.append((name, url))
|
| 15 |
+
return streams
|
| 16 |
+
|
| 17 |
+
# Load and parse the M3U file
|
| 18 |
+
m3u_file = "index.m3u" # Path to your M3U file
|
| 19 |
+
streams = parse_m3u(m3u_file)
|
| 20 |
+
|
| 21 |
+
# Streamlit UI
|
| 22 |
+
st.title("IPTV Player")
|
| 23 |
+
|
| 24 |
+
# Dropdown menu to select stream
|
| 25 |
+
stream_names = [name for name, _ in streams]
|
| 26 |
+
selected_stream = st.selectbox("Select a channel", stream_names)
|
| 27 |
+
|
| 28 |
+
# Find the URL of the selected stream
|
| 29 |
+
stream_url = dict(streams).get(selected_stream)
|
| 30 |
+
|
| 31 |
+
# Display the selected stream
|
| 32 |
+
if stream_url:
|
| 33 |
+
st_player(stream_url, playing=True, controls=True, loop=False, width=700, height=400)
|
| 34 |
+
else:
|
| 35 |
+
st.write("Please select a valid stream.")
|