diff --git a/db/migrate/20200206110845_add_play_url_to_videos.rb b/db/migrate/20200206110845_add_play_url_to_videos.rb new file mode 100644 index 000000000..b2b3048d8 --- /dev/null +++ b/db/migrate/20200206110845_add_play_url_to_videos.rb @@ -0,0 +1,5 @@ +class AddPlayUrlToVideos < ActiveRecord::Migration[5.2] + def change + add_column :videos, :play_url, :string + end +end \ No newline at end of file diff --git a/lib/tasks/get_video_data.rake b/lib/tasks/get_video_data.rake index b2f8a1e7a..644168699 100644 --- a/lib/tasks/get_video_data.rake +++ b/lib/tasks/get_video_data.rake @@ -42,4 +42,13 @@ namespace :video do puts data end end + + task :get_play_url => :environment do + Video.all.each do |video| + result = AliyunVod::Service.get_play_info(video.uuid) + play_url = (result.dig('PlayInfoList', 'PlayInfo') || []).first&.[]('PlayURL') + + video.update!(play_url: play_url) if play_url.present? + end + end end \ No newline at end of file