- if response.get('success') and response.get('access'):
- width = int_or_none(result.get('width'))
- height = int_or_none(result.get('height'))
-
- playlist0 = try_get(result, lambda x: x['playlist'][0], dict)
- fmts = playlist0.get('sources')
- for fmt in fmts:
- file_path = fmt.get('file')
- if file_path:
- file_url = urljoin(_APPS_BASE_URL, file_path)
- # If we ever wanted to provide the final resolved URL that
- # does not require cookies, albeit with a shorter lifespan:
- # urlh = self._downloader.urlopen(file_url)
- # resolved_url = urlh.geturl()
-
- label = fmt.get('label')
- w = None
- h = None
- if label == 'HD':
- h = 720
- elif label == 'SD':
- h = 360
- if h:
- if width and height:
- w = h * width // height
- else:
- w = h * 4 // 3
-
- formats.append({
- 'format_id': label,
- 'ext': fmt.get('type'),
- 'url': file_url,
- 'width': w,
- 'height': h,
- })
-
- tracks = playlist0.get('tracks', [])
- for track in tracks:
- if not isinstance(track, dict):
- continue
- track_kind = str_or_none(track.get('kind'))
- if not track_kind or not isinstance(track_kind, compat_str):
- continue
- if track_kind.lower() not in ('captions', 'subtitles'):
- continue
- track_url = urljoin(_APPS_BASE_URL, track.get('file'))
- if not track_url:
- continue
- track_label = track.get('label')
- subtitles.setdefault(self._CC_LANGS.get(track_label, track_label), []).append({
+ width = int_or_none(result.get('width'))
+ height = int_or_none(result.get('height'))
+
+ playlist0 = result['playlist'][0]
+ for fmt in playlist0['sources']:
+ file_url = urljoin(self._APPS_BASE_URL, fmt.get('file'))
+ if not file_url:
+ continue
+ # If we ever wanted to provide the final resolved URL that
+ # does not require cookies, albeit with a shorter lifespan:
+ # urlh = self._downloader.urlopen(file_url)
+ # resolved_url = urlh.geturl()
+ label = fmt.get('label')
+ h = self._FORMAT_HEIGHTS.get(label)
+ w = h * width // height if h and width and height else None
+ formats.append({
+ 'format_id': label,
+ 'ext': fmt.get('type'),
+ 'url': file_url,
+ 'width': w,
+ 'height': h,
+ })
+ self._sort_formats(formats)
+
+ subtitles = {}
+ tracks = try_get(playlist0, lambda x: x['tracks'], list) or []
+ for track in tracks:
+ if not isinstance(track, dict):
+ continue
+ track_kind = str_or_none(track.get('kind'))
+ if not track_kind or not isinstance(track_kind, compat_str):
+ continue
+ if track_kind.lower() not in ('captions', 'subtitles'):
+ continue
+ track_url = urljoin(self._APPS_BASE_URL, track.get('file'))
+ if not track_url:
+ continue
+ track_label = track.get('label')
+ subtitles.setdefault(self._CC_LANGS.get(
+ track_label, track_label), []).append({