changeset 654:d325f380e2fb

add a front-end to minidlna
author Jeff Hammel <k0scist@gmail.com>
date Fri, 28 Mar 2014 23:01:22 -0700
parents 69a76c1e65d9
children cd73d951ae5b
files python/dlna.py
diffstat 1 files changed, 51 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/python/dlna.py	Fri Mar 28 23:01:22 2014 -0700
@@ -0,0 +1,51 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import argparse
+import os
+import subprocess
+import sys
+import tempfile
+from which import which
+
+here = os.path.dirname(os.path.realpath(__file__))
+string = (str, unicode)
+
+def main(args=sys.argv[1:]):
+
+    dlna = which('minidlna')
+    assert dlna
+
+    parser = argparse.ArgumentParser(description=__doc__)
+    parser.add_argument('--name', dest='name', default='protest servant',
+                        help="friendly name")
+    parser.add_argument('--db-dir', dest='db_dir',
+                        default=os.path.join(os.environ['HOME'], 'minidlna'),
+                        help='db directory')
+    parser.add_argument('-p', '--port', dest='port', default=8200, type=int,
+                        help="port")
+    parser.add_argument('audio', nargs='+')
+    options = parser.parse_args(args)
+
+    lines = [('friendly_name', options.name),
+             ('db_dir', options.db_dir),
+             ('log_dir', options.db_dir),
+             ('inotify', 'yes'),
+             ('enable_tivo', 'yes')]
+    lines.extend([('media_dir', 'A,{}'.format(os.path.abspath(d)))
+                  for d in options.audio])
+    config = '\n'.join(['{}={}'.format(*line) for line in lines])
+    print (config)
+
+    fd, name = tempfile.mkstemp()
+    os.write(fd, config)
+    os.close(fd)
+
+    command = [dlna, '-f', name, '-d', '-p', str(options.port)]
+    print (subprocess.list2cmdline(command))
+    subprocess.check_call(command)
+
+    os.remove(name)
+
+if __name__ == '__main__':
+    main()