mirror of
https://github.com/migatu/conjurer.git
synced 2026-07-17 15:22:10 +00:00
63 lines
2.1 KiB
Python
63 lines
2.1 KiB
Python
# This Python file uses the following encoding: utf-8
|
|
"""This module contains utility scripts used by musi radiostation Conjurer"""
|
|
import time
|
|
import re
|
|
import os
|
|
from mutagen.easyid3 import EasyID3
|
|
from mutagen.mp3 import MP3
|
|
|
|
def update_metadata(base_folder):
|
|
for root, _, files in os.walk(base_folder):
|
|
for file in files:
|
|
if file.endswith('.mp3'):
|
|
full_path = os.path.join(root, file)
|
|
try:
|
|
print(f"Processing {full_path}")
|
|
# Parse metadata from the filename or path
|
|
# For example, assume filenames are in the format "Artist - Title.mp3"
|
|
filename = os.path.splitext(file)[0]
|
|
parts = filename.split(' - ')
|
|
if len(parts) == 2:
|
|
artist, title = parts
|
|
else:
|
|
artist = 'Unknown Artist'
|
|
title = filename
|
|
|
|
# Load the MP3 file
|
|
audio = MP3(full_path, ID3=EasyID3)
|
|
|
|
# Update metadata
|
|
audio['title'] = title
|
|
audio['artist'] = artist
|
|
|
|
# Save changes
|
|
audio.save()
|
|
print(f"Updated metadata: Artist = {artist}, Title = {title}")
|
|
except Exception as e:
|
|
print(f"Error processing {file}: {e}")
|
|
|
|
base_folder = 'path/to/your/folder' # Update with the path to your folder
|
|
#update_metadata(base_folder)
|
|
|
|
NAME = "/home/pi/Conjurer/persistence.log"
|
|
|
|
def print_top():
|
|
"""
|
|
Prints the top 65 lines from a file specified by the NAME variable.
|
|
"""
|
|
while True:
|
|
line = ""
|
|
buffer = ""
|
|
with open(NAME, "r", encoding="utf-8") as f:
|
|
for _ in range (45):
|
|
line = f.readline()
|
|
if re.match(".*mp3", line):
|
|
buffer += line
|
|
print("=====================================")
|
|
print(buffer)
|
|
print("=====================================")
|
|
time.sleep(180)
|
|
|
|
if __name__ == "__main__":
|
|
print_top()
|