Cron.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace Live\Lib;
  3. use Dever;
  4. class Cron
  5. {
  6. public function getStream_api()
  7. {
  8. }
  9. public function getUrl_api()
  10. {
  11. }
  12. # 定时获取 所有流的状态 获取推流地址、拉流地址、推流历史等
  13. public function getStream()
  14. {
  15. $data = Dever::db('live/stream')->state();
  16. if ($data) {
  17. foreach ($data as $k => $v) {
  18. $handle = new Handle();
  19. $data = $handle->get($v['id']);
  20. }
  21. }
  22. return 'yes';
  23. }
  24. # 定时获取 所有的直播视频的回放地址
  25. public function getUrl()
  26. {
  27. $video = Dever::config('base', 'live')->video;
  28. $data = Dever::db($video['table'])->state();
  29. if ($data) {
  30. $time = time();
  31. foreach ($data as $k => $v) {
  32. $state = false;
  33. if ($v[$video['url_m3u8']]) {
  34. $url = explode('/', $v[$video['url_m3u8']]);
  35. $index = count($url)-1;
  36. $date = explode('_', str_replace('.m3u8', '', $url[$index]));
  37. if (isset($date[0]) && isset($date[1])) {
  38. if ($date[0] != $v[$video['sdate']]) {
  39. $state = true;
  40. }
  41. if ($date[1] != $v[$video['edate']]) {
  42. $state = true;
  43. }
  44. }
  45. } else {
  46. $state = true;
  47. }
  48. if ($v[$video['stream_id']] > 0 && $state && $v[$video['sdate']] > 0 && $v[$video['edate']] > 0 && $time >= $v[$video['edate']]) {
  49. $info = Dever::db('live/stream')->one($v[$video['stream_id']]);
  50. $config = Dever::db('live/info')->one($info['live_id']);
  51. $handle = new Handle();
  52. $method = $handle->method($config);
  53. $handle->createUrlOne($v, $video, $method, $config, $info);
  54. }
  55. }
  56. }
  57. return 'yes';
  58. }
  59. }