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")
|
656
|
28 parser.add_argument('-v', '--videos', dest='videos', nargs='+',
|
|
29 help="videos")
|
654
|
30 parser.add_argument('audio', nargs='+')
|
|
31 options = parser.parse_args(args)
|
|
32
|
|
33 lines = [('friendly_name', options.name),
|
|
34 ('db_dir', options.db_dir),
|
|
35 ('log_dir', options.db_dir),
|
|
36 ('inotify', 'yes'),
|
|
37 ('enable_tivo', 'yes')]
|
|
38 lines.extend([('media_dir', 'A,{}'.format(os.path.abspath(d)))
|
|
39 for d in options.audio])
|
656
|
40 lines.extend([('media_dir', 'V,{}'.format(os.path.abspath(d)))
|
|
41 for d in options.audio])
|
654
|
42 config = '\n'.join(['{}={}'.format(*line) for line in lines])
|
|
43 print (config)
|
|
44
|
|
45 fd, name = tempfile.mkstemp()
|
|
46 os.write(fd, config)
|
|
47 os.close(fd)
|
|
48
|
|
49 command = [dlna, '-f', name, '-d', '-p', str(options.port)]
|
|
50 print (subprocess.list2cmdline(command))
|
|
51 subprocess.check_call(command)
|
|
52
|
|
53 os.remove(name)
|
655
|
54 shutil.rmtree(options.db_dir)
|
654
|
55
|
|
56 if __name__ == '__main__':
|
|
57 main()
|