Permalink
Browse files

DAAP? DAAP!

  • Loading branch information...
0 parents commit fd0ec3489c31a1340bc26eb40f513b1867bb8a39 @mitsuhiko committed Feb 5, 2011
Showing with 126 additions and 0 deletions.
  1. +49 −0 README
  2. +77 −0 daap-forward.py
49 README
@@ -0,0 +1,49 @@
+
+ ~ OS X Daap SSH Forward Script
+
+ For the lazy of us that use a remote DAAP server and want to
+ connect to it via SSH port forwarding but can't remember the
+ commands to run.
+
+
+ Usage:
+
+ 1. Create a file called `~/.daapforward`
+ 2. Update config according to example below
+ 3. run `python daap-forward.py`
+ 4. Start iTunes and click on the daap share on the left
+ 5. \m/
+
+ Config:
+
+ # the name of the server that runs ssh. If this is also
+ # the server that runs the DAAP share, this is actually
+ # all you have to put into the config
+ ssh-server-name example.com
+
+ # this is the name of the user used for connecting.
+ # empty or not specified means current user
+ ssh-username anne
+
+ # if the DAAP server is running on a different computer
+ # on the network the ssh server is on, you have to specify
+ # this as well. Otherwise localhost is assumed
+ daap-server-name localhost
+
+ # the port the remote daap server runs on
+ remote-daap-port 3689
+
+ # the local port where daap should "run on"
+ local-daap-port 3689
+
+ # the name of the share. Now this is the name that is
+ # displayed in iTunes before you actually connect to the
+ # share. As soon as you are connected that name is
+ # overridden with the actual name on the remote, so make
+ # sure to keep them somewhat synchronized.
+ share-name Remote iTunes Share
+
+ This script has bad code and just works good enough for
+ accessing remote DAAP shares if you are lazy. Use it in
+ combination with dyndns or something for your mobile
+ listening pleasure.
@@ -0,0 +1,77 @@
+ #!/usr/bin/env python
+import os
+import sys
+import signal
+from select import select
+from subprocess import Popen
+from threading import Thread
+
+config = {
+ 'ssh-server-name': 'localhost',
+ 'ssh-username': '',
+ 'daap-server-name': 'localhost',
+ 'remote-daap-port': '3689',
+ 'local-daap-port': '3689',
+ 'share-name': 'Remote iTunes Share'
+}
+
+
+def read_config(path):
+ if not os.path.isfile(path):
+ print >> sys.stderr, 'Missing config %s' % path
+ return
+ for line in open(path):
+ line = line.strip().split(None, 1)
+ if not line or line[0][:1] == '#':
+ continue
+ config[line[0]] = line[1]
+
+
+def start_ssh(pids):
+ user = config['ssh-username']
+ if user:
+ user += '@'
+ c = Popen(['ssh', user + config['ssh-server-name'], '-g', '-N', '-L',
+ '%s:%s:%s' % (config['local-daap-port'],
+ config['daap-server-name'],
+ config['remote-daap-port'])])
+ pids.append(c.pid)
+ c.wait()
+
+
+def start_proxy(pids):
+ c = Popen(['dns-sd', '-R', config['share-name'], '_daap._tcp.', 'local',
+ config['local-daap-port']])
+ pids.append(c.pid)
+ c.wait()
+
+
+def main():
+ read_config(os.path.expanduser('~/.daapforward'))
+ pids = []
+ print 'Starting up...'
+ print 'Connecting to %s via %s' % (
+ config['daap-server-name'],
+ config['ssh-server-name']
+ )
+ try:
+ try:
+ for task in start_ssh, start_proxy:
+ t = Thread(target=task, args=(pids,))
+ t.setDaemon(True)
+ t.start()
+ while 1:
+ select([sys.stdin], [], [])
+ except KeyboardInterrupt:
+ pass
+ finally:
+ for pid in pids:
+ try:
+ os.kill(pid, signal.SIGTERM)
+ except OSError:
+ pass
+ print 'Shut down'
+
+
+if __name__ == '__main__':
+ main()

0 comments on commit fd0ec34

Please sign in to comment.