Rename patches to patch
This commit is contained in:
1 parent
19c301ad76
commit
4f9e0bf949
1 file changed
@@ -0,0 +1,42 @@
|
||||
from yt_dlp import YoutubeDL
|
||||
|
||||
class PatchedYoutubeDL(YoutubeDL):
|
||||
|
||||
def _sanitize_thumbnails(self, info_dict):
|
||||
thumbnails = info_dict.get('thumbnails')
|
||||
if thumbnails is None:
|
||||
thumbnail = info_dict.get('thumbnail')
|
||||
if thumbnail:
|
||||
info_dict['thumbnails'] = thumbnails = [{'url': thumbnail}]
|
||||
if not thumbnails:
|
||||
return
|
||||
|
||||
|
||||
def check_thumbnails(thumbnails):
|
||||
for t in thumbnails:
|
||||
self.to_screen(f'[info] Testing thumbnail {t["id"]}')
|
||||
try:
|
||||
self.urlopen(HEADRequest(t['url']))
|
||||
except network_exceptions as err:
|
||||
self.to_screen(f'[info] Unable to connect to thumbnail {t["id"]} URL {t["url"]!r} - {err}. Skipping...')
|
||||
continue
|
||||
yield t
|
||||
|
||||
|
||||
self._sort_thumbnails(thumbnails)
|
||||
for i, t in enumerate(thumbnails):
|
||||
if t.get('id') is None:
|
||||
t['id'] = str(i)
|
||||
if t.get('width') and t.get('height'):
|
||||
t['resolution'] = '%dx%d' % (t['width'], t['height'])
|
||||
t['url'] = sanitize_url(t['url'])
|
||||
|
||||
|
||||
if self.params.get('check_thumbnails') is True:
|
||||
info_dict['thumbnails'] = LazyList(check_thumbnails(thumbnails[::-1]), reverse=True)
|
||||
else:
|
||||
info_dict['thumbnails'] = thumbnails
|
||||
|
||||
|
||||
YoutubeDL.__unpatched___sanitize_thumbnails = YoutubeDL._sanitize_thumbnails
|
||||
YoutubeDL._sanitize_thumbnails = PatchedYoutubeDL._sanitize_thumbnails
|
||||
Reference in new issue
Block a user