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.")