-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathsong_scan.py
29 lines (22 loc) · 841 Bytes
/
song_scan.py
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
27
28
29
import os
def get(base_dir, opt_dir = ''):
folders = []
songs = []
final_dir = os.path.join(base_dir, opt_dir)
for dirs in os.listdir(final_dir):
if not dirs.startswith('.'):
if os.path.isdir(os.path.join(final_dir, dirs)):
folders.append({'name':dirs, 'href':'/ls/' + os.path.join(opt_dir, dirs),'playable':False})
elif _is_audio_file(dirs):
songs.append({'name':dirs, 'file_path':os.path.join(opt_dir, dirs), 'href':'/player/play', 'addhref':'/player/add','playable':True})
folders.sort()
songs.sort()
return folders + songs
pass
def _is_audio_file(name):
valid_ext = ['mp3', 'm4a', 'ape', 'wma', 'flac']
n, ext = os.path.splitext(name)
if valid_ext.count(ext[1:].lower()) != 0:
return True
return False
pass