- series_id, episode_number = video_id.split('.')
- episode_info = self._download_json(
- # We only need a single episode info, so restricting page size to one episode
- # and dealing with page number as with episode number
- r'http://www.dramafever.com/api/4/episode/series/?cs=%s&series_id=%s&page_number=%s&page_size=1'
- % (self._consumer_secret, series_id, episode_number),
- video_id, 'Downloading episode info JSON', fatal=False)
- if episode_info:
- value = episode_info.get('value')
- if isinstance(value, list):
- for v in value:
- if v.get('type') == 'Episode':
- subfile = v.get('subfile') or v.get('new_subfile')
- if subfile and subfile != 'http://www.dramafever.com/st/':
- info.setdefault('subtitles', {}).setdefault('English', []).append({
- 'ext': 'srt',
- 'url': subfile,
- })
- episode_number = int_or_none(v.get('number'))
- episode_fallback = 'Episode'
- if episode_number:
- episode_fallback += ' %d' % episode_number
- info['episode'] = v.get('title') or episode_fallback
- info['episode_number'] = episode_number
- break
-
- return info
+ formats = []
+ download_assets = video.get('download_assets')
+ if download_assets and isinstance(download_assets, dict):
+ for format_id, format_dict in download_assets.items():
+ if not isinstance(format_dict, dict):
+ continue
+ format_url = format_dict.get('url')
+ if not format_url or not isinstance(format_url, compat_str):
+ continue
+ formats.append({
+ 'url': format_url,
+ 'format_id': format_id,
+ 'filesize': int_or_none(video.get('filesize')),
+ })
+
+ stream = self._call_api(
+ 'video/%s/stream/' % video_id, video_id, 'Downloading stream JSON',
+ fatal=False)
+ if stream:
+ stream_url = stream.get('stream_url')
+ if stream_url:
+ formats.extend(self._extract_m3u8_formats(
+ stream_url, video_id, 'mp4', entry_protocol='m3u8_native',
+ m3u8_id='hls', fatal=False))
+ self._sort_formats(formats)
+
+ title = video.get('title') or 'Episode %s' % episode_number
+ description = video.get('description')
+ thumbnail = video.get('thumbnail')
+ timestamp = unified_timestamp(video.get('release_date'))
+ duration = parse_duration(video.get('duration'))
+ age_limit = parse_age_limit(video.get('tv_rating'))
+ series = video.get('series_title')
+ season_number = int_or_none(video.get('season'))
+
+ if series:
+ title = '%s - %s' % (series, title)
+
+ subtitles = self.extract_subtitles(video_id)
+
+ return {
+ 'id': video_id,
+ 'title': title,
+ 'description': description,
+ 'thumbnail': thumbnail,
+ 'duration': duration,
+ 'timestamp': timestamp,
+ 'age_limit': age_limit,
+ 'series': series,
+ 'season_number': season_number,
+ 'episode_number': int_or_none(episode_number),
+ 'formats': formats,
+ 'subtitles': subtitles,
+ }