[ceskatelevize] Simplify

pull/4613/merge
Sergey M․ 10 years ago
parent ecd1936695
commit 27a82a1b93

@ -12,7 +12,6 @@ from ..compat import (
from ..utils import (
ExtractorError,
float_or_none,
HEADRequest,
)
@ -105,14 +104,16 @@ class CeskaTelevizeIE(SubtitlesInfoExtractor):
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,
@ -124,13 +125,14 @@ class CeskaTelevizeIE(SubtitlesInfoExtractor):
'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)
@ -139,7 +141,7 @@ class CeskaTelevizeIE(SubtitlesInfoExtractor):
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:])
@ -151,15 +153,3 @@ class CeskaTelevizeIE(SubtitlesInfoExtractor):
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 {}

Loading…
Cancel
Save