from ..utils import (
ExtractorError,
float_or_none,
- HEADRequest,
)
duration = float_or_none(item.get('duration'))
thumbnail = item.get('previewImageUrl')
- # subtitles
- subtitles = self.extract_subtitles(video_id, webpage)
+ subtitles = {}
+ subs = item.get('subtitles')
+ if subs:
+ subtitles['cs'] = subs[0]['url']
if self._downloader.params.get('listsubtitles', False):
- self._list_available_subtitles(video_id, webpage)
+ self._list_available_subtitles(video_id, subtitles)
return
- subtitles = self._fix_subtitles(self.extract_subtitles(video_id, webpage))
+ subtitles = self._fix_subtitles(self.extract_subtitles(video_id, subtitles))
return {
'id': episode_id,
'subtitles': subtitles,
}
- def _fix_subtitles(self, subtitles):
- """ Convert milisecond-based subtitles to SRT """
+ @staticmethod
+ def _fix_subtitles(subtitles):
+ """ Convert millisecond-based subtitles to SRT """
if subtitles is None:
return subtitles # subtitles not requested
def _msectotimecode(msec):
- """ Helper utility to convert miliseconds to timecode """
+ """ Helper utility to convert milliseconds to timecode """
components = []
for divider in [1000, 60, 60, 100]:
components.append(msec % divider)
def _fix_subtitle(subtitle):
for line in subtitle.splitlines():
- m = re.match(r"^ *([0-9]+); *([0-9]+) +([0-9]+) *$", line)
+ m = re.match(r"^\s*([0-9]+);\s*([0-9]+)\s+([0-9]+)\s*$", line)
if m:
yield m.group(1)
start, stop = (_msectotimecode(int(t)) for t in m.groups()[1:])
for k, v in subtitles.items():
fixed_subtitles[k] = "\r\n".join(_fix_subtitle(v))
return fixed_subtitles
-
- def _get_available_subtitles(self, video_id, webpage):
- video_id = video_id.partition('-')[0]
- url = 'http://imgct.ceskatelevize.cz/cache/data/ivysilani/' \
- 'subtitles/{}/{}/sub.txt'.format(video_id[:3], video_id)
- req = HEADRequest(url)
- sub = self._request_webpage(
- req, video_id,
- note="Checking subtitles",
- errnote="No subtitles found",
- fatal=False)
- return {'cs': url} if sub else {}