From 1d173aa45a8a65f1c51581b1192d0f485881de36 Mon Sep 17 00:00:00 2001 From: neingeist Date: Mon, 6 Dec 2021 23:31:08 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=B7=F0=9F=8F=BB=E2=80=8D=E2=99=80?= =?UTF-8?q?=EF=B8=8F=20make=20sources=20something=20to=20configure?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.py.example | 25 ++++++++++++++----------- prolefeeder.py | 3 +-- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/config.py.example b/config.py.example index 094d1f0..8ed8e28 100644 --- a/config.py.example +++ b/config.py.example @@ -18,16 +18,19 @@ def mp3_sources(data_dir, pattern, kbits): length = timedelta(minutes=size / (1000*kbits/8) / 60) return length - # Get a sorted list of all source files with start time and length - sources = [] - for fn in os.listdir(data_dir): - try: - start_time = start_time_for_source_fn(fn) - length = length_for_source_fn(fn) - sources.append({'fn': os.path.join(data_dir, fn), 'start_time': start_time, 'length': length}) - except ValueError: - pass - return sources + def get_sources(): + # Get a sorted list of all source files with start time and length + sources = [] + for fn in os.listdir(data_dir): + try: + start_time = start_time_for_source_fn(fn) + length = length_for_source_fn(fn) + sources.append({'fn': os.path.join(data_dir, fn), 'start_time': start_time, 'length': length}) + except ValueError: + pass + return sources + + return get_sources class Config: @@ -43,7 +46,7 @@ class Config: # Here's the interesting part: configuring the source. # - # We need to return a list of dicts of source files with metadata, e.g. + # We need to return a function that returns a list of dicts of source files with metadata, e.g. # [ {"fn": "/path/to/foo-20:01.mp3", "start_time": datetime(...), "length": timedelta(hours=1)} ] data_dir = os.environ.get('DATA_DIR') or '/var/tmp/prolefeeder-test-data' diff --git a/prolefeeder.py b/prolefeeder.py index 2167c49..d2352c5 100644 --- a/prolefeeder.py +++ b/prolefeeder.py @@ -87,8 +87,7 @@ def prepare_download(form): """Prepare a download given the user's request form""" # Get a sorted list of all source files with start time and length - sources = sorted(Config.SOURCES, key=lambda s: s['start_time']) - print(sources) + sources = sorted(Config.SOURCES(), key=lambda s: s['start_time']) # Only interested in the source files from the start file start_index = None