from ..utils import (
int_or_none,
strip_or_none,
+ url_or_none,
)
if not video_id:
entries = []
for episode in video_data.get('archiveEpisodes', []):
- episode_url = episode.get('url')
+ episode_url = url_or_none(episode.get('url'))
if not episode_url:
continue
entries.append(self.url_result(
determine_ext,
ExtractorError,
int_or_none,
+ url_or_none,
urlencode_postdata,
xpath_text,
)
file_elements = video_element.findall(compat_xpath('./file'))
one = len(file_elements) == 1
for file_num, file_element in enumerate(file_elements, start=1):
- file_url = file_element.text
+ file_url = url_or_none(file_element.text)
if not file_url:
continue
key = file_element.get('key', '')
from .common import InfoExtractor
from ..utils import (
- int_or_none,
- parse_iso8601,
- mimetype2ext,
determine_ext,
ExtractorError,
+ int_or_none,
+ mimetype2ext,
+ parse_iso8601,
+ url_or_none,
)
media_thumbnail = [media_thumbnail]
for thumbnail_data in media_thumbnail:
thumbnail = thumbnail_data.get('@attributes', {})
- thumbnail_url = thumbnail.get('url')
+ thumbnail_url = url_or_none(thumbnail.get('url'))
if not thumbnail_url:
continue
thumbnails.append({
media_subtitle = [media_subtitle]
for subtitle_data in media_subtitle:
subtitle = subtitle_data.get('@attributes', {})
- subtitle_href = subtitle.get('href')
+ subtitle_href = url_or_none(subtitle.get('href'))
if not subtitle_href:
continue
subtitles.setdefault(subtitle.get('lang') or 'en', []).append({
media_content = [media_content]
for media_data in media_content:
media = media_data.get('@attributes', {})
- media_url = media.get('url')
+ media_url = url_or_none(media.get('url'))
if not media_url:
continue
ext = mimetype2ext(media.get('type')) or determine_ext(media_url)
else:
formats.append({
'format_id': media_data.get('media-category', {}).get('@attributes', {}).get('label'),
- 'url': media['url'],
+ 'url': media_url,
'tbr': int_or_none(media.get('bitrate')),
'filesize': int_or_none(media.get('fileSize')),
'ext': ext,
determine_ext,
extract_attributes,
ExtractorError,
+ url_or_none,
urlencode_postdata,
urljoin,
)
}, fatal=False)
if not playlist:
continue
- stream_url = playlist.get('streamurl')
+ stream_url = url_or_none(playlist.get('streamurl'))
if stream_url:
rtmp = re.search(
r'^(?P<url>rtmpe?://(?P<host>[^/]+)/(?P<app>.+/))(?P<playpath>mp[34]:.+)',
from ..utils import (
ExtractorError,
int_or_none,
+ url_or_none,
)
formats.extend(self._extract_m3u8_formats(
m3u8_url, video_id, 'mp4', m3u8_id='hls', fatal=False))
for rendition in video_data.get('renditions', []):
- video_url = rendition.get('url')
+ video_url = url_or_none(rendition.get('url'))
if not video_url:
continue
ext = rendition.get('format')
import re
from .common import InfoExtractor
-from ..compat import compat_str
from ..utils import (
determine_ext,
js_to_json,
+ url_or_none,
)
for source in sources:
if not isinstance(source, dict):
continue
- source_url = source.get('file')
- if not source_url or not isinstance(source_url, compat_str):
+ source_url = url_or_none(source.get('file'))
+ if not source_url:
continue
ext = determine_ext(source_url)
if ext == 'm3u8':
from ..utils import (
int_or_none,
mimetype2ext,
+ url_or_none,
)
formats = []
for item in file_list[0]:
- file_url = item.get('file')
+ file_url = url_or_none(item.get('file'))
if not file_url:
continue
ext = mimetype2ext(item.get('type'))
from .common import InfoExtractor
from .generic import GenericIE
-from ..compat import compat_str
from ..utils import (
determine_ext,
ExtractorError,
unified_strdate,
xpath_text,
update_url_query,
+ url_or_none,
)
from ..compat import compat_etree_fromstring
quality = stream.get('_quality')
server = stream.get('_server')
for stream_url in stream_urls:
- if not isinstance(stream_url, compat_str) or '//' not in stream_url:
+ if not url_or_none(stream_url):
continue
ext = determine_ext(stream_url)
if quality != 'auto' and ext in ('f4m', 'm3u8'):
unescapeHTML,
update_url_query,
unified_strdate,
+ url_or_none,
)
fatal=False)
if not stat:
continue
- retry_url = stat.get('retry_url')
- if not isinstance(retry_url, compat_str):
+ retry_url = url_or_none(stat.get('retry_url'))
+ if not retry_url:
continue
formats.append({
'url': self._proto_relative_url(retry_url, 'http:'),
formats = []
for format_id, format_url in show['audio_stream'].items():
- if not isinstance(format_url, compat_str):
+ if not url_or_none(format_url):
continue
for known_ext in KNOWN_EXTENSIONS:
if known_ext in format_id:
from .common import InfoExtractor
from .youtube import YoutubeIE
-from ..compat import compat_str
-from ..utils import int_or_none
+from ..utils import (
+ int_or_none,
+ url_or_none,
+)
class BreakIE(InfoExtractor):
formats = []
for video in content:
- video_url = video.get('url')
- if not video_url or not isinstance(video_url, compat_str):
+ video_url = url_or_none(video.get('url'))
+ if not video_url:
continue
bitrate = int_or_none(self._search_regex(
r'(\d+)_kbps', video_url, 'tbr', default=None))
from __future__ import unicode_literals
from .common import InfoExtractor
-from ..compat import compat_str
from ..utils import (
ExtractorError,
int_or_none,
+ url_or_none,
)
for media in encodings:
if not isinstance(media, dict):
continue
- media_url = media.get('location')
- if not media_url or not isinstance(media_url, compat_str):
+ media_url = url_or_none(media.get('location'))
+ if not media_url:
continue
format_id_list = [format_id]
import re
from .common import InfoExtractor
-from ..compat import compat_str
from ..utils import (
clean_html,
int_or_none,
parse_duration,
parse_iso8601,
parse_resolution,
+ url_or_none,
)
media_url = media['media']['url']
if isinstance(media_url, list):
for format_ in media_url:
- format_url = format_.get('file')
- if not format_url or not isinstance(format_url, compat_str):
+ format_url = url_or_none(format_.get('file'))
+ if not format_url:
continue
label = format_.get('label')
f = parse_resolution(label)
import re
from .common import InfoExtractor
-from ..compat import (
- compat_str,
- compat_HTTPError,
-)
+from ..compat import compat_HTTPError
from ..utils import (
determine_ext,
float_or_none,
int_or_none,
parse_age_limit,
parse_duration,
+ url_or_none,
ExtractorError
)
for e in media['MediaURLs']:
if e.get('UseDRM') is True:
continue
- format_url = e.get('Path')
- if not format_url or not isinstance(format_url, compat_str):
+ format_url = url_or_none(e.get('Path'))
+ if not format_url:
continue
ext = determine_ext(format_url)
if ext == 'm3u8':
for cc_file in cc_files:
if not isinstance(cc_file, dict):
continue
- cc_url = cc_file.get('Path')
- if not cc_url or not isinstance(cc_url, compat_str):
+ cc_url = url_or_none(cc_file.get('Path'))
+ if not cc_url:
continue
lang = cc_file.get('Locale') or 'en'
subtitles.setdefault(lang, []).append({'url': cc_url})
float_or_none,
int_or_none,
unified_timestamp,
+ url_or_none,
)
endpoint = next(
server['endpoint']
for server in servers
- if isinstance(server.get('endpoint'), compat_str) and
+ if url_or_none(server.get('endpoint')) and
'cloudfront' in server['endpoint'])
else:
endpoint = 'rtmpe://s2pqqn4u96e4j8.cloudfront.net/cfx/st/'
for image in images:
if not isinstance(image, dict):
continue
- image_url = image.get('url')
- if not image_url or not isinstance(image_url, compat_str):
+ image_url = url_or_none(image.get('url'))
+ if not image_url:
continue
thumbnails.append({
'url': image_url,
import re
from .common import InfoExtractor
-from ..compat import compat_str
from ..utils import (
determine_ext,
extract_attributes,
parse_age_limit,
remove_end,
unescapeHTML,
+ url_or_none,
)
captions = stream.get('captions')
if isinstance(captions, list):
for caption in captions:
- subtitle_url = caption.get('fileUrl')
- if (not subtitle_url or not isinstance(subtitle_url, compat_str) or
- not subtitle_url.startswith('http')):
+ subtitle_url = url_or_none(caption.get('fileUrl'))
+ if not subtitle_url or not subtitle_url.startswith('http'):
continue
lang = caption.get('fileLang', 'en')
ext = determine_ext(subtitle_url)
from .common import InfoExtractor
from ..compat import (
compat_HTTPError,
- compat_str,
compat_urlparse,
)
from ..utils import (
parse_age_limit,
parse_duration,
unified_timestamp,
+ url_or_none,
)
for sub in subs:
if not isinstance(sub, dict):
continue
- sub_url = sub.get('url')
- if not sub_url or not isinstance(sub_url, compat_str):
+ sub_url = url_or_none(sub.get('url'))
+ if not sub_url:
continue
subtitles.setdefault(
sub.get('code') or sub.get('language') or 'en', []).append({
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):
+ format_url = url_or_none(format_dict.get('url'))
+ if not format_url:
continue
formats.append({
'url': format_url,
import re
from .common import InfoExtractor
-from ..compat import (
- compat_HTTPError,
- compat_str,
-)
+from ..compat import compat_HTTPError
from ..utils import (
ExtractorError,
int_or_none,
unsmuggle_url,
+ url_or_none,
)
video_id, 'Downloading mp4 JSON', fatal=False)
if mp4_data:
for format_id, format_url in mp4_data.get('data', {}).items():
- if not isinstance(format_url, compat_str):
+ if not url_or_none(format_url):
continue
height = int_or_none(format_id)
if height is not None and m3u8_formats_dict.get(height):
int_or_none,
try_get,
unified_timestamp,
+ url_or_none,
)
entries = []
for lesson in lessons:
- lesson_url = lesson.get('http_url')
- if not lesson_url or not isinstance(lesson_url, compat_str):
+ lesson_url = url_or_none(lesson.get('http_url'))
+ if not lesson_url:
continue
lesson_id = lesson.get('id')
if lesson_id:
formats = []
for _, format_url in lesson['media_urls'].items():
- if not format_url or not isinstance(format_url, compat_str):
+ format_url = url_or_none(format_url)
+ if not format_url:
continue
ext = determine_ext(format_url)
if ext == 'm3u8':
int_or_none,
parse_duration,
str_to_int,
+ url_or_none,
)
for format_id, format_dict in formats_dict.items():
if not isinstance(format_dict, dict):
continue
- src = format_dict.get('src')
- if not isinstance(src, compat_str) or not src.startswith('http'):
+ src = url_or_none(format_dict.get('src'))
+ if not src or not src.startswith('http'):
continue
if kind == 'hls':
formats.extend(self._extract_m3u8_formats(
int_or_none,
qualities,
unified_strdate,
+ url_or_none,
)
formats = []
path = None
for f in item.get('mbr', []):
- src = f.get('src')
- if not src or not isinstance(src, compat_str):
+ src = url_or_none(f.get('src'))
+ if not src:
continue
tbr = int_or_none(self._search_regex(
r'_(\d{3,})\.mp4', src, 'tbr', default=None))
int_or_none,
parse_duration,
try_get,
+ url_or_none,
)
from .dailymotion import DailymotionIE
def sign(manifest_url, manifest_id):
for host in ('hdfauthftv-a.akamaihd.net', 'hdfauth.francetv.fr'):
- signed_url = self._download_webpage(
+ signed_url = url_or_none(self._download_webpage(
'https://%s/esi/TA' % host, video_id,
'Downloading signed %s manifest URL' % manifest_id,
fatal=False, query={
'url': manifest_url,
- })
- if (signed_url and isinstance(signed_url, compat_str) and
- re.search(r'^(?:https?:)?//', signed_url)):
+ }))
+ if signed_url:
return signed_url
return manifest_url
from ..utils import (
ExtractorError,
parse_duration,
+ url_or_none,
urlencode_postdata,
)
chapters = []
lesson_elements = course.get('lessonElements')
if isinstance(lesson_elements, list):
- chapters = [e for e in lesson_elements if isinstance(e, compat_str)]
+ chapters = [url_or_none(e) for e in lesson_elements if url_or_none(e)]
return chapters
@staticmethod
unified_strdate,
unsmuggle_url,
UnsupportedError,
+ url_or_none,
xpath_text,
)
from .commonprotocols import RtmpIE
sources = [sources]
formats = []
for source in sources:
- src = source.get('src')
- if not src or not isinstance(src, compat_str):
+ src = url_or_none(source.get('src'))
+ if not src:
continue
src = compat_urlparse.urljoin(url, src)
src_type = source.get('type')
from ..utils import (
ExtractorError,
int_or_none,
+ url_or_none,
urlencode_postdata,
)
bitrates = rendition.get('bitrates')
if not isinstance(bitrates, dict):
continue
- m3u8_url = bitrates.get('hls')
- if not isinstance(m3u8_url, compat_str):
+ m3u8_url = url_or_none(bitrates.get('hls'))
+ if not m3u8_url:
continue
formats.extend(self._extract_m3u8_formats(
m3u8_url, video_id, 'mp4', entry_protocol='m3u8_native',
if not isinstance(cc_file, list) or len(cc_file) < 3:
continue
cc_lang = cc_file[0]
- cc_url = cc_file[2]
- if not isinstance(cc_lang, compat_str) or not isinstance(
- cc_url, compat_str):
+ cc_url = url_or_none(cc_file[2])
+ if not isinstance(cc_lang, compat_str) or not cc_url:
continue
subtitles.setdefault(cc_lang, []).append({
'url': cc_url,
import re
from .common import InfoExtractor
-from ..compat import compat_str
from ..utils import (
determine_ext,
mimetype2ext,
parse_duration,
qualities,
+ url_or_none,
)
for encoding in video_metadata.get('encodings', []):
if not encoding or not isinstance(encoding, dict):
continue
- video_url = encoding.get('videoUrl')
- if not video_url or not isinstance(video_url, compat_str):
+ video_url = url_or_none(encoding.get('videoUrl'))
+ if not video_url:
continue
ext = determine_ext(video_url, mimetype2ext(encoding.get('mimeType')))
if ext == 'm3u8':
lowercase_escape,
std_headers,
try_get,
+ url_or_none,
)
node = try_get(edge, lambda x: x['node'], dict)
if not node:
continue
- node_video_url = try_get(node, lambda x: x['video_url'], compat_str)
+ node_video_url = url_or_none(node.get('video_url'))
if not node_video_url:
continue
entries.append({
merge_dicts,
parse_duration,
smuggle_url,
+ url_or_none,
xpath_with_ns,
xpath_element,
xpath_text,
for sub in subs:
if not isinstance(sub, dict):
continue
- href = sub.get('Href')
- if isinstance(href, compat_str):
+ href = url_or_none(sub.get('Href'))
+ if href:
extract_subtitle(href)
if not info.get('duration'):
info['duration'] = parse_duration(video_data.get('Duration'))
from .common import InfoExtractor
from ..aes import aes_decrypt_text
-from ..compat import (
- compat_str,
- compat_urllib_parse_unquote,
-)
+from ..compat import compat_urllib_parse_unquote
from ..utils import (
determine_ext,
ExtractorError,
int_or_none,
str_to_int,
strip_or_none,
+ url_or_none,
)
encrypted = False
def extract_format(format_url, height=None):
- if not isinstance(format_url, compat_str) or not format_url.startswith(('http', '//')):
+ format_url = url_or_none(format_url)
+ if not format_url or not format_url.startswith(('http', '//')):
return
if format_url in format_urls:
return
from __future__ import unicode_literals
from .common import InfoExtractor
-from ..compat import compat_str
from ..utils import (
determine_ext,
float_or_none,
int_or_none,
+ url_or_none,
)
captions = source.get('captionsAvailableLanguages')
if isinstance(captions, dict):
for lang, subtitle_url in captions.items():
- if lang != 'none' and isinstance(subtitle_url, compat_str):
+ subtitle_url = url_or_none(subtitle_url)
+ if lang != 'none' and subtitle_url:
subtitles.setdefault(lang, []).append({'url': subtitle_url})
return {
mimetype2ext,
unescapeHTML,
unsmuggle_url,
+ url_or_none,
urljoin,
)
stream_formats = []
for unum, VideoUrl in enumerate(video_urls):
- video_url = VideoUrl.get('Location')
- if not video_url or not isinstance(video_url, compat_str):
+ video_url = url_or_none(VideoUrl.get('Location'))
+ if not video_url:
continue
# XXX: if Stream.get('CanChangeScheme', False), switch scheme to HTTP/HTTPS
parse_resolution,
try_get,
unified_timestamp,
+ url_or_none,
urljoin,
)
for file_ in video['files']:
if not isinstance(file_, dict):
continue
- file_url = file_.get('fileUrl')
- if not file_url or not isinstance(file_url, compat_str):
+ file_url = url_or_none(file_.get('fileUrl'))
+ if not file_url:
continue
file_size = int_or_none(file_.get('size'))
format_id = try_get(
import re
from .common import InfoExtractor
-from ..compat import compat_str
from ..utils import (
ExtractorError,
int_or_none,
str_to_int,
unified_strdate,
+ url_or_none,
)
video_id, fatal=False)
if medias and isinstance(medias, list):
for media in medias:
- format_url = media.get('videoUrl')
- if not format_url or not isinstance(format_url, compat_str):
+ format_url = url_or_none(media.get('videoUrl'))
+ if not format_url:
continue
format_id = media.get('quality')
formats.append({
from ..utils import (
determine_ext,
int_or_none,
+ url_or_none,
)
title = config['title']
formats = []
for video in config['src']:
- src = video.get('src')
- if not src or not isinstance(src, compat_str):
+ src = url_or_none(video.get('src'))
+ if not src:
continue
ext = determine_ext(src)
if ext == 'm3u8':
int_or_none,
try_get,
unified_timestamp,
+ url_or_none,
)
break
for result in results:
- video_url = result.get('video_url')
- if not video_url or not isinstance(video_url, compat_str):
+ video_url = url_or_none(result.get('video_url'))
+ if not video_url:
continue
entry = self._extract_video(result, require_title=False)
entry.update({
update_url_query,
ExtractorError,
strip_or_none,
+ url_or_none,
)
subtitles = {}
for source in video_data.findall('closedCaptions/source'):
for track in source.findall('track'):
- track_url = track.get('url')
- if not isinstance(track_url, compat_str) or track_url.endswith('/big'):
+ track_url = url_or_none(track.get('url'))
+ if not track_url or track_url.endswith('/big'):
continue
lang = track.get('lang') or track.get('label') or 'en'
subtitles.setdefault(lang, []).append({
import re
from .common import InfoExtractor
-from ..compat import compat_str
from ..utils import (
int_or_none,
unescapeHTML,
+ url_or_none,
)
for stream in self._download_json(data_file, video_id):
if not isinstance(stream, dict):
continue
- stream_url = stream.get('url')
- if (stream_url in stream_urls or not stream_url or
- not isinstance(stream_url, compat_str)):
+ stream_url = url_or_none(stream.get('url'))
+ if stream_url in stream_urls or not stream_url:
continue
stream_urls.add(stream_url)
formats.extend(self._extract_m3u8_formats(
try_get,
unsmuggle_url,
update_url_query,
+ url_or_none,
)
quality = qualities(['hls', 'medium', 'high'])
formats = []
for format_id, video_url in streams.get('streams', {}).items():
- if not video_url or not isinstance(video_url, compat_str):
+ video_url = url_or_none(video_url)
+ if not video_url:
continue
ext = determine_ext(video_url)
if ext == 'f4m':
unified_timestamp,
update_url_query,
urlencode_postdata,
+ url_or_none,
urljoin,
)
for option in status['quality_options']:
if not isinstance(option, dict):
continue
- source = option.get('source')
- if not source or not isinstance(source, compat_str):
+ source = url_or_none(option.get('source'))
+ if not source:
continue
formats.append({
'url': source,
sanitized_Request,
try_get,
unescapeHTML,
+ url_or_none,
urlencode_postdata,
)
if not isinstance(source_list, list):
return
for source in source_list:
- video_url = source.get('file') or source.get('src')
- if not video_url or not isinstance(video_url, compat_str):
+ video_url = url_or_none(source.get('file') or source.get('src'))
+ if not video_url:
continue
if source.get('type') == 'application/x-mpegURL' or determine_ext(video_url) == 'm3u8':
formats.extend(self._extract_m3u8_formats(
continue
if track.get('kind') != 'captions':
continue
- src = track.get('src')
- if not src or not isinstance(src, compat_str):
+ src = url_or_none(track.get('src'))
+ if not src:
continue
lang = track.get('language') or track.get(
'srclang') or track.get('label')
for cc in captions:
if not isinstance(cc, dict):
continue
- cc_url = cc.get('url')
- if not cc_url or not isinstance(cc_url, compat_str):
+ cc_url = url_or_none(cc.get('url'))
+ if not cc_url:
continue
lang = try_get(cc, lambda x: x['locale']['locale'], compat_str)
sub_dict = (automatic_captions if cc.get('source') == 'auto'
import itertools
from .common import InfoExtractor
-from ..compat import (
- compat_HTTPError,
- compat_str,
-)
+from ..compat import compat_HTTPError
from ..utils import (
ExtractorError,
int_or_none,
float_or_none,
parse_iso8601,
+ url_or_none,
)
formats = []
for f in video.get('formats', []):
- format_url = f.get('uri')
- if not format_url or not isinstance(format_url, compat_str):
+ format_url = url_or_none(f.get('uri'))
+ if not format_url:
continue
format_type = f.get('type')
if format_type == 'dash':
str_to_int,
unescapeHTML,
unified_timestamp,
+ url_or_none,
urlencode_postdata,
)
from .dailymotion import DailymotionIE
formats = []
for format_id, format_url in data.items():
- if not isinstance(format_url, compat_str) or not format_url.startswith(('http', '//', 'rtmp')):
+ format_url = url_or_none(format_url)
+ if not format_url or not format_url.startswith(('http', '//', 'rtmp')):
continue
if (format_id.startswith(('url', 'cache')) or
format_id in ('extra_data', 'live_mp4', 'postlive_mp4')):
parse_duration,
try_get,
unified_strdate,
+ url_or_none,
)
else:
format_url = format_item
filesize = None
- if not isinstance(format_url, compat_str):
+ format_url = url_or_none(format_url)
+ if not format_url:
continue
formats.append({
'format_id': '%s-%s' % (format_id, quality),
default='{}'),
video_id, fatal=False)
for format_id, format_url in sources.items():
- if not isinstance(format_url, compat_str):
+ format_url = url_or_none(format_url)
+ if not format_url:
continue
if format_url in format_urls:
continue
import re
from .common import InfoExtractor
-from ..compat import compat_str
from ..utils import (
ExtractorError,
int_or_none,
qualities,
unescapeHTML,
+ url_or_none,
)
formats = []
for format_id in QUALITIES:
is_hd = format_id == 'hd'
- format_url = playlist.get(
- 'file%s' % ('_hd' if is_hd else ''))
- if not format_url or not isinstance(format_url, compat_str):
+ format_url = url_or_none(playlist.get(
+ 'file%s' % ('_hd' if is_hd else '')))
+ if not format_url:
continue
formats.append({
'url': format_url,
import re
from .common import InfoExtractor
-from ..compat import compat_str
from ..utils import (
determine_ext,
int_or_none,
parse_duration,
+ url_or_none,
)
for encoding in encodings:
if not isinstance(encoding, dict):
continue
- format_url = encoding.get('filename')
- if not isinstance(format_url, compat_str):
+ format_url = url_or_none(encoding.get('filename'))
+ if not format_url:
continue
if determine_ext(format_url) == 'm3u8':
formats.extend(self._extract_m3u8_formats(
import re
from .common import InfoExtractor
-from ..compat import compat_str
from ..utils import (
int_or_none,
sanitized_Request,
str_to_int,
unescapeHTML,
unified_strdate,
+ url_or_none,
)
from ..aes import aes_decrypt_text
for definition in definitions:
if not isinstance(definition, dict):
continue
- video_url = definition.get('videoUrl')
- if isinstance(video_url, compat_str) and video_url:
+ video_url = url_or_none(definition.get('videoUrl'))
+ if video_url:
links.append(video_url)
# Fallback #1, this also contains extra low quality 180p format
ExtractorError,
int_or_none,
try_get,
+ url_or_none,
urlencode_postdata,
)
for watch in watch_urls:
if not isinstance(watch, dict):
continue
- watch_url = watch.get('url')
- if not watch_url or not isinstance(watch_url, compat_str):
+ watch_url = url_or_none(watch.get('url'))
+ if not watch_url:
continue
format_id_list = [stream_type]
maxrate = watch.get('maxrate')
try_get,
unified_timestamp,
update_url_query,
+ url_or_none,
urljoin,
)
def _extract_subtitles(src):
subtitles = {}
for caption in try_get(src, lambda x: x['captions'], list) or []:
- subtitle_url = caption.get('uri')
- if subtitle_url and isinstance(subtitle_url, compat_str):
+ subtitle_url = url_or_none(caption.get('uri'))
+ if subtitle_url:
lang = caption.get('language', 'deu')
subtitles.setdefault(lang, []).append({
'url': subtitle_url,
return subtitles
def _extract_format(self, video_id, formats, format_urls, meta):
- format_url = meta.get('url')
- if not format_url or not isinstance(format_url, compat_str):
+ format_url = url_or_none(meta.get('url'))
+ if not format_url:
return
if format_url in format_urls:
return
content, lambda x: x['teaserImageRef']['layouts'], dict)
if layouts:
for layout_key, layout_url in layouts.items():
- if not isinstance(layout_url, compat_str):
+ layout_url = url_or_none(layout_url)
+ if not layout_url:
continue
thumbnail = {
'url': layout_url,