- def _get_subtitles(self, video_id, video_subtitles_id, hl):
- if not video_subtitles_id or not hl:
- return None
- if self._captions_by_country_xml is None:
- self._set_captions_data(video_id, video_subtitles_id, hl)
- if self._captions_by_country_xml is None:
- return None
- return self._get_captions_by_type(video_id, video_subtitles_id, 'subtitles')
-
- def _get_automatic_captions(self, video_id, video_subtitles_id, hl):
- if not video_subtitles_id or not hl:
- return None
- if self._captions_by_country_xml is None:
- self._set_captions_data(video_id, video_subtitles_id, hl)
- if self._captions_by_country_xml is None:
- return None
- self.to_screen('%s: Looking for automatic captions' % video_id)
- subtitle_original_track = self._captions_by_country_xml.find('track')
- if subtitle_original_track is None:
- return None
- subtitle_original_lang_code = subtitle_original_track.attrib.get('lang_code')
- if not subtitle_original_lang_code:
- return None
- return self._get_captions_by_type(video_id, video_subtitles_id, 'automatic_captions', subtitle_original_lang_code)
+ def _get_subtitles(self, video_id, subtitles_id, hl):
+ if not subtitles_id or not hl:
+ return
+ self._download_subtitles_xml(video_id, subtitles_id, hl)
+ if not self._captions_xml:
+ return
+ return self._get_captions_by_type(video_id, subtitles_id, 'subtitles')
+
+ def _get_automatic_captions(self, video_id, subtitles_id, hl):
+ if not subtitles_id or not hl:
+ return
+ self._download_subtitles_xml(video_id, subtitles_id, hl)
+ if not self._captions_xml:
+ return
+ track = self._captions_xml.find('track')
+ if track is None:
+ return
+ origin_lang_code = track.attrib.get('lang_code')
+ if not origin_lang_code:
+ return
+ return self._get_captions_by_type(
+ video_id, subtitles_id, 'automatic_captions', origin_lang_code)