Mercurial > hg > config
annotate python/dlna.py @ 922:74dc16f074be default tip
ignore ff merges
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Thu, 03 Oct 2024 05:36:19 -0700 |
parents | af7b427b3b83 |
children |
rev | line source |
---|---|
654 | 1 #!/usr/bin/env python |
2 # -*- coding: utf-8 -*- | |
3 | |
710 | 4 """ |
5 serve DLNA | |
6 """ | |
7 | |
654 | 8 import argparse |
9 import os | |
655 | 10 import shutil |
654 | 11 import subprocess |
12 import sys | |
13 import tempfile | |
14 from which import which | |
15 | |
16 here = os.path.dirname(os.path.realpath(__file__)) | |
17 string = (str, unicode) | |
18 | |
19 def main(args=sys.argv[1:]): | |
710 | 20 """CLI""" |
654 | 21 |
710 | 22 # parse command line |
654 | 23 parser = argparse.ArgumentParser(description=__doc__) |
24 parser.add_argument('--name', dest='name', default='protest servant', | |
25 help="friendly name") | |
26 parser.add_argument('--db-dir', dest='db_dir', | |
27 default=os.path.join(os.environ['HOME'], 'minidlna'), | |
28 help='db directory') | |
29 parser.add_argument('-p', '--port', dest='port', default=8200, type=int, | |
30 help="port") | |
656 | 31 parser.add_argument('-v', '--videos', dest='videos', nargs='+', |
32 help="videos") | |
654 | 33 parser.add_argument('audio', nargs='+') |
757 | 34 parser.add_argument('--print', '--print-config', dest='print_config', |
35 action='store_true', default=False, | |
36 help="write config to stdout and exit") | |
654 | 37 options = parser.parse_args(args) |
38 | |
710 | 39 # dlna location |
40 dlna = which('minidlnad') | |
41 if not dlna: | |
42 parser.error("minidlna command not found") | |
43 | |
654 | 44 lines = [('friendly_name', options.name), |
45 ('db_dir', options.db_dir), | |
46 ('log_dir', options.db_dir), | |
47 ('inotify', 'yes'), | |
48 ('enable_tivo', 'yes')] | |
49 lines.extend([('media_dir', 'A,{}'.format(os.path.abspath(d))) | |
50 for d in options.audio]) | |
656 | 51 lines.extend([('media_dir', 'V,{}'.format(os.path.abspath(d))) |
52 for d in options.audio]) | |
654 | 53 config = '\n'.join(['{}={}'.format(*line) for line in lines]) |
54 print (config) | |
55 | |
757 | 56 if options.print_config: |
57 parser.exit() | |
58 | |
654 | 59 fd, name = tempfile.mkstemp() |
60 os.write(fd, config) | |
61 os.close(fd) | |
62 | |
712
02aec49585ab
dont pass -d flag; i dont know why
Jeff Hammel <k0scist@gmail.com>
parents:
710
diff
changeset
|
63 command = [dlna, '-f', name, '-p', str(options.port)] |
654 | 64 print (subprocess.list2cmdline(command)) |
65 subprocess.check_call(command) | |
66 | |
67 os.remove(name) | |
655 | 68 shutil.rmtree(options.db_dir) |
654 | 69 |
70 if __name__ == '__main__': | |
71 main() |