I realized having to host this potentially indefinitely might not be the best idea, so I am going to shut down this gitea instance eventually.
You’ll have time, at least until the end of 2022, probably longer, but please just get all your stuff somewhere safe in case we ever disappear.
beets plugin to update m3u playlists when renaming/importing
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.7 KiB

from beets.plugins import BeetsPlugin
from beets import config
import os
rename_cache = os.path.expanduser('~/beets_mv3u_renames')
music_root = config['directory'].get()
class MV3U(BeetsPlugin):
def __init__(self):
super(MV3U, self).__init__()
self.register_listener('item_moved', self.add_rename)
self.register_listener('item_copied', self.add_rename)
self.register_listener('import_task_created', self.clear_persistence)
#self.register_listener('import', self.mv3u)
This has been moved to a standalone program because I felt like it. ¯\_(ツ)_/¯
def mv3u(self):
playlist_dir = self.config['playlists'].get()
if not playlist_dir:
for pl in os.listdir(playlist_dir):
pl = os.path.join(playlist_dir, pl)
p2 = None
with open(pl, 'r') as p:
p2 = [l.replace(src, dst) for l in p]
with open(pl, 'w') as p:
#print(f'Changed entry {src} to {dst} in {pl}')
def clear_persistence(self, task, session):
if os.path.isfile(rename_cache):
def add_rename(self, item):
src = item.path.decode().replace(music_root, '')
dst = item.destination().decode().replace(music_root, '')
with open(rename_cache, 'a') as cache:
def mv3u(self, lib, paths):
def read_renames() -> dict:
with open(rename_cache) as cache:
return dict([line.rstrip('\n').split('\t\t') for line in cache])