Beispiel #1
0
 def get_subtitles(self, video_id):
     subtitles = []
     for subtitle in self.iter_subtitles(video_id):
         if "language_label" not in subtitle:
             subtitle["language_label"] = language_name(subtitle['language'])
         subtitles.append(subtitle)
     return subtitles
Beispiel #2
0
 def get_subtitles(self, video_id):
     subtitles = []
     for subtitle in self.iter_subtitles(video_id):
         if "language_label" not in subtitle:
             subtitle["language_label"] = language_name(
                 subtitle['language'])
         subtitles.append(subtitle)
     return subtitles
Beispiel #3
0
 def convert_subtitle_to_dict(self, subtitle):
     subtitle_href = subtitle.attrib['href']
     # Subtitles have no id, so we refer to them via their file name
     subtitle_id = os.path.basename(subtitle_href)
     return {
         'id': subtitle_id,
         'language': subtitle.attrib['language'],
         'language_label': language_name(subtitle.attrib['language']),
         'url': subtitle_href,
     }
Beispiel #4
0
 def convert_subtitle_to_dict(self, subtitle):
     subtitle_href = subtitle.attrib['href']
     # Subtitles have no id, so we refer to them via their file name
     subtitle_id = os.path.basename(subtitle_href)
     return {
         'id': subtitle_id,
         'language': subtitle.attrib['language'],
         'language_label': language_name(subtitle.attrib['language']),
         'url': subtitle_href,
     }
Beispiel #5
0
 def get_video_with_subtitles(self, video_id):
     """Return a single video, identified by its id, along with the
     subtitles information. This method is used by the video xblock to fetch
     video + subtitles info in one go."""
     video = self.fetch_video(video_id)
     video_dict = self.convert_video_to_dict(video)
     video_dict['subtitles'] = [
         {
             'id': sub['id'],
             'url': sub['url'],
             'language': sub['language'],
             'language_label': language_name(sub['language']),
         }
         for sub in video['subtitles']
     ]
     return video_dict
Beispiel #6
0
 def get_video_with_subtitles(self, video_id):
     """Return a single video, identified by its id, along with the
     subtitles information. This method is used by the video xblock to fetch
     video + subtitles info in one go."""
     video = self.fetch_video(video_id)
     video_dict = self.convert_video_to_dict(video)
     video_dict['subtitles'] = [{
         'id':
         sub['id'],
         'url':
         sub['url'],
         'language':
         sub['language'],
         'language_label':
         language_name(sub['language']),
     } for sub in video['subtitles']]
     return video_dict
Beispiel #7
0
    def get_video_with_subtitles(self, video_id):
        """Return a single video, identified by its id, along with the
        subtitles information. This method is used by the video xblock to fetch
        video + subtitles info in one go."""
        if getattr(settings, "VIDEOFRONT_CDN_BASE_URL"):
            # Try getting the video document directly from the S3 bucket metadata file
            try:
                response = requests.get(
                    "{cdn:s}/videos/{id:s}/metadata.json".format(
                        cdn=settings.VIDEOFRONT_CDN_BASE_URL, id=video_id))
            except requests.exceptions.RequestException:
                logger.error(
                    'Unexpected error loading metadata file for video "%s".',
                    video_id,
                )
            else:
                if response.status_code == 200:
                    try:
                        return response.json()
                    except JSONDecodeError:
                        logger.error(
                            'Metadata for VideoFront video "%s" is not valid json.',
                            video_id,
                        )
                else:
                    logger.error(
                        'VideoFront video "%s" could not be loaded from metadata file.',
                        video_id,
                    )

        # Otherwise, load the video document from VideoFront
        video = self.fetch_video(video_id)
        video_dict = self.convert_video_to_dict(video)
        video_dict['subtitles'] = [{
            'id':
            sub['id'],
            'url':
            sub['url'],
            'language':
            sub['language'],
            'language_label':
            language_name(sub['language']),
        } for sub in video['subtitles']]
        return video_dict