Fix n-click behaviour on poster. Fix unit tests. Fix handler for non_en lang for bumper. Add more tests. Fix docstrings. Fix pep8. Fix static redirection with bumper. Fix button in IE11. Add video_bumper field in bok_choy. Fix pylink violations. Update docstrings and some clean up. Rename edx_video_id in bumper tests. Fix too long lines in help text. Address ui comments. Fix bumper events. Refactor bumper-transcripts code, fix bugs, address comments. Squashed commits: Fix download transcript button. [74e0c8c] Fix quality [a759f33] Fix error, when sub contains extension. [b30755c] Revert "Add video files to host for transcripts." This reverts commit cf8a96bf84346e17b6ad57ad4cc6a27d7a9118cd. [36f038a] Add video files to host for transcripts. [23f1655] Fix pep8 and pyling issues. [0f1f9d2] Update acceptance test. [765a27d] Wait for ajax in captions. [8ae72a3] Fix logic. [063450f] Fix unit tests. [d1075fc] Fix handlers tests. [25d31ad] Update bumper_utils. [cb5f9df] Remove maxDiff. [8738b1a] Code cleanup. [87dbcb7] Fix issues with transcripts. [ec899de] Fix transcripts in serializers. [444b1fc] Fix transcripts typo. [d524cb5] Fix bumper. [f62cf22] Fix video mongo tests. [8f1b55a] Fix dispatches. [53bc308] Add more fixes. [d5e3723] Fix test_video_handlers and rename the method. [93efc23] Fix mobile tests. [740e2ae] Fix pep8 and pylint. [47cfb66] Address comments, add fixes. [4e499d9] Add fixes. [8353553] Add improvements. Updated dispatch values) . Use ddt in bumper handler tests. Move common metadata to single place. Fix style. Update docstring. Fix poster button. Improve bumper events. Fix test after rebase. Address comments. Download transcript: use def video lang, not bump. Renamed date_last_view_bumper to bumper_last_view_date. Rename do_not_show_again_bumper to bumper_... Address comments. Fix tests for download for en lang. Fix bumper logic. Update strings. Update resizer. Remove resizer. Fix unit tests. Add tests. Fix bumper events. Clean up tests. Fix pylint violations. Fix pep8 and pylint violations. Update docs and method names. Update events. Make /static/ prefix a must. Fix wrong code.
131 lines
4.4 KiB
Python
131 lines
4.4 KiB
Python
"""
|
|
Video Outlines
|
|
|
|
We only provide the listing view for a video outline, and video outlines are
|
|
only displayed at the course level. This is because it makes it a lot easier to
|
|
optimize and reason about, and it avoids having to tackle the bigger problem of
|
|
general XBlock representation in this rather specialized formatting.
|
|
"""
|
|
from functools import partial
|
|
|
|
from django.http import Http404, HttpResponse
|
|
from mobile_api.models import MobileApiConfig
|
|
|
|
from rest_framework import generics
|
|
from rest_framework.response import Response
|
|
from opaque_keys.edx.locator import BlockUsageLocator
|
|
|
|
from xmodule.exceptions import NotFoundError
|
|
from xmodule.modulestore.django import modulestore
|
|
|
|
from ..utils import mobile_view, mobile_course_access
|
|
from .serializers import BlockOutline, video_summary
|
|
|
|
|
|
@mobile_view()
|
|
class VideoSummaryList(generics.ListAPIView):
|
|
"""
|
|
**Use Case**
|
|
|
|
Get a list of all videos in the specified course. You can use the
|
|
video_url value to access the video file.
|
|
|
|
**Example request**:
|
|
|
|
GET /api/mobile/v0.5/video_outlines/courses/{organization}/{course_number}/{course_run}
|
|
|
|
**Response Values**
|
|
|
|
An array of videos in the course. For each video:
|
|
|
|
* section_url: The URL to the first page of the section that
|
|
contains the video in the Learning Management System.
|
|
|
|
* path: An array containing category, name, and id values specifying the
|
|
complete path the the video in the courseware hierarchy. The
|
|
following categories values are included: "chapter", "sequential",
|
|
and "vertical". The name value is the display name for that object.
|
|
|
|
* unit_url: The URL to the unit contains the video in the Learning
|
|
Management System.
|
|
|
|
* named_path: An array consisting of the display names of the
|
|
courseware objects in the path to the video.
|
|
|
|
* summary: An array of data about the video that includes:
|
|
|
|
* category: The type of component, in this case always "video".
|
|
|
|
* video_thumbnail_url: The URL to the thumbnail image for the
|
|
video, if available.
|
|
|
|
* language: The language code for the video.
|
|
|
|
* name: The display name of the video.
|
|
|
|
* video_url: The URL to the video file. Use this value to access
|
|
the video.
|
|
|
|
* duration: The length of the video, if available.
|
|
|
|
* transcripts: An array of language codes and URLs to available
|
|
video transcripts. Use the URL value to access a transcript
|
|
for the video.
|
|
|
|
* id: The unique identifier for the video.
|
|
|
|
* size: The size of the video file
|
|
"""
|
|
|
|
@mobile_course_access(depth=None)
|
|
def list(self, request, course, *args, **kwargs):
|
|
video_profiles = MobileApiConfig.get_video_profiles()
|
|
video_outline = list(
|
|
BlockOutline(
|
|
course.id,
|
|
course,
|
|
{"video": partial(video_summary, video_profiles)},
|
|
request,
|
|
video_profiles,
|
|
)
|
|
)
|
|
return Response(video_outline)
|
|
|
|
|
|
@mobile_view()
|
|
class VideoTranscripts(generics.RetrieveAPIView):
|
|
"""
|
|
**Use Case**
|
|
|
|
Use to get a transcript for a specified video and language.
|
|
|
|
**Example request**:
|
|
|
|
GET /api/mobile/v0.5/video_outlines/transcripts/{organization}/{course_number}/{course_run}/{video ID}/{language code}
|
|
|
|
**Response Values**
|
|
|
|
An HttpResponse with an SRT file download.
|
|
|
|
"""
|
|
|
|
@mobile_course_access()
|
|
def get(self, request, course, *args, **kwargs):
|
|
block_id = kwargs['block_id']
|
|
lang = kwargs['lang']
|
|
|
|
usage_key = BlockUsageLocator(
|
|
course.id, block_type="video", block_id=block_id
|
|
)
|
|
try:
|
|
video_descriptor = modulestore().get_item(usage_key)
|
|
transcripts = video_descriptor.get_transcripts_info()
|
|
content, filename, mimetype = video_descriptor.get_transcript(transcripts, lang=lang)
|
|
except (NotFoundError, ValueError, KeyError):
|
|
raise Http404(u"Transcript not found for {}, lang: {}".format(block_id, lang))
|
|
|
|
response = HttpResponse(content, content_type=mimetype)
|
|
response['Content-Disposition'] = 'attachment; filename="{}"'.format(filename.encode('utf-8'))
|
|
|
|
return response
|