Vod.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace Video\Lib;
  3. use Dever;
  4. class Vod
  5. {
  6. # 根据id 获取信息
  7. public function get($data, $uid = false)
  8. {
  9. if (!is_array($data)) {
  10. $data = Dever::db('video/vod')->getOne($data);
  11. }
  12. if (!$data) {
  13. Dever::alert('错误的信息');
  14. }
  15. $data['content'] = Dever::filter($data['content']);
  16. $data['video'] = convert($data['video'], 'mp4', 'video/vod', $data['id'], 'video');
  17. $data = $this->avinfo($data);
  18. return $data;
  19. }
  20. # 获取相关推荐
  21. public function getRelation($info)
  22. {
  23. $where['noid'] = $info['id'];
  24. $where['cate_id'] = $info['cate_id'];
  25. return Dever::db('video/vod')->getRelation($where);
  26. }
  27. # 增加浏览量
  28. public function addView($id)
  29. {
  30. Dever::db('video/vod')->addView($id);
  31. }
  32. # 解析元信息
  33. public function avinfo($data, $url = 'video', $table = 'video/vod')
  34. {
  35. # 解析视频元信息
  36. if (!$data['video_info']) {
  37. $video_info = Dever::curl($data[$url] . '?avinfo');
  38. Dever::db($table)->update(array('where_id' => $data['id'], 'video_info' => $video_info));
  39. $video_info = Dever::json_decode($video_info);
  40. } else {
  41. $video_info = Dever::json_decode($data['video_info']);
  42. }
  43. unset($data['video_info']);
  44. $data['video_width'] = 0;
  45. $data['video_height'] = 0;
  46. # 默认横屏
  47. $data['video_type'] = 1;
  48. if (isset($video_info['streams']) && $video_info['streams']) {
  49. foreach ($video_info['streams'] as $k => $v) {
  50. if (isset($v['width']) && isset($v['height'])) {
  51. $data['video_width'] = $v['width'];
  52. $data['video_height'] = $v['height'];
  53. if ($data['video_width'] >= $data['video_height']) {
  54. $data['video_type'] = 1;
  55. } else {
  56. $data['video_type'] = 2;
  57. }
  58. break;
  59. }
  60. }
  61. }
  62. return $data;
  63. }
  64. }