Compare commits

..

5 Commits

Author SHA1 Message Date
0xvd
707537a039
[ie/patreon] Support new URL format (#16926)
Closes #16923
Authored by: 0xvd
2026-06-12 09:14:10 +00:00
Deltadroid
7937a139cf
[fd/external] curl: Support development versions (#16922)
Authored by: syphyr
2026-06-12 09:00:06 +00:00
doe1080
cb309b3293
[utils] HTTPHeaderDict: Fix __ior__ (#16930)
Authored by: doe1080
2026-06-11 16:43:24 +02:00
bashonly
e47691215f
Fix allow-unsafe-ext compat option (#16920)
Fix bug in e578e265f7c6ca94a74b30e0d8d6196a4d19fb6a

Closes #16919
Authored by: bashonly
2026-06-10 23:00:05 +00:00
bashonly
a541df1ea5
[ie/bandcamp:weekly] Fix extractor (#16925)
Closes #16924
Authored by: bashonly
2026-06-10 22:34:16 +00:00
7 changed files with 61 additions and 15 deletions

View File

@ -327,6 +327,12 @@ class TestUtil(unittest.TestCase):
with self.assertRaises(_UnsafeExtensionError):
prepend_extension('abc.unexpected_ext', ext, 'ext')
# Test allow-unsafe-ext compat option
_UnsafeExtensionError._enabled = False
self.assertEqual(prepend_extension('abc.ext', 'un/safe'), 'abc.un/safe.ext')
# Re-enable sanitization for other tests
_UnsafeExtensionError._enabled = True
def test_replace_extension(self):
self.assertEqual(replace_extension('abc.ext', 'temp'), 'abc.temp')
self.assertEqual(replace_extension('abc.ext', 'temp', 'ext'), 'abc.temp')
@ -345,6 +351,12 @@ class TestUtil(unittest.TestCase):
with self.assertRaises(_UnsafeExtensionError):
replace_extension('abc.unexpected_ext', ext, 'ext')
# Test allow-unsafe-ext compat option
_UnsafeExtensionError._enabled = False
self.assertEqual(replace_extension('abc.ext', 'bin'), 'abc.bin')
# Re-enable sanitization for other tests
_UnsafeExtensionError._enabled = True
def test_subtitles_filename(self):
self.assertEqual(subtitles_filename('abc.ext', 'en', 'vtt'), 'abc.en.vtt')
self.assertEqual(subtitles_filename('abc.ext', 'en', 'vtt', 'ext'), 'abc.en.vtt')
@ -2160,6 +2172,10 @@ Line 1
headers6 = HTTPHeaderDict(a=1, b=2)
self.assertEqual(pickle.loads(pickle.dumps(headers6)), headers6)
headers7 = HTTPHeaderDict()
headers7 |= {'X-dlp': 'data'}
self.assertEqual(headers7.sensitive(), {'X-dlp': 'data'})
def test_extract_basic_auth(self):
assert extract_basic_auth('http://:foo.bar') == ('http://:foo.bar', None)
assert extract_basic_auth('http://foo.bar') == ('http://foo.bar', None)

View File

@ -619,7 +619,7 @@ def validate_options(opts):
warnings.append(
'Using allow-unsafe-ext opens you up to potential attacks. '
'Use with great care!')
_UnsafeExtensionError.sanitize_extension = lambda x, prepend=False: x
_UnsafeExtensionError._enabled = False
return warnings, deprecation_warnings

View File

@ -209,7 +209,7 @@ class CurlFD(ExternalFD):
return False
cls.exe = path
cls._curl_version = version_tuple(parts[1])
cls._curl_version = version_tuple(parts[1], lenient=True)
return path
def _make_cmd(self, tmpfilename, info_dict):

View File

@ -420,10 +420,10 @@ class BandcampWeeklyIE(BandcampIE): # XXX: Do not subclass from concrete IE
'info_dict': {
'id': '224',
'ext': 'mp3',
'title': 'Bandcamp Weekly, 2017-04-04',
'title': 'Magic Moments, 2017-04-04',
'description': 'md5:5d48150916e8e02d030623a48512c874',
'thumbnail': 'https://f4.bcbits.com/img/9982549_0.jpg',
'series': 'Bandcamp Weekly',
'series': 'Magic Moments',
'episode_id': '224',
'release_timestamp': 1491264000,
'release_date': '20170404',
@ -440,10 +440,10 @@ class BandcampWeeklyIE(BandcampIE): # XXX: Do not subclass from concrete IE
def _real_extract(self, url):
show_id = self._match_id(url)
show_data = self._download_json(
'https://bandcamp.com/api/bcradio_api/1/get_show',
'https://bandcamp.com/api/player/2/player_data_web',
show_id, 'Downloading radio show JSON',
data=json.dumps({'id': show_id}).encode(),
headers={'Content-Type': 'application/json'})
data=json.dumps({'item_id': int(show_id), 'item_type': 'radio'}).encode(),
headers={'Content-Type': 'application/json'})['tracklist']
audio_data = show_data['compiledTrack']
stream_url = audio_data['streamUrl']

View File

@ -65,8 +65,9 @@ class PatreonBaseIE(InfoExtractor):
class PatreonIE(PatreonBaseIE):
IE_NAME = 'patreon'
_VALID_URL = r'https?://(?:www\.)?patreon\.com/(?:creation\?hid=|posts/(?:[\w-]+-)?)(?P<id>\d+)'
_VALID_URL = r'https?://(?:www\.)?patreon\.com/(?:creation\?hid=|(?:[^/?#]+/)?posts/(?:[\w-]+-)?)(?P<id>\d+)'
_TESTS = [{
# FIXME: Fails due to no description extracted
'url': 'http://www.patreon.com/creation?hid=743933',
'md5': 'e25505eec1053a6e6813b8ed369875cc',
'info_dict': {
@ -107,17 +108,17 @@ class PatreonIE(PatreonBaseIE):
'id': 'SU4fj_aEMVw',
'ext': 'mp4',
'title': 'I\'m on Patreon!',
'uploader': 'TraciJHines',
'uploader': 'Traci Oden',
'thumbnail': 're:^https?://.*$',
'upload_date': '20150211',
'description': 'md5:8af6425f50bd46fbf29f3db0fc3a8364',
'uploader_id': '@TraciHinesMusic',
'uploader_id': '@TraciOden',
'categories': ['Entertainment'],
'duration': 282,
'view_count': int,
'tags': 'count:39',
'age_limit': 0,
'channel': 'TraciJHines',
'channel': 'Traci Oden',
'channel_url': 'https://www.youtube.com/channel/UCGLim4T2loE5rwCMdpCIPVg',
'live_status': 'not_live',
'like_count': int,
@ -125,7 +126,7 @@ class PatreonIE(PatreonBaseIE):
'availability': 'public',
'channel_follower_count': int,
'playable_in_embed': True,
'uploader_url': 'https://www.youtube.com/@TraciHinesMusic',
'uploader_url': 'https://www.youtube.com/@TraciOden',
'comment_count': int,
'channel_is_verified': True,
'chapters': 'count:4',
@ -157,6 +158,7 @@ class PatreonIE(PatreonBaseIE):
},
'skip': 'Patron-only content',
}, {
# FIXME: Fails due to no description extracted
# m3u8 video (https://github.com/yt-dlp/yt-dlp/issues/2277)
'url': 'https://www.patreon.com/posts/video-sketchbook-32452882',
'info_dict': {
@ -220,6 +222,7 @@ class PatreonIE(PatreonBaseIE):
'channel_id': '2147162',
'uploader_url': 'https://www.patreon.com/yaboyroshi',
},
'skip': 'HTTP Error 401 for m3u8 request; site now requires login to play the video',
}, {
# NSFW vimeo embed URL
'url': 'https://www.patreon.com/posts/4k-spiderman-4k-96414599',
@ -242,6 +245,7 @@ class PatreonIE(PatreonBaseIE):
},
'params': {'skip_download': 'm3u8'},
'expected_warnings': ['Failed to parse XML: not well-formed'],
'skip': 'Video removed',
}, {
# multiple attachments/embeds
'url': 'https://www.patreon.com/posts/holy-wars-solos-100601977',
@ -285,6 +289,7 @@ class PatreonIE(PatreonBaseIE):
},
'params': {'getcomments': True},
}, {
# FIXME: Error: No supported media found in this post
# Inlined media in post; uses _extract_from_media_api
'url': 'https://www.patreon.com/posts/scottfalco-146966245',
'info_dict': {
@ -304,6 +309,26 @@ class PatreonIE(PatreonBaseIE):
'timestamp': 1767061800,
'upload_date': '20251230',
},
}, {
# FIXME: need to extract description
'url': 'https://www.patreon.com/Insanimate/posts/meatcanyon-in-142663524',
'md5': '132332e3bb345f75d8b471242346dee6',
'info_dict': {
'id': '142663524',
'ext': 'mp4',
'title': 'Meatcanyon in Playground',
'uploader': 'Insanimate',
'uploader_id': '2828146',
'uploader_url': 'https://www.patreon.com/Insanimate',
'channel_id': '6260877',
'channel_url': 'https://www.patreon.com/Insanimate',
'channel_follower_count': int,
'comment_count': int,
'like_count': int,
'thumbnail': 're:^https?://.*$',
'timestamp': 1762101034,
'upload_date': '20251102',
},
}]
_RETURN_TYPE = 'video'
_HTTP_HEADERS = {
@ -357,7 +382,7 @@ class PatreonIE(PatreonBaseIE):
post = self._call_api(
f'posts/{video_id}', video_id, query={
'fields[media]': 'download_url,mimetype,size_bytes,file_name',
'fields[post]': 'comment_count,content,embed,image,like_count,post_file,published_at,title,current_user_can_view',
'fields[post]': 'comment_count,content,content_teaser_text,cleaned_teaser_text,embed,image,like_count,post_file,published_at,title,current_user_can_view',
'fields[user]': 'full_name,url',
'fields[post_tag]': 'value',
'fields[campaign]': 'url,name,patron_count',
@ -367,7 +392,7 @@ class PatreonIE(PatreonBaseIE):
attributes = post['data']['attributes']
info = traverse_obj(attributes, {
'title': ('title', {str.strip}),
'description': ('content', {clean_html}),
'description': (('content', 'content_teaser_text', 'cleaned_teaser_text'), {clean_html}, any),
'thumbnail': ('image', ('large_url', 'url'), {url_or_none}, any),
'timestamp': ('published_at', {parse_iso8601}),
'like_count': ('like_count', {int_or_none}),

View File

@ -5218,12 +5218,17 @@ class _UnsafeExtensionError(Exception):
'sbv',
])
_enabled = True
def __init__(self, extension, /):
super().__init__(f'unsafe file extension: {extension!r}')
self.extension = extension
@classmethod
def sanitize_extension(cls, extension, /, *, prepend=False, _allowed_exts=()):
if not cls._enabled:
return extension
if extension is None:
return None

View File

@ -64,7 +64,7 @@ class HTTPHeaderDict(dict):
other = other.sensitive()
if isinstance(other, dict):
self.update(other)
return
return self
return NotImplemented
def __or__(self, other, /) -> typing.Self: