infinity-player

infinite jukebox clone using librosa
git clone https://git.ce9e.org/infinity-player.git

commit
11d632c98bc86f41a54985fd0436d04874155b16
parent
329ce6fc8d157acbf9e35b6c1d3ca6d9c965aa9b
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2025-03-06 10:37
refactor: use pathlib

Diffstat

M player.py 14 +++++++-------

1 files changed, 7 insertions, 7 deletions


diff --git a/player.py b/player.py

@@ -2,9 +2,9 @@
    2     2 
    3     3 import argparse
    4     4 import gzip
    5    -1 import os
    6     5 import pickle
    7     6 import shutil
   -1     7 from pathlib import Path
    8     8 from random import random
    9     9 
   10    10 import librosa
@@ -12,9 +12,9 @@ import numpy
   12    12 import soundcard
   13    13 from PIL import Image
   14    14 
   15    -1 BASE_DIR = os.path.dirname(os.path.abspath(__file__))
   -1    15 BASE_DIR = Path(__file__).parent
   16    16 
   17    -1 with open(os.path.join(BASE_DIR, 'timbre.pickle'), 'rb') as fh:
   -1    17 with open(BASE_DIR / 'timbre.pickle', 'rb') as fh:
   18    18     TIMBRE_PATTERNS = pickle.load(fh)
   19    19 
   20    20 
@@ -80,9 +80,9 @@ def analyze(y, sample_rate, beat_frames, bins_per_octave=12, n_octaves=7):
   80    80 def load(filename, *, force=False):
   81    81     y, sample_rate = librosa.load(filename, mono=False)
   82    82 
   83    -1     fn_inf = filename + '.inf'
   84    -1     if not force and os.path.exists(fn_inf):
   85    -1         with gzip.open(fn_inf, 'rb') as fh:
   -1    83     path_inf = Path(filename + '.inf')
   -1    84     if not force and path_inf.exists():
   -1    85         with gzip.open(path_inf, 'rb') as fh:
   86    86             beat_frames, jumps = pickle.load(fh)
   87    87     else:
   88    88         print('Analyzing…')
@@ -90,7 +90,7 @@ def load(filename, *, force=False):
   90    90         tempo, beat_frames = librosa.beat.beat_track(y=y1, sr=sample_rate1)
   91    91         jumps = analyze(y1, sample_rate1, beat_frames)
   92    92 
   93    -1         with gzip.open(fn_inf, 'wb') as fh:
   -1    93         with gzip.open(path_inf, 'wb') as fh:
   94    94             pickle.dump((beat_frames, jumps), fh)
   95    95 
   96    96     return y, sample_rate, beat_frames, jumps