Open denizoezmen opened 3 years ago
It's more than feasible, gallery-dl has done that by default (other places're used in order too).
User can change it using --cache-dir
Thank you for the suggestion. However, I wouldn't classify this as a solution, since usage of the correct (platform-depent) directories intended for application data should be the default behaviour.
if params.get('cache_dir') is None and platform == 'Windows':
params['cache_dir'] = ...
This is not the intended use of site.userbase
and it may not always point to the appdata. Better to expand the relevant env vars
That said, I don't know if this change is justified. When a user updates to a version with this change, the old .cache
directory will remain, and even --rm-cache-dir
will no longer remove it. Additional checks may need to be done to handle this
OTOH compat_getenv('APPDATA')
won't find ~/.cache
.
I share the concern about the pain of moving the default cache to a new location. Perhaps the old default should be maintained if present?
So
--- old/youtube-dl/youtube_dl/cache.py
+++ new/youtube-dl/youtube_dl/cache.py
@@ -19,11 +19,26 @@
def __init__(self, ydl):
self._ydl = ydl
- def _get_root_dir(self):
+ def _get_old_root_dir(self):
res = self._ydl.params.get('cachedir')
if res is None:
cache_root = compat_getenv('XDG_CACHE_HOME', '~/.cache')
res = os.path.join(cache_root, 'youtube-dl')
return expand_path(res)
+
+ def _get_root_dir(self):
+ res = self._get_old_root_dir()
+ if os.path.exists(res):
+ return res
+ res = self._ydl.params.get('cachedir')
+ if res is None:
+ # LOCALAPPDATA "new" in Windows 7
+ res = compat_getenv('APPDATA')
+ if res is not None:
+ # assumption: setting APPDATA means this is the answer
+ return os.path.join(res, 'youtube-dl', 'cache')
+ res = compat_getenv('XDG_CACHE_HOME', '~/.cache')
+ res = os.path.join(res, 'youtube-dl')
+ return expand_path(res)
def _get_cache_fn(self, section, key, dtype):
Checklist
Description
When downloading files from certain URLs on the Windows platform, youtube-dl (or one of its libraries?) will generate a ".cache" directory directly in the root of the user's profile directory (e.g.
C:\Users\<username>\.cache
).Example:
youtube-dl --no-check-certificate https://soundcloud.com/laurence_chapman/heavens-vault
will create a file called
C:\Users\<username>\.cache\youtube-dl\soundcloud\client_id.json
Unlike on *nix platforms, file and directory names starting with a dot are not hidden by default on the Windows platform. Using multiple applications that exhibit this behaviour thus clutters up the user's profile directory.
On Windows, application-specific data should usually be placed in the profile directory's AppData\Roaming subdirectory (%APPDATA%) for "permanent" data that would also be considered in a roaming profile, or the AppData\Local subdirectory (%LOCALAPPDATA%) for mere temporary files.
Please consider using these directories instead (if feasible).