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