Live.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. namespace Video\Lib;
  3. use Dever;
  4. class Live
  5. {
  6. # 根据id 获取信息
  7. public function get($data, $uid = false)
  8. {
  9. if (!is_array($data)) {
  10. $data = Dever::db('video/live')->getOne($data);
  11. }
  12. if (!$data) {
  13. Dever::alert('错误的信息');
  14. }
  15. $data['content'] = Dever::filter($data['content']);
  16. //embed
  17. $time = time();
  18. $data['live_status'] = $data['status'];
  19. $data['status'] = 1;
  20. $data['stream'] = '';
  21. if ($data['sdate'] <= $time && $time <= $data['edate']) {
  22. if ($data['stream_id'] && $data['stream_id'] > 0) {
  23. $stream = Dever::db('live/stream')->one($data['stream_id']);
  24. $data['stream'] = $stream['live'];
  25. $data['stream_rtmp'] = $stream['url_rtmp'];
  26. $data['stream_hls'] = str_replace('http://', 'https://', $stream['url_hls']);
  27. $data['stream_hdl'] = $stream['url_hdl'];
  28. $data['stream_pic'] = $stream['url_pic'];
  29. $data['url'] = $data['stream_hls'];
  30. $source_type = Dever::input('source_type');
  31. if ($source_type != 'ios' && $source_type != 'android') {
  32. //$data['stream_rtmp'] = $data['stream_hdl'];
  33. }
  34. } elseif (isset($data['stream_link']) && $data['stream_link']) {
  35. $data['stream'] = $data['stream_link'];
  36. $data['stream_rtmp'] = $data['stream_link'];
  37. $data['stream_hls'] = $data['stream_link'];
  38. $data['stream_hdl'] = $data['stream_link'];
  39. $data['stream_pic'] = $data['stream_link'];
  40. $data['url'] = $data['stream_hls'];
  41. }
  42. $data['status'] = 2;
  43. } elseif ($data['sdate'] > $time) {
  44. $data['status'] = 1;
  45. } elseif ($data['edate'] <= $time) {
  46. $data['status'] = 3;
  47. if (!$data['url']) {
  48. # 回放生成中
  49. $data['status'] = 3;
  50. }
  51. }
  52. if ($data['url'] && !isset($data['stream_rtmp'])) {
  53. $data = Dever::load('video/lib/vod')->avinfo($data, 'url', 'video/live');
  54. }
  55. if (Dever::input('test') == 1) {
  56. print_r($data);die;
  57. }
  58. $data['sdate_time'] = date('Y-m-d H:i:s', $data['sdate']);
  59. $data['edate_time'] = date('Y-m-d H:i:s', $data['edate']);
  60. return $data;
  61. }
  62. # 获取相关推荐
  63. public function getRelation($info)
  64. {
  65. $where['noid'] = $info['id'];
  66. $where['cate_id'] = $info['cate_id'];
  67. return Dever::db('video/live')->getRelation($where);
  68. }
  69. # 增加浏览量
  70. public function addView($id)
  71. {
  72. Dever::db('video/live')->addView($id);
  73. }
  74. }