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

Method sd_lineups

apps/epg/api_views.py:247–406  ·  view source on GitHub ↗

GET — list lineups currently on the SD account POST — add a lineup (body: {"lineup": "USA-NJ29486-X"}) DELETE — remove a lineup (body: {"lineup": "USA-NJ29486-X"})

(self, request, pk=None)

Source from the content-addressed store, hash-verified

245
246 @action(detail=True, methods=["get", "post", "delete"], url_path="sd-lineups")
247 def sd_lineups(self, request, pk=None):
248 """
249 GET — list lineups currently on the SD account
250 POST — add a lineup (body: {"lineup": "USA-NJ29486-X"})
251 DELETE — remove a lineup (body: {"lineup": "USA-NJ29486-X"})
252 """
253 import requests as http_requests
254 from apps.epg.tasks import SD_BASE_URL
255 from core.utils import dispatcharr_http_headers
256
257 source = self.get_object()
258 if source.source_type != 'schedules_direct':
259 return Response(
260 {"error": "This action is only available for Schedules Direct sources."},
261 status=status.HTTP_400_BAD_REQUEST
262 )
263
264 token, error = self._sd_authenticate(source)
265 if error:
266 return error
267
268 headers = dispatcharr_http_headers(token=token)
269
270 if request.method == "GET":
271 countries = self._fetch_sd_countries()
272 try:
273 resp = http_requests.get(
274 f"{SD_BASE_URL}/lineups",
275 headers=headers,
276 timeout=15,
277 )
278 if resp.status_code == 400:
279 sd_data = resp.json()
280 sd_code = sd_data.get('code')
281 if sd_code == 4102:
282 return Response({
283 "lineups": [],
284 "max_lineups": 4,
285 "changes_remaining": self._get_sd_changes_remaining(source),
286 "changes_reset_at": self._get_sd_reset_at(source),
287 "notice": "No lineups are currently configured on this Schedules Direct account. Use the search below to add one.",
288 "countries": countries,
289 })
290 resp.raise_for_status()
291 data = resp.json()
292 lineups = [l for l in data.get('lineups', []) if not l.get('isDeleted', False)]
293 return Response({
294 "lineups": lineups,
295 "max_lineups": 4,
296 "changes_remaining": self._get_sd_changes_remaining(source),
297 "changes_reset_at": self._get_sd_reset_at(source),
298 "countries": countries,
299 })
300 except http_requests.exceptions.RequestException as e:
301 return Response(
302 {"error": f"Failed to fetch lineups: {str(e)}"},
303 status=status.HTTP_502_BAD_GATEWAY
304 )

Callers

nothing calls this directly

Calls 10

_sd_authenticateMethod · 0.95
_fetch_sd_countriesMethod · 0.95
_get_sd_reset_atMethod · 0.95
_save_sd_lockoutMethod · 0.95
dispatcharr_http_headersFunction · 0.90
getMethod · 0.45
putMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected