diff --git a/app/libs/aliyun_vod/service/video_manage.rb b/app/libs/aliyun_vod/service/video_manage.rb index 703151841..ca32bda13 100644 --- a/app/libs/aliyun_vod/service/video_manage.rb +++ b/app/libs/aliyun_vod/service/video_manage.rb @@ -37,4 +37,18 @@ module AliyunVod::Service::VideoManage result end + + # 视频播放数据 + def video_data(video_id, start_time, end_time) + params = { + Action: 'DescribePlayVideoStatis', + VideoId: video_id, + StartTime: start_time, + EndTime: end_time + }.merge(base_params) + + result = request(:post, params) + + result + end end \ No newline at end of file diff --git a/app/models/video.rb b/app/models/video.rb index 381db58a9..9af87fe85 100644 --- a/app/models/video.rb +++ b/app/models/video.rb @@ -33,4 +33,8 @@ class Video < ApplicationRecord transitions from: :uploading, to: :uploaded end end + + def video_play_duration + (play_duration / (60*60.0)).ceil + end end \ No newline at end of file diff --git a/app/views/users/videos/_video.json.jbuilder b/app/views/users/videos/_video.json.jbuilder index 9b91c5e94..749532e7d 100644 --- a/app/views/users/videos/_video.json.jbuilder +++ b/app/views/users/videos/_video.json.jbuilder @@ -1,5 +1,6 @@ -json.extract! video, :id, :title, :cover_url, :file_url +json.extract! video, :id, :title, :cover_url, :file_url, :vv +json.play_duration video.video_play_duration json.published_at video.display_published_at json.created_at video.display_created_at json.updated_at video.display_updated_at \ No newline at end of file diff --git a/db/migrate/20200206042916_add_new_column_to_videos.rb b/db/migrate/20200206042916_add_new_column_to_videos.rb new file mode 100644 index 000000000..c2aec6dd3 --- /dev/null +++ b/db/migrate/20200206042916_add_new_column_to_videos.rb @@ -0,0 +1,6 @@ +class AddNewColumnToVideos < ActiveRecord::Migration[5.2] + def change + add_column :videos, :vv, :integer, default: 0 + add_column :videos, :play_duration, :integer, default: 0 + end +end diff --git a/lib/tasks/get_video_data.rake b/lib/tasks/get_video_data.rake new file mode 100644 index 000000000..08ef1acb7 --- /dev/null +++ b/lib/tasks/get_video_data.rake @@ -0,0 +1,14 @@ +namespace :video do + desc "get video play data" + task :data => :environment do + start_time = [Time.utc(2019,8,19,0,0,0), Time.utc(2019,11,10,0,0,0)] + end_time = [Time.utc(2019,11,09,23,59,59), Time.utc(2020,2,6,23,59,59)] + + Video.all.each do |video| + vv = 0 + play_duration = 0 + + + end + end +end \ No newline at end of file