[jsinterp, extractor/youtube] Minor fixes

This commit is contained in:
pukkandan 2022-08-30 17:23:59 +05:30
parent 5135ed3d4a
commit d81ba7d491
No known key found for this signature in database
GPG key ID: 7EEE9E1E817D0A39
5 changed files with 30 additions and 14 deletions

View file

@ -51,15 +51,15 @@ class Cache:
tb = traceback.format_exc()
self._ydl.report_warning(f'Writing cache to {fn!r} failed: {tb}')
def _validate(self, data, after):
def _validate(self, data, min_ver):
version = traverse_obj(data, 'yt-dlp_version')
if not version: # Backward compatibility
data, version = {'data': data}, '2022.08.19'
if not after or version_tuple(version) > version_tuple(after):
if not min_ver or version_tuple(version) >= version_tuple(min_ver):
return data['data']
self._ydl.write_debug(f'Discarding old cache from version {version} (need {after})')
self._ydl.write_debug(f'Discarding old cache from version {version} (needs {min_ver})')
def load(self, section, key, dtype='json', default=None, *, after=None):
def load(self, section, key, dtype='json', default=None, *, min_ver=None):
assert dtype in ('json',)
if not self.enabled:
@ -70,7 +70,7 @@ class Cache:
try:
with open(cache_fn, encoding='utf-8') as cachef:
self._ydl.write_debug(f'Loading {section}.{key} from cache')
return self._validate(json.load(cachef), after)
return self._validate(json.load(cachef), min_ver)
except (ValueError, KeyError):
try:
file_size = os.path.getsize(cache_fn)