Skip to content

Commit

Permalink
[ie] Do not test truth value of xml.etree.ElementTree.Element (#8582)
Browse files Browse the repository at this point in the history
Testing the truthiness of an `xml.etree.ElementTree.Element` instance is deprecated in py3.12

Authored by: bashonly
  • Loading branch information
bashonly committed Nov 14, 2023
1 parent 87264d4 commit d4f14a7
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
7 changes: 4 additions & 3 deletions yt_dlp/extractor/cbc.py
@@ -1,8 +1,9 @@
import re
import json
import base64
import json
import re
import time
import urllib.parse
import xml.etree.ElementTree

from .common import InfoExtractor
from ..compat import (
Expand Down Expand Up @@ -387,7 +388,7 @@ def _find_secret_formats(self, formats, video_id):
url = re.sub(r'(Manifest\(.*?),format=[\w-]+(.*?\))', r'\1\2', base_url)

secret_xml = self._download_xml(url, video_id, note='Downloading secret XML', fatal=False)
if not secret_xml:
if not isinstance(secret_xml, xml.etree.ElementTree.Element):
return

for child in secret_xml:
Expand Down
4 changes: 3 additions & 1 deletion yt_dlp/extractor/common.py
Expand Up @@ -2225,7 +2225,9 @@ def _extract_mpd_vod_duration(
mpd_url, video_id,
note='Downloading MPD VOD manifest' if note is None else note,
errnote='Failed to download VOD manifest' if errnote is None else errnote,
fatal=False, data=data, headers=headers, query=query) or {}
fatal=False, data=data, headers=headers, query=query)
if not isinstance(mpd_doc, xml.etree.ElementTree.Element):
return None
return int_or_none(parse_duration(mpd_doc.get('mediaPresentationDuration')))

@staticmethod
Expand Down
3 changes: 2 additions & 1 deletion yt_dlp/extractor/mtv.py
@@ -1,4 +1,5 @@
import re
import xml.etree.ElementTree

from .common import InfoExtractor
from ..compat import compat_str
Expand Down Expand Up @@ -137,7 +138,7 @@ def _get_video_info(self, itemdoc, use_hls=True):
mediagen_doc = self._download_xml(
mediagen_url, video_id, 'Downloading video urls', fatal=False)

if mediagen_doc is False:
if not isinstance(mediagen_doc, xml.etree.ElementTree.Element):
return None

item = mediagen_doc.find('./video/item')
Expand Down
7 changes: 5 additions & 2 deletions yt_dlp/extractor/nbc.py
@@ -1,6 +1,7 @@
import base64
import json
import re
import xml.etree.ElementTree

from .common import InfoExtractor
from .theplatform import ThePlatformIE, default_ns
Expand Down Expand Up @@ -803,8 +804,10 @@ def _real_extract(self, url):
smil = self._download_xml(
f'https://link.theplatform.com/s/{pdk_acct}/{player_id}', video_id,
note='Downloading SMIL data', query=query, fatal=is_live)
subtitles = self._parse_smil_subtitles(smil, default_ns) if smil else {}
for video in smil.findall(self._xpath_ns('.//video', default_ns)) if smil else []:
if not isinstance(smil, xml.etree.ElementTree.Element):
smil = None
subtitles = self._parse_smil_subtitles(smil, default_ns) if smil is not None else {}
for video in smil.findall(self._xpath_ns('.//video', default_ns)) if smil is not None else []:
info['duration'] = float_or_none(remove_end(video.get('dur'), 'ms'), 1000)
video_src_url = video.get('src')
ext = mimetype2ext(video.get('type'), default=determine_ext(video_src_url))
Expand Down
12 changes: 7 additions & 5 deletions yt_dlp/extractor/slideslive.py
@@ -1,5 +1,6 @@
import re
import urllib.parse
import xml.etree.ElementTree

from .common import InfoExtractor
from ..utils import (
Expand Down Expand Up @@ -469,11 +470,12 @@ def _real_extract(self, url):
slides = self._download_xml(
player_info['slides_xml_url'], video_id, fatal=False,
note='Downloading slides XML', errnote='Failed to download slides info')
slide_url_template = 'https://cdn.slideslive.com/data/presentations/%s/slides/big/%s%s'
for slide_id, slide in enumerate(slides.findall('./slide') if slides else [], 1):
slides_info.append((
slide_id, xpath_text(slide, './slideName', 'name'), '.jpg',
int_or_none(xpath_text(slide, './timeSec', 'time'))))
if isinstance(slides, xml.etree.ElementTree.Element):
slide_url_template = 'https://cdn.slideslive.com/data/presentations/%s/slides/big/%s%s'
for slide_id, slide in enumerate(slides.findall('./slide')):
slides_info.append((
slide_id, xpath_text(slide, './slideName', 'name'), '.jpg',
int_or_none(xpath_text(slide, './timeSec', 'time'))))

chapters, thumbnails = [], []
if url_or_none(player_info.get('thumbnail')):
Expand Down

0 comments on commit d4f14a7

Please sign in to comment.