Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +87 -0
- requirements.txt +2 -0
app.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# -*- coding: utf-8 -*-
|
| 2 |
+
"""AIR_Widget.ipynb
|
| 3 |
+
|
| 4 |
+
Automatically generated by Colab.
|
| 5 |
+
|
| 6 |
+
Original file is located at
|
| 7 |
+
https://colab.research.google.com/drive/13DSMlvyBAyKz0NMD4uE8u26KOtQVK5mx
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
import gradio as gr
|
| 13 |
+
import base64
|
| 14 |
+
|
| 15 |
+
# AIR News 24x7 stream URL
|
| 16 |
+
stream_url = "https://air.pc.cdn.bitgravity.com/air/live/pbaudio001/playlist.m3u8"
|
| 17 |
+
station_name = "AIR News 24x7"
|
| 18 |
+
|
| 19 |
+
def generate_iframe():
|
| 20 |
+
html_template = f"""
|
| 21 |
+
<!DOCTYPE html>
|
| 22 |
+
<html>
|
| 23 |
+
<head>
|
| 24 |
+
<script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
|
| 25 |
+
<style>
|
| 26 |
+
body {{
|
| 27 |
+
font-family: sans-serif;
|
| 28 |
+
text-align: center;
|
| 29 |
+
margin: 0;
|
| 30 |
+
padding: 1em;
|
| 31 |
+
}}
|
| 32 |
+
video {{
|
| 33 |
+
width: 80%;
|
| 34 |
+
max-width: 600px;
|
| 35 |
+
height: 50px;
|
| 36 |
+
background: #000;
|
| 37 |
+
}}
|
| 38 |
+
#notice {{
|
| 39 |
+
color: red;
|
| 40 |
+
margin-top: 10px;
|
| 41 |
+
}}
|
| 42 |
+
</style>
|
| 43 |
+
</head>
|
| 44 |
+
<body>
|
| 45 |
+
<h3>{station_name}</h3>
|
| 46 |
+
<video id="player" controls autoplay></video>
|
| 47 |
+
<div id="notice">🔈 If playback doesn't start automatically, click play.</div>
|
| 48 |
+
<script>
|
| 49 |
+
var video = document.getElementById('player');
|
| 50 |
+
if (Hls.isSupported()) {{
|
| 51 |
+
var hls = new Hls();
|
| 52 |
+
hls.loadSource("{stream_url}");
|
| 53 |
+
hls.attachMedia(video);
|
| 54 |
+
hls.on(Hls.Events.MANIFEST_PARSED, function () {{
|
| 55 |
+
var playPromise = video.play();
|
| 56 |
+
if (playPromise !== undefined) {{
|
| 57 |
+
playPromise.catch(function() {{
|
| 58 |
+
document.getElementById("notice").innerText = "Click play to start radio";
|
| 59 |
+
}});
|
| 60 |
+
}}
|
| 61 |
+
}});
|
| 62 |
+
}} else if (video.canPlayType('application/vnd.apple.mpegurl')) {{
|
| 63 |
+
video.src = "{stream_url}";
|
| 64 |
+
video.addEventListener('loadedmetadata', function () {{
|
| 65 |
+
var playPromise = video.play();
|
| 66 |
+
if (playPromise !== undefined) {{
|
| 67 |
+
playPromise.catch(function() {{
|
| 68 |
+
document.getElementById("notice").innerText = "Click play to start radio";
|
| 69 |
+
}});
|
| 70 |
+
}}
|
| 71 |
+
}});
|
| 72 |
+
}} else {{
|
| 73 |
+
document.getElementById("notice").innerText = "❌ Your browser does not support HLS audio.";
|
| 74 |
+
}}
|
| 75 |
+
</script>
|
| 76 |
+
</body>
|
| 77 |
+
</html>
|
| 78 |
+
"""
|
| 79 |
+
html_base64 = base64.b64encode(html_template.encode("utf-8")).decode("utf-8")
|
| 80 |
+
iframe_src = f"data:text/html;base64,{html_base64}"
|
| 81 |
+
return f"""<iframe src="{iframe_src}" width="100%" height="180px" frameborder="0"></iframe>"""
|
| 82 |
+
|
| 83 |
+
with gr.Blocks() as demo:
|
| 84 |
+
gr.Markdown("## 🎙️ AIR News 24x7 Live Stream")
|
| 85 |
+
gr.Markdown("▶ Autoplay enabled. If autoplay is blocked, click the play button.")
|
| 86 |
+
output = gr.HTML(value=generate_iframe())
|
| 87 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
feedparser
|