New albums for local library

Hi, it will be nice to have a New category on the local albums that will be New albums where to find the New albums added since the last 3 months for example. It IS very useful for me or users that often buy New music.

We’ve asked for this many times. Please make it happen.

It would be nice. In the meantime, you could use playlists. For example I have a playlist called “Q1-24” and will be making a new one on 1 April called “Q2-24”.

I love this idea. I made a quick python script to automate this task and thought I would share it here if anyone else wants to do this.

I have it making custom playlists with the naming convention of:
2024-Q1, 2024-Q2 etc…

makeplaylists.py

Summary

import os
import json
from datetime import datetime

Directories

music_directory = “/media/VOL01/clean”
playlist_directory = “/data/playlist”

Function to determine the quarter of the year

def get_quarter(date):
month = date.month
year = date.year
if 1 <= month <= 3:
return f"{year}-Q1"
elif 4 <= month <= 6:
return f"{year}-Q2"
elif 7 <= month <= 9:
return f"{year}-Q3"
elif 10 <= month <= 12:
return f"{year}-Q4"

Function to create or append to a playlist file

def add_to_playlist(playlist_name, track_info):
playlist_path = os.path.join(playlist_directory, f"{playlist_name}.json")
if os.path.exists(playlist_path):
with open(playlist_path, ‘r’) as file:
playlist = json.load(file)
else:
playlist =

playlist.append(track_info)
with open(playlist_path, 'w') as file:
    json.dump(playlist, file, indent=4)

Main script to process files

def create_playlists():
for root, dirs, files in os.walk(music_directory):
for file in files:
if file.endswith((‘.mp3’, ‘.flac’, ‘.wav’)): # Add other file formats as needed
file_path = os.path.join(root, file)
creation_time = datetime.fromtimestamp(os.path.getctime(file_path))
quarter = get_quarter(creation_time)

            # Extract album and artist from directory structure
            relative_path = os.path.relpath(root, music_directory)
            parts = relative_path.split(os.sep)
            artist = parts[0] if len(parts) > 0 else "Unknown Artist"
            album = parts[1] if len(parts) > 1 else "Unknown Album"

            # Collect track info
            track_info = {
                "service": "mpd",
                "type": "song",
                "title": os.path.splitext(file)[0],  # File name without extension
                "artist": artist,
                "album": album,
                "year": creation_time.year,
                "albumart": f"/albumart?cacheid=960&web={artist}/{album}/extralarge&path=USB%2FVOL01%2Fclean%2F{relative_path}&icon=dot-circle-o&metadata=false",
                "uri": f"music-library/USB/VOL01/clean/{relative_path}/{file}"
            }

            # Add to playlist
            add_to_playlist(quarter, track_info)

Run the script

if name == “main”:
os.makedirs(playlist_directory, exist_ok=True) # Ensure playlist directory exists
create_playlists()
print(“Playlists created successfully!”)

I might have it get the creation date from the album folder instead of the file creation date. For some reason some of my file’s dates match the release date of the album. So, I got a few 1980-Q1 and 1999-Q2 playlists.