sfd
This commit is contained in:
parent
fb29c46f4f
commit
45e5a7aef4
4 changed files with 180 additions and 180 deletions
|
@ -1,58 +1,58 @@
|
|||
from flask import Flask, request, render_template, send_from_directory
|
||||
import requests
|
||||
import os
|
||||
|
||||
app = Flask(__name__)
|
||||
M3U_URL = "https://iptv-org.github.io/iptv/index.m3u"
|
||||
PLAYLIST_DIR = "playlists"
|
||||
|
||||
if not os.path.exists(PLAYLIST_DIR):
|
||||
os.makedirs(PLAYLIST_DIR)
|
||||
|
||||
def fetch_m3u():
|
||||
response = requests.get(M3U_URL)
|
||||
if response.status_code == 200:
|
||||
return response.text
|
||||
return ""
|
||||
|
||||
def parse_m3u(m3u_content):
|
||||
lines = m3u_content.split("\n")
|
||||
channels = []
|
||||
name, url = None, None
|
||||
for line in lines:
|
||||
if line.startswith("#EXTINF"):
|
||||
parts = line.split(",")
|
||||
name = parts[-1].strip() if len(parts) > 1 else "Unknown Channel"
|
||||
elif line.startswith("http"):
|
||||
url = line.strip()
|
||||
if name and url:
|
||||
channels.append((name, name, url))
|
||||
name, url = None, None
|
||||
return channels
|
||||
|
||||
@app.route("/")
|
||||
def index():
|
||||
m3u_content = fetch_m3u()
|
||||
channels = parse_m3u(m3u_content)
|
||||
return render_template("index.html", channels=channels)
|
||||
|
||||
@app.route("/generate", methods=["POST"])
|
||||
def generate_playlist():
|
||||
filename = request.form.get("filename", "custom_playlist").strip()
|
||||
selected_channels = request.form.getlist("channels")
|
||||
if not filename.endswith(".m3u"):
|
||||
filename += ".m3u"
|
||||
filepath = os.path.join(PLAYLIST_DIR, filename)
|
||||
with open(filepath, "w") as f:
|
||||
f.write("#EXTM3U\n")
|
||||
for channel in selected_channels:
|
||||
info, url = channel.split("|", 1)
|
||||
f.write(f"#EXTINF:-1,{info}\n{url}\n")
|
||||
return f"Playlist created: <a href='/playlists/{filename}'>{filename}</a>"
|
||||
|
||||
@app.route("/playlists/<filename>")
|
||||
def serve_playlist(filename):
|
||||
return send_from_directory(PLAYLIST_DIR, filename)
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(debug=True)
|
||||
from flask import Flask, request, render_template, send_from_directory
|
||||
import requests
|
||||
import os
|
||||
|
||||
app = Flask(__name__)
|
||||
M3U_URL = "https://iptv-org.github.io/iptv/index.m3u"
|
||||
PLAYLIST_DIR = "playlists"
|
||||
|
||||
if not os.path.exists(PLAYLIST_DIR):
|
||||
os.makedirs(PLAYLIST_DIR)
|
||||
|
||||
def fetch_m3u():
|
||||
response = requests.get(M3U_URL)
|
||||
if response.status_code == 200:
|
||||
return response.text
|
||||
return ""
|
||||
|
||||
def parse_m3u(m3u_content):
|
||||
lines = m3u_content.split("\n")
|
||||
channels = []
|
||||
name, url = None, None
|
||||
for line in lines:
|
||||
if line.startswith("#EXTINF"):
|
||||
parts = line.split(",")
|
||||
name = parts[-1].strip() if len(parts) > 1 else "Unknown Channel"
|
||||
elif line.startswith("http"):
|
||||
url = line.strip()
|
||||
if name and url:
|
||||
channels.append((name, name, url))
|
||||
name, url = None, None
|
||||
return channels
|
||||
|
||||
@app.route("/")
|
||||
def index():
|
||||
m3u_content = fetch_m3u()
|
||||
channels = parse_m3u(m3u_content)
|
||||
return render_template("index.html", channels=channels)
|
||||
|
||||
@app.route("/generate", methods=["POST"])
|
||||
def generate_playlist():
|
||||
filename = request.form.get("filename", "custom_playlist").strip()
|
||||
selected_channels = request.form.getlist("channels")
|
||||
if not filename.endswith(".m3u"):
|
||||
filename += ".m3u"
|
||||
filepath = os.path.join(PLAYLIST_DIR, filename)
|
||||
with open(filepath, "w") as f:
|
||||
f.write("#EXTM3U\n")
|
||||
for channel in selected_channels:
|
||||
info, url = channel.split("|", 1)
|
||||
f.write(f"#EXTINF:-1,{info}\n{url}\n")
|
||||
return f"Playlist created: <a href='/playlists/{filename}'>{filename}</a>"
|
||||
|
||||
@app.route("/playlists/<filename>")
|
||||
def serve_playlist(filename):
|
||||
return send_from_directory(PLAYLIST_DIR, filename)
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(debug=True)
|
|
@ -1 +1 @@
|
|||
placeholder
|
||||
placeholder
|
|
@ -1,122 +1,122 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Create Playlist</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
margin: 0;
|
||||
padding: 20px;
|
||||
text-align: center;
|
||||
background-color: #121212;
|
||||
color: #ffffff;
|
||||
}
|
||||
.container {
|
||||
max-width: 600px;
|
||||
margin: auto;
|
||||
background-color: #1e1e1e;
|
||||
padding: 20px;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 0 10px rgba(255, 255, 255, 0.2);
|
||||
}
|
||||
input, button {
|
||||
width: 100%;
|
||||
padding: 10px;
|
||||
margin: 5px 0;
|
||||
font-size: 16px;
|
||||
background-color: #333;
|
||||
color: #ffffff;
|
||||
border: 1px solid #555;
|
||||
border-radius: 5px;
|
||||
}
|
||||
button {
|
||||
background-color: #007bff;
|
||||
cursor: pointer;
|
||||
}
|
||||
button:hover {
|
||||
background-color: #0056b3;
|
||||
}
|
||||
.channel-list {
|
||||
text-align: left;
|
||||
max-height: 300px;
|
||||
overflow-y: auto;
|
||||
border: 1px solid #555;
|
||||
padding: 10px;
|
||||
background-color: #222;
|
||||
border-radius: 5px;
|
||||
}
|
||||
.channel-item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 10px;
|
||||
cursor: pointer;
|
||||
border-bottom: 1px solid #333;
|
||||
}
|
||||
.channel-item:hover {
|
||||
background-color: #333;
|
||||
}
|
||||
.channel-content {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
justify-content: space-between;
|
||||
}
|
||||
.channel-text {
|
||||
flex: 1;
|
||||
}
|
||||
.channel-checkbox {
|
||||
flex-basis: 50px;
|
||||
text-align: right;
|
||||
}
|
||||
.channel-checkbox input {
|
||||
transform: scale(1.2);
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
function filterChannels() {
|
||||
let input = document.getElementById("search").value.toLowerCase();
|
||||
let items = document.querySelectorAll(".channel-item");
|
||||
items.forEach(item => {
|
||||
let text = item.querySelector(".channel-text").textContent.toLowerCase();
|
||||
item.style.display = text.includes(input) ? "flex" : "none";
|
||||
});
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
document.querySelectorAll(".channel-item").forEach(item => {
|
||||
item.addEventListener("click", (event) => {
|
||||
if (event.target.tagName !== "INPUT") {
|
||||
let checkbox = item.querySelector("input");
|
||||
checkbox.checked = !checkbox.checked;
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>Select Channels to Create a New Playlist</h1>
|
||||
<form action="/generate" method="post">
|
||||
<label for="filename">Playlist Name:</label>
|
||||
<input type="text" name="filename" required>
|
||||
<input type="text" id="search" onkeyup="filterChannels()" placeholder="Search channels...">
|
||||
<div class="channel-list">
|
||||
{% for name, info, url in channels %}
|
||||
<div class="channel-item">
|
||||
<div class="channel-content">
|
||||
<span class="channel-text">{{ name }}</span>
|
||||
<div class="channel-checkbox">
|
||||
<input type="checkbox" name="channels" value="{{ info }}|{{ url }}">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<button type="submit">Generate Playlist</button>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Create Playlist</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
margin: 0;
|
||||
padding: 20px;
|
||||
text-align: center;
|
||||
background-color: #121212;
|
||||
color: #ffffff;
|
||||
}
|
||||
.container {
|
||||
max-width: 600px;
|
||||
margin: auto;
|
||||
background-color: #1e1e1e;
|
||||
padding: 20px;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 0 10px rgba(255, 255, 255, 0.2);
|
||||
}
|
||||
input, button {
|
||||
width: 100%;
|
||||
padding: 10px;
|
||||
margin: 5px 0;
|
||||
font-size: 16px;
|
||||
background-color: #333;
|
||||
color: #ffffff;
|
||||
border: 1px solid #555;
|
||||
border-radius: 5px;
|
||||
}
|
||||
button {
|
||||
background-color: #007bff;
|
||||
cursor: pointer;
|
||||
}
|
||||
button:hover {
|
||||
background-color: #0056b3;
|
||||
}
|
||||
.channel-list {
|
||||
text-align: left;
|
||||
max-height: 300px;
|
||||
overflow-y: auto;
|
||||
border: 1px solid #555;
|
||||
padding: 10px;
|
||||
background-color: #222;
|
||||
border-radius: 5px;
|
||||
}
|
||||
.channel-item {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 10px;
|
||||
cursor: pointer;
|
||||
border-bottom: 1px solid #333;
|
||||
}
|
||||
.channel-item:hover {
|
||||
background-color: #333;
|
||||
}
|
||||
.channel-content {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
justify-content: space-between;
|
||||
}
|
||||
.channel-text {
|
||||
flex: 1;
|
||||
}
|
||||
.channel-checkbox {
|
||||
flex-basis: 50px;
|
||||
text-align: right;
|
||||
}
|
||||
.channel-checkbox input {
|
||||
transform: scale(1.2);
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
function filterChannels() {
|
||||
let input = document.getElementById("search").value.toLowerCase();
|
||||
let items = document.querySelectorAll(".channel-item");
|
||||
items.forEach(item => {
|
||||
let text = item.querySelector(".channel-text").textContent.toLowerCase();
|
||||
item.style.display = text.includes(input) ? "flex" : "none";
|
||||
});
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
document.querySelectorAll(".channel-item").forEach(item => {
|
||||
item.addEventListener("click", (event) => {
|
||||
if (event.target.tagName !== "INPUT") {
|
||||
let checkbox = item.querySelector("input");
|
||||
checkbox.checked = !checkbox.checked;
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>Select Channels to Create a New Playlist</h1>
|
||||
<form action="/generate" method="post">
|
||||
<label for="filename">Playlist Name:</label>
|
||||
<input type="text" name="filename" required>
|
||||
<input type="text" id="search" onkeyup="filterChannels()" placeholder="Search channels...">
|
||||
<div class="channel-list">
|
||||
{% for name, info, url in channels %}
|
||||
<div class="channel-item">
|
||||
<div class="channel-content">
|
||||
<span class="channel-text">{{ name }}</span>
|
||||
<div class="channel-checkbox">
|
||||
<input type="checkbox" name="channels" value="{{ info }}|{{ url }}">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<button type="submit">Generate Playlist</button>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
Loading…
Add table
Reference in a new issue