]> git.phdru.name Git - audio-cdr-video.git/blob - audio/mk_list.py
Add `cat-playlists`
[audio-cdr-video.git] / audio / mk_list.py
1 #! /usr/bin/env python
2
3 import sys, os
4 from filetypes import is_v1, is_v2, is_mp3, is_wav, is_ogg, is_flac, is_ape
5
6 import locale
7 locale.setlocale(locale.LC_ALL, '')
8
9 import glob, re
10 mp3_file = re.compile("^([^0-9]*)([0-9]+)(.*)$")
11
12
13 dir = glob.glob("*")
14 if not dir:
15    sys.exit("Dir is empty")
16
17
18 new_list = []
19 for entry in dir:
20    if not os.path.isfile(entry):
21       continue
22
23    lower = entry.lower()
24    if not is_v1(entry) and not is_v2(entry) and not is_mp3(entry) and \
25          not is_wav(entry) and not is_ogg(entry) and \
26          not is_flac(entry) and not is_ape(entry) and \
27          not lower.endswith(".mp3") and not lower.endswith(".wav") and \
28          not lower.endswith(".ogg") and not lower.endswith(".flac") and \
29          not lower.endswith(".ape"):
30       continue
31
32    match = mp3_file.match(entry)
33    if match:
34       name = match.group(1)
35       number = match.group(2)
36       suffix = match.group(3)
37
38       new_list.append((int(number), locale.strxfrm(name), name, number, suffix))
39    else:
40       number = ''
41       name, suffix = os.path.splitext(entry)
42       new_list.append((number, locale.strxfrm(name), name, number, suffix))
43
44 if not new_list:
45    sys.exit()
46
47 new_list.sort()
48
49 outfile = open("PlayList.m3u", 'w')
50 for i, _xname, name, number, suffix in new_list:
51    outfile.write("%s%s%s\n" % (name, number, suffix))
52 outfile.close()