mirror of
https://github.com/ytdl-org/youtube-dl
synced 2024-12-23 04:30:10 +09:00
[youtube] Simplify cache_dir code (#1529)
This commit is contained in:
parent
4f8bf17f23
commit
c38b1e776d
@ -113,12 +113,6 @@ def parseOpts(overrideArguments=None):
|
|||||||
pass
|
pass
|
||||||
return opts
|
return opts
|
||||||
|
|
||||||
xdg_cache_home = os.environ.get('XDG_CACHE_HOME')
|
|
||||||
if xdg_cache_home:
|
|
||||||
userCacheDir = os.path.join(xdg_cache_home, 'youtube-dl')
|
|
||||||
else:
|
|
||||||
userCacheDir = os.path.join(os.path.expanduser('~'), '.cache', 'youtube-dl')
|
|
||||||
|
|
||||||
max_width = 80
|
max_width = 80
|
||||||
max_help_position = 80
|
max_help_position = 80
|
||||||
|
|
||||||
@ -174,7 +168,7 @@ def parseOpts(overrideArguments=None):
|
|||||||
general.add_option('--proxy', dest='proxy', default=None, help='Use the specified HTTP/HTTPS proxy', metavar='URL')
|
general.add_option('--proxy', dest='proxy', default=None, help='Use the specified HTTP/HTTPS proxy', metavar='URL')
|
||||||
general.add_option('--no-check-certificate', action='store_true', dest='no_check_certificate', default=False, help='Suppress HTTPS certificate validation.')
|
general.add_option('--no-check-certificate', action='store_true', dest='no_check_certificate', default=False, help='Suppress HTTPS certificate validation.')
|
||||||
general.add_option(
|
general.add_option(
|
||||||
'--cache-dir', dest='cachedir', default=userCacheDir,
|
'--cache-dir', dest='cachedir', default=get_cachedir(),
|
||||||
help='Location in the filesystem where youtube-dl can store downloaded information permanently. %default by default')
|
help='Location in the filesystem where youtube-dl can store downloaded information permanently. %default by default')
|
||||||
general.add_option(
|
general.add_option(
|
||||||
'--no-cache-dir', action='store_const', const=None, dest='cachedir',
|
'--no-cache-dir', action='store_const', const=None, dest='cachedir',
|
||||||
|
@ -27,6 +27,7 @@ from ..utils import (
|
|||||||
compat_str,
|
compat_str,
|
||||||
|
|
||||||
clean_html,
|
clean_html,
|
||||||
|
get_cachedir,
|
||||||
get_element_by_id,
|
get_element_by_id,
|
||||||
ExtractorError,
|
ExtractorError,
|
||||||
unescapeHTML,
|
unescapeHTML,
|
||||||
@ -421,12 +422,7 @@ class YoutubeIE(YoutubeBaseInfoExtractor, SubtitlesInfoExtractor):
|
|||||||
# Read from filesystem cache
|
# Read from filesystem cache
|
||||||
func_id = '%s_%s_%d' % (player_type, player_id, slen)
|
func_id = '%s_%s_%d' % (player_type, player_id, slen)
|
||||||
assert os.path.basename(func_id) == func_id
|
assert os.path.basename(func_id) == func_id
|
||||||
xdg_cache_home = os.environ.get('XDG_CACHE_HOME')
|
cache_dir = get_cachedir(self._downloader.params)
|
||||||
if xdg_cache_home:
|
|
||||||
userCacheDir = os.path.join(xdg_cache_home, 'youtube-dl')
|
|
||||||
else:
|
|
||||||
userCacheDir = os.path.join(os.path.expanduser('~'), '.cache', 'youtube-dl')
|
|
||||||
cache_dir = self._downloader.params.get('cachedir', userCacheDir)
|
|
||||||
|
|
||||||
cache_enabled = cache_dir is not None
|
cache_enabled = cache_dir is not None
|
||||||
if cache_enabled:
|
if cache_enabled:
|
||||||
|
@ -824,3 +824,9 @@ def intlist_to_bytes(xs):
|
|||||||
return ''.join([chr(x) for x in xs])
|
return ''.join([chr(x) for x in xs])
|
||||||
else:
|
else:
|
||||||
return bytes(xs)
|
return bytes(xs)
|
||||||
|
|
||||||
|
|
||||||
|
def get_cachedir(params={}):
|
||||||
|
cache_root = os.environ.get('XDG_CACHE_HOME',
|
||||||
|
os.path.expanduser('~/.cache'))
|
||||||
|
return params.get('cachedir', os.path.join(cache_root, 'youtube-dl'))
|
||||||
|
Loading…
Reference in New Issue
Block a user