654
|
1 #!/usr/bin/env python
|
|
2 # -*- coding: utf-8 -*-
|
|
3
|
|
4 import argparse
|
|
5 import os
|
655
|
6 import shutil
|
654
|
7 import subprocess
|
|
8 import sys
|
|
9 import tempfile
|
|
10 from which import which
|
|
11
|
|
12 here = os.path.dirname(os.path.realpath(__file__))
|
|
13 string = (str, unicode)
|
|
14
|
|
15 def main(args=sys.argv[1:]):
|
|
16
|
|
17 dlna = which('minidlna')
|
|
18 assert dlna
|
|
19
|
|
20 parser = argparse.ArgumentParser(description=__doc__)
|
|
21 parser.add_argument('--name', dest='name', default='protest servant',
|
|
22 help="friendly name")
|
|
23 parser.add_argument('--db-dir', dest='db_dir',
|
|
24 default=os.path.join(os.environ['HOME'], 'minidlna'),
|
|
25 help='db directory')
|
|
26 parser.add_argument('-p', '--port', dest='port', default=8200, type=int,
|
|
27 help="port")
|
|
28 parser.add_argument('audio', nargs='+')
|
|
29 options = parser.parse_args(args)
|
|
30
|
|
31 lines = [('friendly_name', options.name),
|
|
32 ('db_dir', options.db_dir),
|
|
33 ('log_dir', options.db_dir),
|
|
34 ('inotify', 'yes'),
|
|
35 ('enable_tivo', 'yes')]
|
|
36 lines.extend([('media_dir', 'A,{}'.format(os.path.abspath(d)))
|
|
37 for d in options.audio])
|
|
38 config = '\n'.join(['{}={}'.format(*line) for line in lines])
|
|
39 print (config)
|
|
40
|
|
41 fd, name = tempfile.mkstemp()
|
|
42 os.write(fd, config)
|
|
43 os.close(fd)
|
|
44
|
|
45 command = [dlna, '-f', name, '-d', '-p', str(options.port)]
|
|
46 print (subprocess.list2cmdline(command))
|
|
47 subprocess.check_call(command)
|
|
48
|
|
49 os.remove(name)
|
655
|
50 shutil.rmtree(options.db_dir)
|
654
|
51
|
|
52 if __name__ == '__main__':
|
|
53 main()
|