👷🏻‍♀️ make sources something to configure

master
neingeist 3 years ago
parent 40e1f51faf
commit 1d173aa45a

@ -18,16 +18,19 @@ def mp3_sources(data_dir, pattern, kbits):
length = timedelta(minutes=size / (1000*kbits/8) / 60) length = timedelta(minutes=size / (1000*kbits/8) / 60)
return length return length
# Get a sorted list of all source files with start time and length def get_sources():
sources = [] # Get a sorted list of all source files with start time and length
for fn in os.listdir(data_dir): sources = []
try: for fn in os.listdir(data_dir):
start_time = start_time_for_source_fn(fn) try:
length = length_for_source_fn(fn) start_time = start_time_for_source_fn(fn)
sources.append({'fn': os.path.join(data_dir, fn), 'start_time': start_time, 'length': length}) length = length_for_source_fn(fn)
except ValueError: sources.append({'fn': os.path.join(data_dir, fn), 'start_time': start_time, 'length': length})
pass except ValueError:
return sources pass
return sources
return get_sources
class Config: class Config:
@ -43,7 +46,7 @@ class Config:
# Here's the interesting part: configuring the source. # 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)} ] # [ {"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' data_dir = os.environ.get('DATA_DIR') or '/var/tmp/prolefeeder-test-data'

@ -87,8 +87,7 @@ def prepare_download(form):
"""Prepare a download given the user's request form""" """Prepare a download given the user's request form"""
# Get a sorted list of all source files with start time and length # Get a sorted list of all source files with start time and length
sources = sorted(Config.SOURCES, key=lambda s: s['start_time']) sources = sorted(Config.SOURCES(), key=lambda s: s['start_time'])
print(sources)
# Only interested in the source files from the start file # Only interested in the source files from the start file
start_index = None start_index = None

Loading…
Cancel
Save