Merge pull request #17 from wahyd4/iptv

Iptv
This commit is contained in:
2024-11-24 16:11:55 +11:00
committed by GitHub
15 changed files with 934 additions and 2 deletions
BIN
View File
Binary file not shown.
+9 -1
View File
@@ -1,5 +1,5 @@
from django import forms
from .models import Link, Page, Newsletter, ImageCollection, Image
from .models import Link, Page, Newsletter, ImageCollection, Image, IPTVChannel
from simplemde.fields import SimpleMDEField
from django.utils.translation import gettext_lazy as _
from django.core.validators import URLValidator
@@ -103,3 +103,11 @@ class ImageUploadForm(forms.ModelForm):
class Meta:
model = Image
fields = ['title', 'description']
class IPTVChannelForm(forms.ModelForm):
class Meta:
model = IPTVChannel
fields = ['title', 'url', 'description']
widgets = {
'description': forms.Textarea(attrs={'rows': 3}),
}
+17
View File
@@ -0,0 +1,17 @@
from django.urls import path
from .iptv_views import (
IPTVChannelListView,
IPTVChannelCreateView,
IPTVChannelUpdateView,
IPTVChannelDeleteView,
export_m3u_playlist,
)
urlpatterns = [
# UI routes
path('ui/iptv/', IPTVChannelListView.as_view(), name='iptv-list'),
path('ui/iptv/create/', IPTVChannelCreateView.as_view(), name='iptv-create'),
path('ui/iptv/<int:pk>/edit/', IPTVChannelUpdateView.as_view(), name='iptv-update'),
path('ui/iptv/<int:pk>/delete/', IPTVChannelDeleteView.as_view(), name='iptv-delete'),
path('api/iptv/export/', export_m3u_playlist, name='iptv-export'),
]
+56
View File
@@ -0,0 +1,56 @@
from django.urls import reverse_lazy
from django.views.generic import ListView, CreateView, UpdateView, DeleteView
from django.shortcuts import render
from django.http import HttpResponse
from .models import IPTVChannel
from .forms import IPTVChannelForm
class IPTVChannelListView(ListView):
model = IPTVChannel
template_name = 'links/iptv/list.html'
context_object_name = 'channels'
def get_queryset(self):
return IPTVChannel.objects.all()
class IPTVChannelCreateView(CreateView):
model = IPTVChannel
form_class = IPTVChannelForm
template_name = 'links/iptv/form.html'
success_url = reverse_lazy('iptv-list')
def form_valid(self, form):
return super().form_valid(form)
class IPTVChannelUpdateView(UpdateView):
model = IPTVChannel
form_class = IPTVChannelForm
template_name = 'links/iptv/form.html'
success_url = reverse_lazy('iptv-list')
class IPTVChannelDeleteView(DeleteView):
model = IPTVChannel
template_name = 'links/iptv/confirm_delete.html'
success_url = reverse_lazy('iptv-list')
def export_m3u_playlist(request):
"""Export all channels as M3U playlist"""
channels = IPTVChannel.objects.all()
# Start the M3U file content
content = ['#EXTM3U']
for channel in channels:
# Add channel info line
content.append(f'#EXTINF:-1 tvg-id="{channel.id}",{channel.title}')
# Add URL line
content.append(channel.url)
# Join all lines with newlines
playlist_content = '\n'.join(content)
# Create the response with appropriate headers
response = HttpResponse(playlist_content, content_type='audio/x-mpegurl')
response['Content-Disposition'] = 'attachment; filename="iptv_channels.m3u"'
return response
+31
View File
@@ -0,0 +1,31 @@
# Generated by Django 5.0.9 on 2024-11-24 03:42
import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('links', '0020_alter_image_description'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='IPTVChannel',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=200)),
('url', models.URLField(help_text='M3U or similar streaming URL')),
('description', models.TextField(blank=True)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='iptv_channels', to=settings.AUTH_USER_MODEL)),
],
options={
'ordering': ['-created_at'],
},
),
]
@@ -0,0 +1,21 @@
# Generated by Django 5.0.9 on 2024-11-24 03:51
import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('links', '0021_iptvchannel'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.AlterField(
model_name='iptvchannel',
name='user',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='iptv_channels', to=settings.AUTH_USER_MODEL),
),
]
@@ -0,0 +1,17 @@
# Generated by Django 5.0.9 on 2024-11-24 03:52
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('links', '0022_alter_iptvchannel_user'),
]
operations = [
migrations.RemoveField(
model_name='iptvchannel',
name='user',
),
]
+13
View File
@@ -289,3 +289,16 @@ class Image(models.Model):
height=height,
fit='cover'
)
class IPTVChannel(models.Model):
title = models.CharField(max_length=200)
url = models.URLField(help_text="M3U or similar streaming URL")
description = models.TextField(blank=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class Meta:
ordering = ['-created_at']
def __str__(self):
return self.title
+1 -1
View File
@@ -30,7 +30,7 @@
{% for image in images %}
<div class="aspect-w-1 aspect-h-1 overflow-hidden rounded-lg bg-gray-200 shadow-sm
{% if forloop.counter > 2 %}hidden sm:block{% endif %}">
<img src="{{ image.get_url }}"
<img src="{{ image.get_thumbnail_url }}"
alt="{{ image.title }}"
class="object-cover w-full h-full">
</div>
@@ -0,0 +1,29 @@
{% extends "base.html" %}
{% block content %}
<div class="max-w-2xl mx-auto py-8 px-4 sm:px-6 lg:px-8">
<div class="bg-white shadow sm:rounded-lg">
<div class="px-4 py-5 sm:p-6">
<h3 class="text-lg leading-6 font-medium text-gray-900">
Delete IPTV Channel
</h3>
<div class="mt-2 max-w-xl text-sm text-gray-500">
<p>Are you sure you want to delete "{{ object.title }}"? This action cannot be undone.</p>
</div>
<div class="mt-5">
<form method="post">
{% csrf_token %}
<div class="flex justify-end space-x-3">
<a href="{% url 'iptv-list' %}" class="inline-flex items-center px-4 py-2 border border-gray-300 shadow-sm text-sm font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">
Cancel
</a>
<button type="submit" class="inline-flex items-center px-4 py-2 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-red-600 hover:bg-red-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-red-500">
Delete
</button>
</div>
</form>
</div>
</div>
</div>
</div>
{% endblock %}
+63
View File
@@ -0,0 +1,63 @@
{% extends "base.html" %}
{% block content %}
<div class="max-w-2xl mx-auto py-8 px-4 sm:px-6 lg:px-8">
<div class="bg-white shadow sm:rounded-lg">
<div class="px-4 py-5 sm:p-6">
<h3 class="text-lg leading-6 font-medium text-gray-900">
{% if form.instance.pk %}Edit{% else %}Add{% endif %} IPTV Channel
</h3>
<div class="mt-5">
<form method="post" class="space-y-6">
{% csrf_token %}
<div>
<label for="{{ form.title.id_for_label }}" class="block text-sm font-medium text-gray-700">
Channel Title
</label>
<div class="mt-1">
{{ form.title }}
</div>
{% if form.title.errors %}
<p class="mt-2 text-sm text-red-600">{{ form.title.errors.0 }}</p>
{% endif %}
</div>
<div>
<label for="{{ form.url.id_for_label }}" class="block text-sm font-medium text-gray-700">
Stream URL
</label>
<div class="mt-1">
{{ form.url }}
</div>
{% if form.url.errors %}
<p class="mt-2 text-sm text-red-600">{{ form.url.errors.0 }}</p>
{% endif %}
</div>
<div>
<label for="{{ form.description.id_for_label }}" class="block text-sm font-medium text-gray-700">
Description
</label>
<div class="mt-1">
{{ form.description }}
</div>
{% if form.description.errors %}
<p class="mt-2 text-sm text-red-600">{{ form.description.errors.0 }}</p>
{% endif %}
</div>
<div class="flex justify-end space-x-3">
<a href="{% url 'iptv-list' %}" class="inline-flex items-center px-4 py-2 border border-gray-300 shadow-sm text-sm font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">
Cancel
</a>
<button type="submit" class="inline-flex items-center px-4 py-2 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">
Save
</button>
</div>
</form>
</div>
</div>
</div>
</div>
{% endblock %}
+461
View File
@@ -0,0 +1,461 @@
{% extends "base.html" %}
{% load static %}
{% block content %}
<div class="flex flex-col h-screen md:h-[calc(100vh-4rem)] md:flex-row">
<!-- Sidebar - full width on mobile, w-80 on desktop -->
<div class="w-full md:w-80 border-b md:border-r border-gray-200 bg-white overflow-y-auto md:h-full">
<div class="p-4 border-b border-gray-200 flex justify-between items-center sticky top-0 bg-white z-10">
<div class="flex items-center space-x-4">
<h2 class="text-lg font-medium text-gray-900">IPTV Channels</h2>
<a href="{% url 'iptv-export' %}" class="text-gray-400 hover:text-gray-600" title="Export M3U Playlist">
<svg class="h-5 w-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"/>
</svg>
</a>
</div>
<button onclick="showAddModal()" class="inline-flex items-center px-4 py-2 border border-transparent text-base font-medium rounded-md shadow-sm text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">
Add Channel
</button>
</div>
<nav class="flex-1 min-h-0 overflow-y-auto">
<div class="p-2 space-y-2">
{% for channel in channels %}
<div class="channel-item p-4 rounded-md hover:bg-gray-50 {% if channel.id == active_channel.id %}bg-gray-100{% endif %} touch-manipulation"
data-url="{{ channel.url }}"
data-title="{{ channel.title }}"
data-id="{{ channel.id }}"
onclick="selectChannel('{{ channel.url }}', '{{ channel.title }}', this)">
<div class="flex justify-between items-start gap-4">
<div class="min-w-0 flex-1">
<h3 class="text-base font-medium text-gray-900 truncate">{{ channel.title }}</h3>
<p class="text-sm text-gray-500 mt-1">{{ channel.description|truncatechars:50 }}</p>
</div>
<div class="flex space-x-3">
<button onclick="event.stopPropagation(); showEditModal('{{ channel.id }}', '{{ channel.title }}', '{{ channel.url }}', '{{ channel.description }}')" class="p-2 text-gray-400 hover:text-gray-500">
<svg class="h-5 w-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"/>
</svg>
</button>
<button onclick="event.stopPropagation(); showDeleteModal('{{ channel.id }}', '{{ channel.title }}')" class="p-2 text-gray-400 hover:text-gray-500">
<svg class="h-5 w-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"/>
</svg>
</button>
</div>
</div>
</div>
{% empty %}
<div class="text-center py-6">
<p class="text-sm text-gray-500">No channels added yet.</p>
</div>
{% endfor %}
</div>
</nav>
</div>
<!-- Main content - full height on mobile -->
<div class="flex-1 flex flex-col bg-gray-50 min-h-[50vh] md:min-h-0">
<div class="flex-1 flex items-center justify-center relative w-full h-full" id="player-container">
<div class="text-center p-4" id="empty-state">
<svg class="mx-auto h-12 w-12 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 10l4.553-2.276A1 1 0 0121 8.618v6.764a1 1 0 01-1.447.894L15 14M5 18h8a2 2 0 002-2V8a2 2 0 00-2-2H5a2 2 0 00-2 2v8a2 2 0 002 2z"/>
</svg>
<h3 class="mt-2 text-base font-medium text-gray-900">No channel selected</h3>
<p class="mt-1 text-sm text-gray-500">Select a channel from the list to start watching</p>
</div>
<!-- Play overlay -->
<div id="play-overlay" class="hidden absolute inset-0 bg-black bg-opacity-50 flex items-center justify-center cursor-pointer">
<div class="text-center text-white p-4">
<button onclick="playVideo()" class="bg-white bg-opacity-20 rounded-full p-6 hover:bg-opacity-30 transition-all touch-manipulation">
<svg class="h-16 w-16 md:h-20 md:w-20" fill="currentColor" viewBox="0 0 24 24">
<path d="M8 5v14l11-7z"/>
</svg>
</button>
<h3 class="mt-4 text-xl md:text-2xl font-medium" id="channel-title"></h3>
</div>
</div>
<video id="video-player" class="hidden w-full h-full object-contain" controls playsinline></video>
</div>
</div>
</div>
<!-- Add/Edit Channel Modal -->
<div id="channelModal" class="fixed inset-0 bg-gray-500 bg-opacity-75 hidden" role="dialog" aria-modal="true">
<div class="fixed inset-0 overflow-y-auto">
<div class="flex min-h-full items-end justify-center p-4 text-center sm:items-center sm:p-0">
<div class="relative transform overflow-hidden rounded-lg bg-white px-4 pb-4 pt-5 text-left shadow-xl transition-all sm:my-8 sm:w-full sm:max-w-lg sm:p-6">
<div class="absolute right-0 top-0 hidden pr-4 pt-4 sm:block">
<button type="button" onclick="hideChannelModal()" class="rounded-md bg-white text-gray-400 hover:text-gray-500">
<span class="sr-only">Close</span>
<svg class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12" />
</svg>
</button>
</div>
<div class="sm:flex sm:items-start">
<div class="mt-3 text-center sm:ml-4 sm:mt-0 sm:text-left w-full">
<h3 class="text-base font-semibold leading-6 text-gray-900" id="modalTitle">Add Channel</h3>
<div class="mt-4">
<form id="channelForm" class="space-y-4" method="POST" onsubmit="event.preventDefault(); submitChannelForm();">
{% csrf_token %}
<input type="hidden" id="channelId" name="id">
<div>
<label for="title" class="block text-sm font-medium text-gray-700">Title</label>
<input type="text" name="title" id="title" required class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm">
</div>
<div>
<label for="url" class="block text-sm font-medium text-gray-700">URL</label>
<input type="url" name="url" id="url" required class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm">
</div>
<div>
<label for="description" class="block text-sm font-medium text-gray-700">Description</label>
<textarea name="description" id="description" rows="3" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm"></textarea>
</div>
</form>
</div>
</div>
</div>
<div class="mt-5 sm:mt-4 sm:flex sm:flex-row-reverse">
<button type="button" onclick="submitChannelForm()" class="inline-flex w-full justify-center rounded-md bg-indigo-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 sm:ml-3 sm:w-auto">Save</button>
<button type="button" onclick="hideChannelModal()" class="mt-3 inline-flex w-full justify-center rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50 sm:mt-0 sm:w-auto">Cancel</button>
</div>
</div>
</div>
</div>
</div>
<!-- Delete Confirmation Modal -->
<div id="deleteModal" class="fixed inset-0 bg-gray-500 bg-opacity-75 hidden" role="dialog" aria-modal="true">
<div class="fixed inset-0 overflow-y-auto">
<div class="flex min-h-full items-end justify-center p-4 text-center sm:items-center sm:p-0">
<div class="relative transform overflow-hidden rounded-lg bg-white px-4 pb-4 pt-5 text-left shadow-xl transition-all sm:my-8 sm:w-full sm:max-w-lg sm:p-6">
<div class="sm:flex sm:items-start">
<div class="mx-auto flex h-12 w-12 flex-shrink-0 items-center justify-center rounded-full bg-red-100 sm:mx-0 sm:h-10 sm:w-10">
<svg class="h-6 w-6 text-red-600" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" d="M12 9v3.75m-9.303 3.376c-.866 1.5.217 3.374 1.948 3.374h14.71c1.73 0 2.813-1.874 1.948-3.374L13.949 3.378c-.866-1.5-3.032-1.5-3.898 0L2.697 16.126zM12 15.75h.007v.008H12v-.008z" />
</svg>
</div>
<div class="mt-3 text-center sm:ml-4 sm:mt-0 sm:text-left">
<h3 class="text-base font-semibold leading-6 text-gray-900">Delete Channel</h3>
<div class="mt-2">
<p class="text-sm text-gray-500">Are you sure you want to delete "<span id="deleteChannelTitle"></span>"? This action cannot be undone.</p>
</div>
</div>
</div>
<div class="mt-5 sm:mt-4 sm:flex sm:flex-row-reverse">
<button type="button" onclick="confirmDelete()" class="inline-flex w-full justify-center rounded-md bg-red-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-red-500 sm:ml-3 sm:w-auto">Delete</button>
<button type="button" onclick="hideDeleteModal()" class="mt-3 inline-flex w-full justify-center rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50 sm:mt-0 sm:w-auto">Cancel</button>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
{% block extra_js %}
<script src="https://cdn.jsdelivr.net/npm/hls.js@1.4.12"></script>
<script>
const videoPlayer = document.getElementById('video-player');
const emptyState = document.getElementById('empty-state');
const playOverlay = document.getElementById('play-overlay');
const channelTitle = document.getElementById('channel-title');
let hls = null;
let activeChannelElement = null;
function initHls() {
if (!Hls.isSupported()) {
alert('Your browser does not support HLS streaming');
return null;
}
return new Hls({
debug: false,
enableWorker: true,
lowLatencyMode: true,
backBufferLength: 90
});
}
function loadStream(url) {
if (hls) {
hls.destroy();
}
hls = initHls();
if (!hls) return false;
try {
hls.loadSource(url);
hls.attachMedia(videoPlayer);
hls.on(Hls.Events.MANIFEST_PARSED, () => {
console.log('HLS manifest loaded');
if (document.documentElement.hasAttribute('data-user-interacted')) {
playVideo();
} else {
playOverlay.classList.remove('hidden');
}
});
hls.on(Hls.Events.ERROR, (event, data) => {
if (data.fatal) {
switch (data.type) {
case Hls.ErrorTypes.NETWORK_ERROR:
console.error('Network error:', data);
hls.startLoad();
break;
case Hls.ErrorTypes.MEDIA_ERROR:
console.error('Media error:', data);
hls.recoverMediaError();
break;
default:
console.error('Fatal error:', data);
hls.destroy();
alert('Error loading stream. Please try another channel.');
break;
}
}
});
return true;
} catch (error) {
console.error('Error initializing stream:', error);
alert('Error loading stream. Please try another channel.');
return false;
}
}
function selectChannel(url, title, element = null) {
if (!url) {
cleanupPlayer();
return;
}
if (activeChannelElement) {
activeChannelElement.classList.remove('bg-indigo-50', 'border-l-4', 'border-indigo-500');
}
if (element) {
element.classList.add('bg-indigo-50', 'border-l-4', 'border-indigo-500');
activeChannelElement = element;
element.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
}
if (loadStream(url)) {
videoPlayer.classList.remove('hidden');
emptyState.classList.add('hidden');
channelTitle.textContent = title;
} else {
cleanupPlayer();
}
}
function updatePlayOverlay() {
if (!videoPlayer.paused) {
playOverlay.classList.add('hidden');
} else {
playOverlay.classList.remove('hidden');
}
}
function playVideo() {
if (!hls || !videoPlayer) return;
videoPlayer.play()
.then(() => {
document.documentElement.setAttribute('data-user-interacted', 'true');
updatePlayOverlay();
})
.catch((error) => {
console.error('Error playing stream:', error);
alert('Error playing stream. Please try another channel.');
updatePlayOverlay();
});
}
// Add video event listeners to handle play button visibility
videoPlayer.addEventListener('play', updatePlayOverlay);
videoPlayer.addEventListener('pause', updatePlayOverlay);
videoPlayer.addEventListener('ended', updatePlayOverlay);
videoPlayer.addEventListener('error', updatePlayOverlay);
function handleKeyNavigation(e) {
if (!activeChannelElement || (e.key !== 'ArrowUp' && e.key !== 'ArrowDown')) {
return;
}
e.preventDefault();
const channels = Array.from(document.querySelectorAll('.channel-item'));
const currentIndex = channels.indexOf(activeChannelElement);
let nextIndex;
if (e.key === 'ArrowUp') {
nextIndex = currentIndex > 0 ? currentIndex - 1 : channels.length - 1;
} else {
nextIndex = currentIndex < channels.length - 1 ? currentIndex + 1 : 0;
}
const nextChannel = channels[nextIndex];
selectChannel(nextChannel.dataset.url, nextChannel.dataset.title, nextChannel);
}
window.addEventListener('beforeunload', cleanupPlayer);
window.addEventListener('keydown', handleKeyNavigation);
document.addEventListener('DOMContentLoaded', function() {
const firstChannel = document.querySelector('.channel-item');
if (firstChannel) {
const url = firstChannel.dataset.url;
const title = firstChannel.dataset.title;
selectChannel(url, title, firstChannel);
}
});
document.querySelectorAll('.channel-item').forEach(channel => {
channel.onclick = function() {
selectChannel(this.dataset.url, this.dataset.title, this);
};
});
function cleanupPlayer() {
if (hls) {
hls.destroy();
hls = null;
}
if (activeChannelElement) {
activeChannelElement.classList.remove('bg-indigo-50', 'border-l-4', 'border-indigo-500');
activeChannelElement = null;
}
videoPlayer.classList.add('hidden');
emptyState.classList.remove('hidden');
playOverlay.classList.add('hidden');
}
// Modal handling functions
let currentDeleteId = null;
let lastFocusedElement = null;
function showAddModal() {
lastFocusedElement = document.activeElement;
document.getElementById('modalTitle').textContent = 'Add Channel';
document.getElementById('channelId').value = '';
document.getElementById('channelForm').reset();
const modal = document.getElementById('channelModal');
modal.classList.remove('hidden');
document.getElementById('title').focus();
}
function showEditModal(id, title, url, description) {
lastFocusedElement = document.activeElement;
document.getElementById('modalTitle').textContent = 'Edit Channel';
document.getElementById('channelId').value = id;
document.getElementById('title').value = title;
document.getElementById('url').value = url;
document.getElementById('description').value = description;
const modal = document.getElementById('channelModal');
modal.classList.remove('hidden');
document.getElementById('title').focus();
}
function hideChannelModal() {
document.getElementById('channelModal').classList.add('hidden');
if (lastFocusedElement) {
lastFocusedElement.focus();
}
}
function showDeleteModal(id, title) {
lastFocusedElement = document.activeElement;
currentDeleteId = id;
document.getElementById('deleteChannelTitle').textContent = title;
document.getElementById('deleteModal').classList.remove('hidden');
}
function hideDeleteModal() {
currentDeleteId = null;
document.getElementById('deleteModal').classList.add('hidden');
if (lastFocusedElement) {
lastFocusedElement.focus();
}
}
async function submitChannelForm() {
const form = document.getElementById('channelForm');
const formData = new FormData(form);
const id = formData.get('id');
const url = id ? `/ui/iptv/${id}/edit/` : '/ui/iptv/create/';
try {
const response = await fetch(url, {
method: 'POST',
headers: {
'X-CSRFToken': getCookie('csrftoken'),
},
body: formData,
credentials: 'same-origin'
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
hideChannelModal();
window.location.reload();
} catch (error) {
console.error('Error:', error);
alert('Error saving channel. Please try again.');
}
}
async function confirmDelete() {
if (!currentDeleteId) return;
try {
const response = await fetch(`/ui/iptv/${currentDeleteId}/delete/`, {
method: 'POST',
headers: {
'X-CSRFToken': getCookie('csrftoken'),
},
credentials: 'same-origin'
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
hideDeleteModal();
window.location.reload();
} catch (error) {
console.error('Error:', error);
alert('Error deleting channel. Please try again.');
}
}
// Add keyboard event listeners for modal accessibility
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape') {
hideChannelModal();
hideDeleteModal();
}
});
function getCookie(name) {
let cookieValue = null;
if (document.cookie && document.cookie !== '') {
const cookies = document.cookie.split(';');
for (let i = 0; i < cookies.length; i++) {
const cookie = cookies[i].trim();
if (cookie.substring(0, name.length + 1) === (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
</script>
{% endblock %}
+3
View File
@@ -57,6 +57,9 @@ urlpatterns = [
# Include collection URLs
path('', include('links.collection_urls')),
# Include IPTV URLs - must be before alias patterns
path('', include('links.iptv_urls')),
# Aliases - these should always be last
path('<str:alias>/', views.redirect_to_original, name='redirect_to_original'),
path('<str:alias>/<str:param>/', views.redirect_to_original, name='redirect_to_original_with_param'),
+204
View File
@@ -588,6 +588,18 @@ video {
}
}
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border-width: 0;
}
.pointer-events-none {
pointer-events: none;
}
@@ -608,6 +620,10 @@ video {
position: relative;
}
.sticky {
position: sticky;
}
.inset-0 {
inset: 0px;
}
@@ -868,6 +884,10 @@ video {
height: 280px;
}
.h-\[calc\(100vh-4rem\)\] {
height: calc(100vh - 4rem);
}
.h-auto {
height: auto;
}
@@ -880,6 +900,18 @@ video {
height: 100vh;
}
.min-h-0 {
min-height: 0px;
}
.min-h-full {
min-height: 100%;
}
.min-h-\[50vh\] {
min-height: 50vh;
}
.w-12 {
width: 3rem;
}
@@ -916,6 +948,10 @@ video {
width: 2rem;
}
.w-80 {
width: 20rem;
}
.w-full {
width: 100%;
}
@@ -928,6 +964,10 @@ video {
min-width: 100%;
}
.max-w-2xl {
max-width: 42rem;
}
.max-w-3xl {
max-width: 48rem;
}
@@ -988,6 +1028,14 @@ video {
cursor: not-allowed;
}
.cursor-pointer {
cursor: pointer;
}
.touch-manipulation {
touch-action: manipulation;
}
.select-all {
-webkit-user-select: all;
-moz-user-select: all;
@@ -1158,6 +1206,10 @@ video {
overflow-x: auto;
}
.overflow-y-auto {
overflow-y: auto;
}
.truncate {
overflow: hidden;
text-overflow: ellipsis;
@@ -1218,6 +1270,10 @@ video {
border-left-width: 4px;
}
.border-r {
border-right-width: 1px;
}
.border-t {
border-top-width: 1px;
}
@@ -1265,6 +1321,11 @@ video {
border-color: rgb(234 179 8 / var(--tw-border-opacity));
}
.border-indigo-500 {
--tw-border-opacity: 1;
border-color: rgb(99 102 241 / var(--tw-border-opacity));
}
.bg-blue-100 {
--tw-bg-opacity: 1;
background-color: rgb(219 234 254 / var(--tw-bg-opacity));
@@ -1325,6 +1386,11 @@ video {
background-color: rgb(22 163 74 / var(--tw-bg-opacity));
}
.bg-indigo-600 {
--tw-bg-opacity: 1;
background-color: rgb(79 70 229 / var(--tw-bg-opacity));
}
.bg-purple-100 {
--tw-bg-opacity: 1;
background-color: rgb(243 232 255 / var(--tw-bg-opacity));
@@ -1374,10 +1440,28 @@ video {
background-color: rgb(254 249 195 / var(--tw-bg-opacity));
}
.bg-black {
--tw-bg-opacity: 1;
background-color: rgb(0 0 0 / var(--tw-bg-opacity));
}
.bg-indigo-50 {
--tw-bg-opacity: 1;
background-color: rgb(238 242 255 / var(--tw-bg-opacity));
}
.bg-opacity-75 {
--tw-bg-opacity: 0.75;
}
.bg-opacity-20 {
--tw-bg-opacity: 0.2;
}
.bg-opacity-50 {
--tw-bg-opacity: 0.5;
}
.bg-gradient-to-b {
background-image: linear-gradient(to bottom, var(--tw-gradient-stops));
}
@@ -1524,6 +1608,11 @@ video {
padding-bottom: 2rem;
}
.py-6 {
padding-top: 1.5rem;
padding-bottom: 1.5rem;
}
.pl-3 {
padding-left: 0.75rem;
}
@@ -1544,6 +1633,14 @@ video {
padding-top: 1.25rem;
}
.pb-4 {
padding-bottom: 1rem;
}
.pt-4 {
padding-top: 1rem;
}
.text-left {
text-align: left;
}
@@ -1810,6 +1907,21 @@ video {
outline-style: solid;
}
.ring-1 {
--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);
--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color);
box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);
}
.ring-inset {
--tw-ring-inset: inset;
}
.ring-gray-300 {
--tw-ring-opacity: 1;
--tw-ring-color: rgb(209 213 219 / var(--tw-ring-opacity));
}
.blur {
--tw-blur: blur(8px);
filter: var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow);
@@ -1959,6 +2071,11 @@ video {
background-color: rgb(21 128 61 / var(--tw-bg-opacity));
}
.hover\:bg-indigo-700:hover {
--tw-bg-opacity: 1;
background-color: rgb(67 56 202 / var(--tw-bg-opacity));
}
.hover\:bg-purple-600:hover {
--tw-bg-opacity: 1;
background-color: rgb(147 51 234 / var(--tw-bg-opacity));
@@ -1984,6 +2101,20 @@ video {
background-color: rgb(185 28 28 / var(--tw-bg-opacity));
}
.hover\:bg-indigo-500:hover {
--tw-bg-opacity: 1;
background-color: rgb(99 102 241 / var(--tw-bg-opacity));
}
.hover\:bg-red-500:hover {
--tw-bg-opacity: 1;
background-color: rgb(239 68 68 / var(--tw-bg-opacity));
}
.hover\:bg-opacity-30:hover {
--tw-bg-opacity: 0.3;
}
.hover\:text-blue-200:hover {
--tw-text-opacity: 1;
color: rgb(191 219 254 / var(--tw-text-opacity));
@@ -2049,6 +2180,11 @@ video {
color: rgb(153 27 27 / var(--tw-text-opacity));
}
.hover\:text-gray-600:hover {
--tw-text-opacity: 1;
color: rgb(75 85 99 / var(--tw-text-opacity));
}
.hover\:underline:hover {
text-decoration-line: underline;
}
@@ -2078,6 +2214,11 @@ video {
border-color: transparent;
}
.focus\:border-indigo-500:focus {
--tw-border-opacity: 1;
border-color: rgb(99 102 241 / var(--tw-border-opacity));
}
.focus\:outline-none:focus {
outline: 2px solid transparent;
outline-offset: 2px;
@@ -2121,6 +2262,11 @@ video {
--tw-ring-color: rgb(34 197 94 / var(--tw-ring-opacity));
}
.focus\:ring-indigo-500:focus {
--tw-ring-opacity: 1;
--tw-ring-color: rgb(99 102 241 / var(--tw-ring-opacity));
}
.focus\:ring-red-500:focus {
--tw-ring-opacity: 1;
--tw-ring-color: rgb(239 68 68 / var(--tw-ring-opacity));
@@ -2171,6 +2317,11 @@ video {
margin-right: 0px;
}
.sm\:my-8 {
margin-top: 2rem;
margin-bottom: 2rem;
}
.sm\:mb-6 {
margin-bottom: 1.5rem;
}
@@ -2255,6 +2406,14 @@ video {
width: auto;
}
.sm\:w-full {
width: 100%;
}
.sm\:max-w-lg {
max-width: 32rem;
}
.sm\:grid-cols-2 {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
@@ -2313,6 +2472,10 @@ video {
margin-bottom: calc(0px * var(--tw-space-y-reverse));
}
.sm\:rounded-lg {
border-radius: 0.5rem;
}
.sm\:rounded-md {
border-radius: 0.375rem;
}
@@ -2337,6 +2500,10 @@ video {
padding: 1.5rem;
}
.sm\:p-0 {
padding: 0px;
}
.sm\:px-4 {
padding-left: 1rem;
padding-right: 1rem;
@@ -2402,6 +2569,30 @@ video {
display: table-cell;
}
.md\:h-20 {
height: 5rem;
}
.md\:h-\[calc\(100vh-4rem\)\] {
height: calc(100vh - 4rem);
}
.md\:h-full {
height: 100%;
}
.md\:min-h-0 {
min-height: 0px;
}
.md\:w-20 {
width: 5rem;
}
.md\:w-80 {
width: 20rem;
}
.md\:grid-cols-3 {
grid-template-columns: repeat(3, minmax(0, 1fr));
}
@@ -2410,9 +2601,22 @@ video {
grid-template-columns: repeat(4, minmax(0, 1fr));
}
.md\:flex-row {
flex-direction: row;
}
.md\:gap-8 {
gap: 2rem;
}
.md\:border-r {
border-right-width: 1px;
}
.md\:text-2xl {
font-size: 1.5rem;
line-height: 2rem;
}
}
@media (min-width: 1024px) {
+9
View File
@@ -122,6 +122,15 @@
{% trans "Images" %}
</div>
</a>
<a href="{% url 'iptv-list' %}" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100">
<div class="flex items-center">
<svg class="w-5 h-5 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M15 10l4.553-2.276A1 1 0 0121 8.618v6.764a1 1 0 01-1.447.894L15 14M5 18h8a2 2 0 002-2V8a2 2 0 00-2-2H5a2 2 0 00-2 2v8a2 2 0 002 2z"/>
</svg>
{% trans "IPTV" %}
</div>
</a>
<a href="{% url 'api-docs' %}" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-100">
<div class="flex items-center">
<svg class="w-5 h-5 mr-1.5" fill="none" stroke="currentColor" viewBox="0 0 24 24">