From 67f27dda9257b5549fb95048d98da68aac5d149e Mon Sep 17 00:00:00 2001 From: harry Date: Thu, 19 Mar 2020 01:06:36 +0800 Subject: [PATCH 1/4] fix --- public/react/src/modules/courses/Video/video-play/index.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/react/src/modules/courses/Video/video-play/index.jsx b/public/react/src/modules/courses/Video/video-play/index.jsx index 77c64f73c..5fb87cc0f 100644 --- a/public/react/src/modules/courses/Video/video-play/index.jsx +++ b/public/react/src/modules/courses/Video/video-play/index.jsx @@ -130,7 +130,7 @@ export default ({ src, videoId, logWatchHistory, courseId = null }) => { let newTime = el.current.currentTime let timeDiff = newTime - lastUpdatedTime //currenttime update before Seeking & Seeked fired - if (Math.abs(timeDiff) < 0.5) { + if (Math.abs(timeDiff) < 10) { sumTimePlayed += Math.abs(timeDiff) lastUpdatedTime = newTime if (!isLoging) { From 495cebdd257dc9f767a916fd466ab9a952e3c0d9 Mon Sep 17 00:00:00 2001 From: anke1460 Date: Thu, 19 Mar 2020 02:36:23 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E8=AF=BB=E5=8F=96=E8=A7=86=E9=A2=91?= =?UTF-8?q?=E6=97=B6=E9=95=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/create_watch_video_service.rb | 7 ++++++- app/services/videos/batch_publish_service.rb | 13 ++++++++++--- db/migrate/20200318181442_add_duration_to_video.rb | 5 +++++ lib/tasks/get_video_data.rake | 13 +++++++++++++ 4 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 db/migrate/20200318181442_add_duration_to_video.rb diff --git a/app/services/create_watch_video_service.rb b/app/services/create_watch_video_service.rb index 4629d9c8e..4920374dc 100644 --- a/app/services/create_watch_video_service.rb +++ b/app/services/create_watch_video_service.rb @@ -50,7 +50,12 @@ class CreateWatchVideoService < ApplicationService # 更新课程视频的时长及是否看完状态 watch_course_video.watch_duration = params[:watch_duration] if watch_course_video.watch_duration < params[:watch_duration] if params[:ed].present? || (watch_course_video.duration >= 300 && (watch_course_video.duration - params[:point].to_i) <= 20) - watch_course_video.is_finished = watch_course_video.total_duration >= watch_course_video.duration + video_duration = watch_video_history.video.duration.to_i + if video_duration > 0 + watch_course_video.is_finished = watch_course_video.total_duration >= video_duration + else + watch_course_video.is_finished = watch_course_video.total_duration >= watch_course_video.duration + end end end watch_course_video.save! diff --git a/app/services/videos/batch_publish_service.rb b/app/services/videos/batch_publish_service.rb index 553ffe4f2..1c3795102 100644 --- a/app/services/videos/batch_publish_service.rb +++ b/app/services/videos/batch_publish_service.rb @@ -31,16 +31,23 @@ class Videos::BatchPublishService < ApplicationService # 非MP4 H264编码的都转码 code_info = AliyunVod::Service.get_meta_code_info(video.uuid) + + result = AliyunVod::Service.get_play_info(video.uuid) rescue nil Rails.logger.info("code_info: #{code_info[:format]}, #{code_info[:codecnamne]}") if code_info[:format] == "mp4" && code_info[:codecnamne].present? && code_info[:codecnamne].start_with?('h264') video.transcoded = true - result = AliyunVod::Service.get_play_info(video.uuid) rescue nil - play_url = result['PlayInfoList']['PlayInfo'].first['PlayURL'] if result.present? - video.play_url = play_url + if result.present? && result['PlayInfoList']['PlayInfo'].first['PlayURL'] + play_url = result['PlayInfoList']['PlayInfo'].first['PlayURL'] + video.play_url = play_url + end else AliyunVod::Service.submit_transcode_job(video.uuid, Video::NORMAL_TRANSCODE_GROUP_ID) end + if result.present? + video.duration = result["VideoBase"]["Duration"] if result["VideoBase"]["Duration"] + end + video.save! if param[:course_id].present? diff --git a/db/migrate/20200318181442_add_duration_to_video.rb b/db/migrate/20200318181442_add_duration_to_video.rb new file mode 100644 index 000000000..caf3a70e9 --- /dev/null +++ b/db/migrate/20200318181442_add_duration_to_video.rb @@ -0,0 +1,5 @@ +class AddDurationToVideo < ActiveRecord::Migration[5.2] + def change + add_column :videos, :duration, :float, default: 0 + end +end diff --git a/lib/tasks/get_video_data.rake b/lib/tasks/get_video_data.rake index f6f85c7d5..3a86273ec 100644 --- a/lib/tasks/get_video_data.rake +++ b/lib/tasks/get_video_data.rake @@ -74,4 +74,17 @@ namespace :video do end end end + + + task :set_duration => :environment do + videos = Video.published.where("duration = 0") + videos.find_each do |v| + result = AliyunVod::Service.get_play_info(v.uuid) + if result.present? && result["VideoBase"]["Duration"].present? + p '-----#{v.id} , #{result["VideoBase"]["Duration"]]}' + video.update(duration: result["VideoBase"]["Duration"]) + end + end + + end end \ No newline at end of file From 1e84cf48af09860f3e76dfae2adcd7aa9f3660d4 Mon Sep 17 00:00:00 2001 From: anke1460 Date: Thu, 19 Mar 2020 02:39:06 +0800 Subject: [PATCH 3/4] fix --- lib/tasks/get_video_data.rake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/tasks/get_video_data.rake b/lib/tasks/get_video_data.rake index 3a86273ec..3de199502 100644 --- a/lib/tasks/get_video_data.rake +++ b/lib/tasks/get_video_data.rake @@ -82,7 +82,7 @@ namespace :video do result = AliyunVod::Service.get_play_info(v.uuid) if result.present? && result["VideoBase"]["Duration"].present? p '-----#{v.id} , #{result["VideoBase"]["Duration"]]}' - video.update(duration: result["VideoBase"]["Duration"]) + v.update(duration: result["VideoBase"]["Duration"]) end end From 81de79240842e393a3c085d9d7813ae53e942c35 Mon Sep 17 00:00:00 2001 From: anke1460 Date: Thu, 19 Mar 2020 02:46:36 +0800 Subject: [PATCH 4/4] fix --- app/services/videos/batch_publish_service.rb | 4 ++-- lib/tasks/get_video_data.rake | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/services/videos/batch_publish_service.rb b/app/services/videos/batch_publish_service.rb index 1c3795102..3ddc54967 100644 --- a/app/services/videos/batch_publish_service.rb +++ b/app/services/videos/batch_publish_service.rb @@ -31,7 +31,7 @@ class Videos::BatchPublishService < ApplicationService # 非MP4 H264编码的都转码 code_info = AliyunVod::Service.get_meta_code_info(video.uuid) - + result = AliyunVod::Service.get_play_info(video.uuid) rescue nil Rails.logger.info("code_info: #{code_info[:format]}, #{code_info[:codecnamne]}") if code_info[:format] == "mp4" && code_info[:codecnamne].present? && code_info[:codecnamne].start_with?('h264') @@ -45,7 +45,7 @@ class Videos::BatchPublishService < ApplicationService end if result.present? - video.duration = result["VideoBase"]["Duration"] if result["VideoBase"]["Duration"] + video.duration = result['PlayInfoList']['PlayInfo'][0]['Duration'] if result['PlayInfoList']['PlayInfo'][0]['Duration'].present? end video.save! diff --git a/lib/tasks/get_video_data.rake b/lib/tasks/get_video_data.rake index 3de199502..efb89e99e 100644 --- a/lib/tasks/get_video_data.rake +++ b/lib/tasks/get_video_data.rake @@ -80,9 +80,9 @@ namespace :video do videos = Video.published.where("duration = 0") videos.find_each do |v| result = AliyunVod::Service.get_play_info(v.uuid) - if result.present? && result["VideoBase"]["Duration"].present? - p '-----#{v.id} , #{result["VideoBase"]["Duration"]]}' - v.update(duration: result["VideoBase"]["Duration"]) + if result.present? && result['PlayInfoList']['PlayInfo'][0]['Duration'].present? + p "-----#{v.id} , #{result['PlayInfoList']['PlayInfo'][0]['Duration']}" + v.update(duration: result['PlayInfoList']['PlayInfo'][0]['Duration']) end end