MCPcopy Create free account
hub / github.com/Dispatcharr/Dispatcharr / from_stream

Method from_stream

apps/channels/api_views.py:1870–2019  ·  view source on GitHub ↗
(self, request)

Source from the content-addressed store, hash-verified

1868 )
1869 @action(detail=False, methods=["post"], url_path="from-stream")
1870 def from_stream(self, request):
1871 stream_id = request.data.get("stream_id")
1872 if not stream_id:
1873 return Response(
1874 {"error": "Missing stream_id"}, status=status.HTTP_400_BAD_REQUEST
1875 )
1876 stream = get_object_or_404(Stream, pk=stream_id)
1877 channel_group = stream.channel_group
1878
1879 name = request.data.get("name")
1880
1881
1882 if name is None:
1883 name = stream.name
1884
1885 # Check if client provided a channel_number; if not, use stream_chno or auto-assign
1886 channel_number = request.data.get("channel_number")
1887
1888 if channel_number is None:
1889 # Channel number not provided by client, check stream's channel number or auto-assign
1890 if stream.stream_chno is not None:
1891 channel_number = stream.stream_chno
1892 elif channel_number == 0:
1893 # Special case: 0 means ignore provider numbers and auto-assign
1894 channel_number = None
1895 elif channel_number == -1:
1896 # Special case: -1 means assign the number after the current highest
1897 highest = Channel.objects.order_by('-channel_number').values_list('channel_number', flat=True).first()
1898 channel_number = (int(highest) + 1) if highest is not None else 1
1899
1900 if channel_number is None:
1901 # Still None, auto-assign the next available channel number
1902 channel_number = Channel.get_next_available_channel_number()
1903
1904
1905 try:
1906 channel_number = float(channel_number)
1907 except ValueError:
1908 return Response(
1909 {"error": "channel_number must be an integer."},
1910 status=status.HTTP_400_BAD_REQUEST,
1911 )
1912 # If the provided number is already used, return an error.
1913 if Channel.objects.filter(channel_number=channel_number).exists():
1914 channel_number = Channel.get_next_available_channel_number(channel_number)
1915 # Get the tvc_guide_stationid from custom properties if it exists
1916 stream_custom_props = stream.custom_properties or {}
1917 tvc_guide_stationid = stream_custom_props.get("tvc-guide-stationid")
1918
1919 channel_data = {
1920 "channel_number": channel_number,
1921 "name": name,
1922 "tvg_id": stream.tvg_id,
1923 "tvc_guide_stationid": tvc_guide_stationid,
1924 "streams": [stream_id],
1925 "is_adult": stream.is_adult,
1926 }
1927

Callers

nothing calls this directly

Calls 8

validate_logo_urlFunction · 0.90
send_websocket_updateFunction · 0.90
getMethod · 0.45
existsMethod · 0.45
filterMethod · 0.45
saveMethod · 0.45

Tested by

no test coverage detected