canvas-lms/lib/api/v1/media_object.rb

51 lines
1.9 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
Use html5 to show videos by default using a library called mediaElement.js, try to show all kaltura video and audio using html5 and fall back on flash if needed. Test Plan: * in all the different browsers (including mobile safari/chrome) * try recording webcam videos (as homework submission, as content in a wiki page, etc) * view those same pages * view recorded submission in speedgrader use the playlist urls to get kaltura urls This will get CDN-configured links from Kaltura instead of direct Kaltura links. It also allows for the case where a MediaObject does not exist. When one is requested, it will be created in the database and details fetched. Test Plan for cdn urls: * Make sure kaltura is enabled * Open your web inspector's network tab * Browse to a recorded media file in Canvas, and play it * Ensure that the file is streamed from kaltura's configured CDN (s3 in the case of instructure). Test Plan for nonexistent MediaObjects: * Make sure kaltura is enabled * In a wiki page, record a media comment * Destroy that MediaObject from the database (use Inspect Element to find the media_id which looks like 0_1234abcd) * Reload the page, and verify that you can still view the video fix error when viewing a video file that has an unknown source type There are some videos that have valid sources that don't have an extension for some reason. This fixes handling of those correctly. There was also a bug that would sort by bitrate as strings, instead of as integers. The sort function was refactored out and tests written to ensure that's fixed. Test Plan * find a video in kaltura that has an asset with no extension, and make sure you can view that video in a wiki page refs #CNVS-324 Change-Id: I8ff24a94b8af11fc29b84e45545f8a8b639eeaff Reviewed-on: https://gerrit.instructure.com/16824 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Bracken Mosbacker <bracken@instructure.com> QA-Review: Adam Phillipps <adam@instructure.com>
2013-01-16 05:14:29 +08:00
#
# Copyright (C) 2011 - present Instructure, Inc.
Use html5 to show videos by default using a library called mediaElement.js, try to show all kaltura video and audio using html5 and fall back on flash if needed. Test Plan: * in all the different browsers (including mobile safari/chrome) * try recording webcam videos (as homework submission, as content in a wiki page, etc) * view those same pages * view recorded submission in speedgrader use the playlist urls to get kaltura urls This will get CDN-configured links from Kaltura instead of direct Kaltura links. It also allows for the case where a MediaObject does not exist. When one is requested, it will be created in the database and details fetched. Test Plan for cdn urls: * Make sure kaltura is enabled * Open your web inspector's network tab * Browse to a recorded media file in Canvas, and play it * Ensure that the file is streamed from kaltura's configured CDN (s3 in the case of instructure). Test Plan for nonexistent MediaObjects: * Make sure kaltura is enabled * In a wiki page, record a media comment * Destroy that MediaObject from the database (use Inspect Element to find the media_id which looks like 0_1234abcd) * Reload the page, and verify that you can still view the video fix error when viewing a video file that has an unknown source type There are some videos that have valid sources that don't have an extension for some reason. This fixes handling of those correctly. There was also a bug that would sort by bitrate as strings, instead of as integers. The sort function was refactored out and tests written to ensure that's fixed. Test Plan * find a video in kaltura that has an asset with no extension, and make sure you can view that video in a wiki page refs #CNVS-324 Change-Id: I8ff24a94b8af11fc29b84e45545f8a8b639eeaff Reviewed-on: https://gerrit.instructure.com/16824 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Bracken Mosbacker <bracken@instructure.com> QA-Review: Adam Phillipps <adam@instructure.com>
2013-01-16 05:14:29 +08:00
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
Update canvas media_objects api for the RCE closes LA-68 test plan: - have a user with media objects in a couple courses - have another user with a media object - GET /api/v1/media_objects > expect all the objects for the logged in user to be returned, including the sources and tracks data - query /api/v1/media_objects?&exclude[]=sources&exclude[]=tracks > expect all the objects for the logged in user to be returned, excluding the sources and tracks data (it should be _much_ faster too) - query /api/v1/courses/:course_id/media_objects?exclude[]=sources&exclude[]=tracks > expect only the media objects for the logged in user, in the given course to be returned > expect /doc/api/media_objects.html to properly document the api - query /api/v1/courses/:a_nonexistent_course_id/ > expect a 404 sorting - have some media objects with user_entered_title, some with only title. - GET /api/v1/media_objects&sort=title&order=desc > expect the results to be sorted by title descending - GET /api/v1/media_objects&sort=create_at&order=asc > expect the results to be sorted by created_at ascending - you can try other sorts updating* - PUT /api/v1/media_objects/:media_obj_id?user_entered_title=new+title - if :media_obj_id belongs to the current user > expect status=200 and the object to be returned - if :media_obj_id doesn't exist > expect status=401 - if :media_obj_id belongs to another user > expect status=401 - if user_entered_title was empty > expect status=400 - if user_entered_title was missing > expect status=400 - if user wasn't logged in > expect either a 422 (cuz the CSRF header is funky) or a 302 (redirect to the login page) - after updating - GET /media_objects/:id/info > expect the object with the new title returned - GET /api/v1/media_objects?exclude[]=sources&exclude[]=tracks > expect the object to have its new title *To PUT, the request must include a X-CSRF-Token header. The value can be found in documet.cookie on a canvas page (after running decodeURIComponent on it) Change-Id: I496b8a36f1d177054736dadb6695a25bb7aee217 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/215292 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> Tested-by: Jenkins Product-Review: Ed Schiebel <eschiebel@instructure.com> Reviewed-by: Jeremy Stanley <jeremy@instructure.com> QA-Review: Jeremy Stanley <jeremy@instructure.com>
2019-10-31 02:12:24 +08:00
API_MEDIA_OBJECT_JSON_OPTS = {
:only => %w(media_id created_at media_type).freeze,
}.freeze
Use html5 to show videos by default using a library called mediaElement.js, try to show all kaltura video and audio using html5 and fall back on flash if needed. Test Plan: * in all the different browsers (including mobile safari/chrome) * try recording webcam videos (as homework submission, as content in a wiki page, etc) * view those same pages * view recorded submission in speedgrader use the playlist urls to get kaltura urls This will get CDN-configured links from Kaltura instead of direct Kaltura links. It also allows for the case where a MediaObject does not exist. When one is requested, it will be created in the database and details fetched. Test Plan for cdn urls: * Make sure kaltura is enabled * Open your web inspector's network tab * Browse to a recorded media file in Canvas, and play it * Ensure that the file is streamed from kaltura's configured CDN (s3 in the case of instructure). Test Plan for nonexistent MediaObjects: * Make sure kaltura is enabled * In a wiki page, record a media comment * Destroy that MediaObject from the database (use Inspect Element to find the media_id which looks like 0_1234abcd) * Reload the page, and verify that you can still view the video fix error when viewing a video file that has an unknown source type There are some videos that have valid sources that don't have an extension for some reason. This fixes handling of those correctly. There was also a bug that would sort by bitrate as strings, instead of as integers. The sort function was refactored out and tests written to ensure that's fixed. Test Plan * find a video in kaltura that has an asset with no extension, and make sure you can view that video in a wiki page refs #CNVS-324 Change-Id: I8ff24a94b8af11fc29b84e45545f8a8b639eeaff Reviewed-on: https://gerrit.instructure.com/16824 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Bracken Mosbacker <bracken@instructure.com> QA-Review: Adam Phillipps <adam@instructure.com>
2013-01-16 05:14:29 +08:00
Update canvas media_objects api for the RCE closes LA-68 test plan: - have a user with media objects in a couple courses - have another user with a media object - GET /api/v1/media_objects > expect all the objects for the logged in user to be returned, including the sources and tracks data - query /api/v1/media_objects?&exclude[]=sources&exclude[]=tracks > expect all the objects for the logged in user to be returned, excluding the sources and tracks data (it should be _much_ faster too) - query /api/v1/courses/:course_id/media_objects?exclude[]=sources&exclude[]=tracks > expect only the media objects for the logged in user, in the given course to be returned > expect /doc/api/media_objects.html to properly document the api - query /api/v1/courses/:a_nonexistent_course_id/ > expect a 404 sorting - have some media objects with user_entered_title, some with only title. - GET /api/v1/media_objects&sort=title&order=desc > expect the results to be sorted by title descending - GET /api/v1/media_objects&sort=create_at&order=asc > expect the results to be sorted by created_at ascending - you can try other sorts updating* - PUT /api/v1/media_objects/:media_obj_id?user_entered_title=new+title - if :media_obj_id belongs to the current user > expect status=200 and the object to be returned - if :media_obj_id doesn't exist > expect status=401 - if :media_obj_id belongs to another user > expect status=401 - if user_entered_title was empty > expect status=400 - if user_entered_title was missing > expect status=400 - if user wasn't logged in > expect either a 422 (cuz the CSRF header is funky) or a 302 (redirect to the login page) - after updating - GET /media_objects/:id/info > expect the object with the new title returned - GET /api/v1/media_objects?exclude[]=sources&exclude[]=tracks > expect the object to have its new title *To PUT, the request must include a X-CSRF-Token header. The value can be found in documet.cookie on a canvas page (after running decodeURIComponent on it) Change-Id: I496b8a36f1d177054736dadb6695a25bb7aee217 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/215292 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> Tested-by: Jenkins Product-Review: Ed Schiebel <eschiebel@instructure.com> Reviewed-by: Jeremy Stanley <jeremy@instructure.com> QA-Review: Jeremy Stanley <jeremy@instructure.com>
2019-10-31 02:12:24 +08:00
module Api::V1::MediaObject
def media_object_api_json(media_object, current_user, session, exclude = [])
api_json(media_object, current_user, session, API_MEDIA_OBJECT_JSON_OPTS).tap do |json|
json['title'] = media_object.guaranteed_title
json['can_add_captions'] = media_object.grants_right?(current_user, session, :add_captions)
json['media_sources'] = media_sources_json(media_object) unless exclude.include?('sources')
json['embedded_iframe_url'] = media_object_iframe_url(media_object.media_id)
Update canvas media_objects api for the RCE closes LA-68 test plan: - have a user with media objects in a couple courses - have another user with a media object - GET /api/v1/media_objects > expect all the objects for the logged in user to be returned, including the sources and tracks data - query /api/v1/media_objects?&exclude[]=sources&exclude[]=tracks > expect all the objects for the logged in user to be returned, excluding the sources and tracks data (it should be _much_ faster too) - query /api/v1/courses/:course_id/media_objects?exclude[]=sources&exclude[]=tracks > expect only the media objects for the logged in user, in the given course to be returned > expect /doc/api/media_objects.html to properly document the api - query /api/v1/courses/:a_nonexistent_course_id/ > expect a 404 sorting - have some media objects with user_entered_title, some with only title. - GET /api/v1/media_objects&sort=title&order=desc > expect the results to be sorted by title descending - GET /api/v1/media_objects&sort=create_at&order=asc > expect the results to be sorted by created_at ascending - you can try other sorts updating* - PUT /api/v1/media_objects/:media_obj_id?user_entered_title=new+title - if :media_obj_id belongs to the current user > expect status=200 and the object to be returned - if :media_obj_id doesn't exist > expect status=401 - if :media_obj_id belongs to another user > expect status=401 - if user_entered_title was empty > expect status=400 - if user_entered_title was missing > expect status=400 - if user wasn't logged in > expect either a 422 (cuz the CSRF header is funky) or a 302 (redirect to the login page) - after updating - GET /media_objects/:id/info > expect the object with the new title returned - GET /api/v1/media_objects?exclude[]=sources&exclude[]=tracks > expect the object to have its new title *To PUT, the request must include a X-CSRF-Token header. The value can be found in documet.cookie on a canvas page (after running decodeURIComponent on it) Change-Id: I496b8a36f1d177054736dadb6695a25bb7aee217 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/215292 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> Tested-by: Jenkins Product-Review: Ed Schiebel <eschiebel@instructure.com> Reviewed-by: Jeremy Stanley <jeremy@instructure.com> QA-Review: Jeremy Stanley <jeremy@instructure.com>
2019-10-31 02:12:24 +08:00
unless exclude.include?('tracks')
json['media_tracks'] = media_object.media_tracks.map do |track|
api_json(track, current_user, session, :only => %w(kind created_at updated_at id locale)).tap do |json2|
json2[:url] = show_media_tracks_url(media_object.media_id, track.id)
end
end
Allow uploading subtitle tracks to videos when you upload a video, you will now see a [cc] box in the player for that video if you are the uploader of that video and in a modern browser. it will have a link to upload a caption track in SRT or WebVTT format in any language you specify. once you attach a caption track to any of your videos, other people that view it will be able to choose that track while playing it. helpful for people that are deaf or that speak another language! this change also adds google analytics tracking to videos so we know when a given media_id was played, paused, and ended. Test Plan: * record a video, go to play the video * you should see a [cc] button * click the "upload subtitles" link, a dialog should appear that lets you choose a language and file to upload. here's one you can test with: http://mediaelementjs.com/media/NT113_u008_v005_transcript.srt * refresh, you (and anyone else that can see video) should now have the option to select that track for subtitles. (if using in HTML5 player) * you should see a delete 'x' on it to delete it, when you click it it should go away. reload to make sure it is not there. * The user who created the video, or any admins of the course the video is in should be able to manage these captions closes CNVS-324 Change-Id: Id6d4abcb581f0daf101d601221dc45edaad6eaa8 Reviewed-on: https://gerrit.instructure.com/16882 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Bracken Mosbacker <bracken@instructure.com> QA-Review: Adam Phillipps <adam@instructure.com>
2013-01-16 05:15:42 +08:00
end
end
Use html5 to show videos by default using a library called mediaElement.js, try to show all kaltura video and audio using html5 and fall back on flash if needed. Test Plan: * in all the different browsers (including mobile safari/chrome) * try recording webcam videos (as homework submission, as content in a wiki page, etc) * view those same pages * view recorded submission in speedgrader use the playlist urls to get kaltura urls This will get CDN-configured links from Kaltura instead of direct Kaltura links. It also allows for the case where a MediaObject does not exist. When one is requested, it will be created in the database and details fetched. Test Plan for cdn urls: * Make sure kaltura is enabled * Open your web inspector's network tab * Browse to a recorded media file in Canvas, and play it * Ensure that the file is streamed from kaltura's configured CDN (s3 in the case of instructure). Test Plan for nonexistent MediaObjects: * Make sure kaltura is enabled * In a wiki page, record a media comment * Destroy that MediaObject from the database (use Inspect Element to find the media_id which looks like 0_1234abcd) * Reload the page, and verify that you can still view the video fix error when viewing a video file that has an unknown source type There are some videos that have valid sources that don't have an extension for some reason. This fixes handling of those correctly. There was also a bug that would sort by bitrate as strings, instead of as integers. The sort function was refactored out and tests written to ensure that's fixed. Test Plan * find a video in kaltura that has an asset with no extension, and make sure you can view that video in a wiki page refs #CNVS-324 Change-Id: I8ff24a94b8af11fc29b84e45545f8a8b639eeaff Reviewed-on: https://gerrit.instructure.com/16824 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Bracken Mosbacker <bracken@instructure.com> QA-Review: Adam Phillipps <adam@instructure.com>
2013-01-16 05:14:29 +08:00
end
def media_sources_json(media_object)
media_object.media_sources&.map do |mo|
mo[:src] = mo[:url]
mo[:label] = "#{(mo[:bitrate].to_i / 1024).floor} kbps"
mo
end
end
end