twitch.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include "service-ingest.h"
  2. #include "twitch.h"
  3. static struct service_ingests twitch = {.update_info = NULL,
  4. .mutex = PTHREAD_MUTEX_INITIALIZER,
  5. .ingests_refreshed = false,
  6. .ingests_refreshing = false,
  7. .ingests_loaded = false,
  8. .cur_ingests = {0},
  9. .cache_old_filename = "twitch_ingests.json",
  10. .cache_new_filename = "twitch_ingests.new.json"};
  11. void twitch_ingests_lock(void)
  12. {
  13. pthread_mutex_lock(&twitch.mutex);
  14. }
  15. void twitch_ingests_unlock(void)
  16. {
  17. pthread_mutex_unlock(&twitch.mutex);
  18. }
  19. size_t twitch_ingest_count(void)
  20. {
  21. return twitch.cur_ingests.num;
  22. }
  23. struct ingest twitch_ingest(size_t idx)
  24. {
  25. return get_ingest(&twitch, idx);
  26. }
  27. void init_twitch_data(void)
  28. {
  29. init_service_data(&twitch);
  30. }
  31. void twitch_ingests_refresh(int seconds)
  32. {
  33. service_ingests_refresh(&twitch, seconds, "[twitch ingest update] ", "https://ingest.twitch.tv/ingests");
  34. }
  35. void load_twitch_data(void)
  36. {
  37. struct ingest def = {.name = bstrdup("Default"), .url = bstrdup("rtmp://live.twitch.tv/app")};
  38. load_service_data(&twitch, "twitch_ingests.json", &def);
  39. }
  40. void unload_twitch_data(void)
  41. {
  42. unload_service_data(&twitch);
  43. }