-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
26 lines (21 loc) · 755 Bytes
/
utils.py
File metadata and controls
26 lines (21 loc) · 755 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
"""File utilities and helpers"""
import os
import os.path
import random
def get_filenames(directory):
"""Reads all mp3 files from given directory
Returns dictionary with numbers from 1 as keys.
"""
results = []
for dirpath, dirnames, filenames in os.walk(directory):
for filename in filenames:
if not filename.endswith('mp3'):
continue
results.append(os.path.join(dirpath, filename))
return {i: path for i, path in enumerate(results, start=1)}
def shuffle(filenames, seed=None):
"""Shuffles filenames and assigns them new keys"""
values = list(filenames.values())
random.seed(seed)
random.shuffle(values)
return {i: v for i, v in enumerate(values, start=1)}