Mercurial > hg > config
comparison python/dlna.py @ 654:d325f380e2fb
add a front-end to minidlna
| author | Jeff Hammel <k0scist@gmail.com> |
|---|---|
| date | Fri, 28 Mar 2014 23:01:22 -0700 |
| parents | |
| children | cd73d951ae5b |
comparison
equal
deleted
inserted
replaced
| 653:69a76c1e65d9 | 654:d325f380e2fb |
|---|---|
| 1 #!/usr/bin/env python | |
| 2 # -*- coding: utf-8 -*- | |
| 3 | |
| 4 import argparse | |
| 5 import os | |
| 6 import subprocess | |
| 7 import sys | |
| 8 import tempfile | |
| 9 from which import which | |
| 10 | |
| 11 here = os.path.dirname(os.path.realpath(__file__)) | |
| 12 string = (str, unicode) | |
| 13 | |
| 14 def main(args=sys.argv[1:]): | |
| 15 | |
| 16 dlna = which('minidlna') | |
| 17 assert dlna | |
| 18 | |
| 19 parser = argparse.ArgumentParser(description=__doc__) | |
| 20 parser.add_argument('--name', dest='name', default='protest servant', | |
| 21 help="friendly name") | |
| 22 parser.add_argument('--db-dir', dest='db_dir', | |
| 23 default=os.path.join(os.environ['HOME'], 'minidlna'), | |
| 24 help='db directory') | |
| 25 parser.add_argument('-p', '--port', dest='port', default=8200, type=int, | |
| 26 help="port") | |
| 27 parser.add_argument('audio', nargs='+') | |
| 28 options = parser.parse_args(args) | |
| 29 | |
| 30 lines = [('friendly_name', options.name), | |
| 31 ('db_dir', options.db_dir), | |
| 32 ('log_dir', options.db_dir), | |
| 33 ('inotify', 'yes'), | |
| 34 ('enable_tivo', 'yes')] | |
| 35 lines.extend([('media_dir', 'A,{}'.format(os.path.abspath(d))) | |
| 36 for d in options.audio]) | |
| 37 config = '\n'.join(['{}={}'.format(*line) for line in lines]) | |
| 38 print (config) | |
| 39 | |
| 40 fd, name = tempfile.mkstemp() | |
| 41 os.write(fd, config) | |
| 42 os.close(fd) | |
| 43 | |
| 44 command = [dlna, '-f', name, '-d', '-p', str(options.port)] | |
| 45 print (subprocess.list2cmdline(command)) | |
| 46 subprocess.check_call(command) | |
| 47 | |
| 48 os.remove(name) | |
| 49 | |
| 50 if __name__ == '__main__': | |
| 51 main() |
