-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocal.py
More file actions
35 lines (30 loc) · 1.3 KB
/
local.py
File metadata and controls
35 lines (30 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env python3
# Checks latest release for each artist.
# By DenickM 20210724
from pathlib import Path
from typing import Tuple, List
MUSIC_DIR = Path().home() / 'muziek'
def get_local_releases(artist_path: Path) -> List[Tuple[str, int]]:
releases = []
for local_release in artist_path.iterdir():
album = local_release.stem
if len(album) < 5 or not (album[:4].isnumeric() and album[4] == ' '):
# print(f'unrecognized year for local album {album}')
pass
else:
year, name = album.split(' ', maxsplit=1)
# Locally we like to write 'st' for a self title album. Change it to the full artist name
if name == 'st':
name = artist_path.stem
# Locally we would like to write multiple artists in the name and then a dash and the album name. So strip the extra artists:
if ' - ' in name:
name = name.split(' - ')[1]
# Remove (Remastered) suffix
name = name.removesuffix(' (Remastered)')
releases.append((name, int(year)))
return releases
def get_latest_local_release(artist_path: Path) -> Tuple[str, int]:
try:
return sorted(get_local_releases(artist_path), key=lambda x: x[1])[-1]
except IndexError:
return ('', 0)