mirror of
https://github.com/Dispatcharr/Dispatcharr.git
synced 2026-07-25 11:04:07 +00:00
commit
e5b71098c5
6 changed files with 31 additions and 8 deletions
|
|
@ -22,15 +22,15 @@ class StreamViewSet(viewsets.ModelViewSet):
|
|||
qs = super().get_queryset()
|
||||
# Exclude streams from inactive M3U accounts
|
||||
qs = qs.exclude(m3u_account__is_active=False)
|
||||
|
||||
|
||||
assigned = self.request.query_params.get('assigned')
|
||||
if assigned is not None:
|
||||
qs = qs.filter(channels__id=assigned)
|
||||
|
||||
|
||||
unassigned = self.request.query_params.get('unassigned')
|
||||
if unassigned == '1':
|
||||
qs = qs.filter(channels__isnull=True)
|
||||
|
||||
|
||||
return qs
|
||||
|
||||
# ─────────────────────────────────────────────────────────
|
||||
|
|
@ -102,11 +102,17 @@ class ChannelViewSet(viewsets.ModelViewSet):
|
|||
return Response({"error": "Missing stream_id"}, status=status.HTTP_400_BAD_REQUEST)
|
||||
stream = get_object_or_404(Stream, pk=stream_id)
|
||||
|
||||
# Create a channel group from the stream group name if it doesn't already exist
|
||||
channel_group, created = ChannelGroup.objects.get_or_create(
|
||||
name=stream.group_name
|
||||
)
|
||||
|
||||
# Include the stream's tvg_id in the channel data
|
||||
channel_data = {
|
||||
'channel_number': request.data.get('channel_number', 0),
|
||||
'channel_name': request.data.get('channel_name', f"Channel from {stream.name}"),
|
||||
'tvg_id': stream.tvg_id, # Inherit tvg-id from the stream
|
||||
'channel_group_id': channel_group.id,
|
||||
}
|
||||
serializer = self.get_serializer(data=channel_data)
|
||||
serializer.is_valid(raise_exception=True)
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ class StreamSerializer(serializers.ModelSerializer):
|
|||
allow_null=True,
|
||||
required=False
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = Stream
|
||||
fields = [
|
||||
|
|
@ -29,6 +30,19 @@ class StreamSerializer(serializers.ModelSerializer):
|
|||
'stream_profile_id',
|
||||
]
|
||||
|
||||
def get_fields(self):
|
||||
fields = super().get_fields()
|
||||
|
||||
# Unable to edit specific properties if this stream was created from an M3U account
|
||||
if self.instance and getattr(self.instance, 'm3u_account', None):
|
||||
fields['id'].read_only = True
|
||||
fields['name'].read_only = True
|
||||
fields['url'].read_only = True
|
||||
fields['m3u_account'].read_only = True
|
||||
fields['tvg_id'].read_only = True
|
||||
fields['group_name'].read_only = True
|
||||
|
||||
return fields
|
||||
|
||||
#
|
||||
# Channel Group
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ class EPGSourceAdmin(admin.ModelAdmin):
|
|||
@admin.register(ProgramData)
|
||||
class ProgramAdmin(admin.ModelAdmin):
|
||||
list_display = ['title', 'get_channel_tvg_id', 'start_time', 'end_time']
|
||||
list_filter = ['epg__channel'] # updated here
|
||||
list_filter = ['epg__channel', 'tvg_id'] # updated here
|
||||
search_fields = ['title', 'epg__channel__channel_name'] # updated here
|
||||
|
||||
def get_channel_tvg_id(self, obj):
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ class ProgramData(models.Model):
|
|||
title = models.CharField(max_length=255)
|
||||
sub_title = models.CharField(max_length=255, blank=True, null=True)
|
||||
description = models.TextField(blank=True, null=True)
|
||||
tvg_id = models.TextField(max_length=255, null=True)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.title} ({self.start_time} - {self.end_time})"
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ class EPGSourceSerializer(serializers.ModelSerializer):
|
|||
class ProgramDataSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = ProgramData
|
||||
fields = ['id', 'start_time', 'end_time', 'title', 'sub_title', 'description']
|
||||
fields = ['id', 'start_time', 'end_time', 'title', 'sub_title', 'description', 'tvg_id']
|
||||
|
||||
class EPGDataSerializer(serializers.ModelSerializer):
|
||||
programs = ProgramDataSerializer(many=True, read_only=True)
|
||||
|
|
|
|||
|
|
@ -47,8 +47,9 @@ def fetch_xmltv(source):
|
|||
'end_time': stop_time,
|
||||
'title': title,
|
||||
'description': desc,
|
||||
'tvg_id': channel_tvg_id,
|
||||
})
|
||||
|
||||
|
||||
# Process each channel group
|
||||
for tvg_id, programmes in programmes_by_channel.items():
|
||||
try:
|
||||
|
|
@ -66,7 +67,7 @@ def fetch_xmltv(source):
|
|||
if not created and epg_data.channel_name != channel.channel_name:
|
||||
epg_data.channel_name = channel.channel_name
|
||||
epg_data.save(update_fields=['channel_name'])
|
||||
|
||||
|
||||
logger.info(f"Processing {len(programmes)} programme(s) for channel '{channel.channel_name}'.")
|
||||
# For each programme, update or create a ProgramData record
|
||||
with transaction.atomic():
|
||||
|
|
@ -78,7 +79,8 @@ def fetch_xmltv(source):
|
|||
defaults={
|
||||
'end_time': prog['end_time'],
|
||||
'description': prog['description'],
|
||||
'sub_title': ''
|
||||
'sub_title': '',
|
||||
'tvg_id': tvg_id,
|
||||
}
|
||||
)
|
||||
if created:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue