From 1c6fd5b4813b17ab8a696d651f0357ab5b8c98ed Mon Sep 17 00:00:00 2001 From: Shuto Tamaoka Date: Sat, 23 Mar 2024 20:54:32 +0900 Subject: [PATCH 1/2] Use XDG Base Directory for storing data --- settings.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/settings.py b/settings.py index 66b283b6..ca29f0cc 100644 --- a/settings.py +++ b/settings.py @@ -406,8 +406,14 @@ def log_ignored_line(line_number, message): data_dir = os.path.normpath('./data') else: print("Running in non-portable mode") - settings_dir = os.path.expanduser(os.path.normpath("~/.youtube-local")) - data_dir = os.path.expanduser(os.path.normpath("~/.youtube-local/data")) + config_dir = os.path.normpath('~/.config/youtube-local') + + if os.getenv('XDG_CONFIG_HOME') != None: + config_dir = os.path.normpath( + os.path.join(os.getenv('XDG_CONFIG_HOME'), 'youtube-local')) + + settings_dir = os.path.expanduser(config_dir) + data_dir = os.path.expanduser(os.path.join(config_dir, 'data')) if not os.path.exists(settings_dir): os.makedirs(settings_dir) From ac59f79ec90bb0901d10e8a14ba5d41b1c6425b0 Mon Sep 17 00:00:00 2001 From: Shuto Tamaoka Date: Sun, 9 Jun 2024 22:08:42 +0900 Subject: [PATCH 2/2] fix: read old ~/.youtube-local path for storing data - Read both XDG directory and old ~/.youtube-local directory for storing data - Use XDG_DATA_HOME as XDG directory --- settings.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/settings.py b/settings.py index ca29f0cc..ea3d62b5 100644 --- a/settings.py +++ b/settings.py @@ -406,14 +406,20 @@ def log_ignored_line(line_number, message): data_dir = os.path.normpath('./data') else: print("Running in non-portable mode") - config_dir = os.path.normpath('~/.config/youtube-local') + settings_dir = os.path.expanduser(os.path.normpath('~/.local/share/youtube-local')) + old_settings_dir = os.path.expanduser(os.path.normpath('~/.youtube-local')) - if os.getenv('XDG_CONFIG_HOME') != None: - config_dir = os.path.normpath( - os.path.join(os.getenv('XDG_CONFIG_HOME'), 'youtube-local')) + # use XDG_DATA_HOME variable if defined + if os.getenv('XDG_DATA_HOME'): + settings_dir = os.path.normpath( + os.path.join(os.getenv('XDG_DATA_HOME'), 'youtube-local')) - settings_dir = os.path.expanduser(config_dir) - data_dir = os.path.expanduser(os.path.join(config_dir, 'data')) + # use old ~/.youtube-local directory if settings.txt is found + if not os.path.exists(os.path.join(settings_dir, 'settings.txt')): + if os.path.exists(os.path.join(old_settings_dir, 'settings.txt')): + settings_dir = old_settings_dir + + data_dir = os.path.join(settings_dir, 'data') if not os.path.exists(settings_dir): os.makedirs(settings_dir)