utils.py
The utils module contains several useful functions that are used within the package.
get_file_path(track: Track, ext: str) -> Path
ยค
Generate a file path using a Track object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
track |
Track |
A Track object. |
required |
ext |
str |
The file extension to be used. |
required |
Returns:
| Type | Description |
|---|---|
Path |
A Path object containing the track path. |
Source code in deethon/utils.py
def get_file_path(track: Track, ext: str) -> Path:
"""
Generate a file path using a Track object.
Args:
track: A Track object.
ext: The file extension to be used.
Returns:
A Path object containing the track path.
"""
forbidden_chars = dict((ord(char), None) for char in r'\/*?:"<>|')
album_artist = track.album.artist.name.translate(forbidden_chars)
album_title = track.album.title.translate(forbidden_chars)
std_dir = "Songs"
dir_path = Path(std_dir, album_artist, album_title)
dir_path.mkdir(parents=True, exist_ok=True)
file_name = f"{track.number:02} {track.title}.{ext}"
return dir_path / file_name.translate(forbidden_chars)