layed out config structure and started implementing the path manager with the temp path and music path.
This commit is contained in:
parent
86e58dcfb4
commit
ba3deb24e3
0
src/music_kraken/utils/config/__init__.py
Normal file
0
src/music_kraken/utils/config/__init__.py
Normal file
3
src/music_kraken/utils/path_manager/__init__.py
Normal file
3
src/music_kraken/utils/path_manager/__init__.py
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
from .locations import Locations
|
||||||
|
|
||||||
|
LOCATIONS = Locations()
|
17
src/music_kraken/utils/path_manager/locations.py
Normal file
17
src/music_kraken/utils/path_manager/locations.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
from pathlib import Path
|
||||||
|
import os
|
||||||
|
|
||||||
|
import tempfile
|
||||||
|
|
||||||
|
from .music_directory import get_music_directory
|
||||||
|
|
||||||
|
|
||||||
|
class Locations:
|
||||||
|
def __init__(self, temp_folder_name: os.PathLike = "music-downloader"):
|
||||||
|
self.TEMP_DIRECTORY = Path(tempfile.gettempdir(), temp_folder_name)
|
||||||
|
self.TEMP_DIRECTORY.mkdir(exist_ok=True)
|
||||||
|
|
||||||
|
self.MUSIC_DIRECTORY = get_music_directory()
|
||||||
|
|
||||||
|
def get_log_file(self, file_name: os.PathLike) -> Path:
|
||||||
|
return Path(self.TEMP_DIRECTORY, file_name)
|
37
src/music_kraken/utils/path_manager/music_directory.py
Normal file
37
src/music_kraken/utils/path_manager/music_directory.py
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
from pathlib import Path
|
||||||
|
from sys import platform
|
||||||
|
import logging
|
||||||
|
from os.path import expandvars
|
||||||
|
|
||||||
|
import configparser
|
||||||
|
|
||||||
|
DEFAULT_MUSIC_DIRECTORY = Path(Path.home(), "Music")
|
||||||
|
|
||||||
|
|
||||||
|
def get_xdg_music_directory() -> Path:
|
||||||
|
# XDG_USER_DIRS_FILE reference: https://freedesktop.org/wiki/Software/xdg-user-dirs/
|
||||||
|
xdg_user_dirs_file = Path(Path.home(), ".config", "user-dirs.dirs")
|
||||||
|
|
||||||
|
try:
|
||||||
|
with open(xdg_user_dirs_file, 'r') as f:
|
||||||
|
data = "[XDG_USER_DIRS]\n" + f.read()
|
||||||
|
config = configparser.ConfigParser(allow_no_value=True)
|
||||||
|
config.read_string(data)
|
||||||
|
xdg_config = config['XDG_USER_DIRS']
|
||||||
|
return Path(expandvars(xdg_config['xdg_music_dir'].strip('"')))
|
||||||
|
|
||||||
|
except (FileNotFoundError, KeyError) as e:
|
||||||
|
logging.warning(
|
||||||
|
f"Missing file or No entry found for \"xdg_music_dir\" in: \"{xdg_user_dirs_file}\".\n"
|
||||||
|
f"Will fallback on default \"$HOME/Music\"."
|
||||||
|
)
|
||||||
|
logging.debug(str(e))
|
||||||
|
|
||||||
|
return DEFAULT_MUSIC_DIRECTORY
|
||||||
|
|
||||||
|
|
||||||
|
def get_music_directory() -> Path:
|
||||||
|
if platform != "linux":
|
||||||
|
return DEFAULT_MUSIC_DIRECTORY
|
||||||
|
|
||||||
|
return get_xdg_music_directory()
|
@ -37,12 +37,14 @@ def get_random_message() -> str:
|
|||||||
|
|
||||||
|
|
||||||
ID_BITS: int = 64
|
ID_BITS: int = 64
|
||||||
ID_RANGE: Tuple[int] = 0, 2**ID_BITS
|
ID_RANGE: Tuple[int, int] = (0, int(2**ID_BITS))
|
||||||
|
|
||||||
TEMP_DIR = Path(tempfile.gettempdir(), "music-downloader")
|
TEMP_DIR = Path(tempfile.gettempdir(), "music-downloader")
|
||||||
TEMP_DIR.mkdir(exist_ok=True)
|
TEMP_DIR.mkdir(exist_ok=True)
|
||||||
LOG_PATH = Path(TEMP_DIR, "download_logs.log")
|
LOG_PATH = Path(TEMP_DIR, "download_logs.log")
|
||||||
|
|
||||||
|
MUSIC_DIR: Path = Path(os.path.expanduser("~"), "Music")
|
||||||
|
|
||||||
|
|
||||||
# configure logger default
|
# configure logger default
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
@ -67,8 +69,7 @@ DOWNLOAD_LOGGER = logging.getLogger("download")
|
|||||||
TAGGING_LOGGER = logging.getLogger("tagging")
|
TAGGING_LOGGER = logging.getLogger("tagging")
|
||||||
CODEX_LOGGER = logging.getLogger("codex")
|
CODEX_LOGGER = logging.getLogger("codex")
|
||||||
|
|
||||||
MUSIC_DIR: Path = Path(os.path.expanduser("~"), "Music")
|
NOT_A_GENRE_REGEX: Tuple[str] = (
|
||||||
NOT_A_GENRE_REGEX: List[str] = (
|
|
||||||
r'^\.', # is hidden/starts with a "."
|
r'^\.', # is hidden/starts with a "."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user