17

I'm currently running Raspbmc on my Raspberry Pi and activated UPnP streaming an rendering.

My goal is to write a simple Python to stream a video or music playlist.

I've tried Coherence, but I it's throwing a bunch exceptions and I don't really get the point as the documentation is pretty chaotic. So I'm looking for an easier way/library.

What's the easiest way to stream media files to my TV using Python?

shackra
  • 277
  • 3
  • 16
  • 56
WhatIsName
  • 2,294
  • 4
  • 24
  • 36
  • 1
    As I understand it DLNA is a pretty complex standard, so (I'm guessing here) the exceptions might be something you have to deal with. Maybe it's worth mentioning which ones you're getting? If you don't need to write the program yourself, Mediatomb and minidlna are capable of streaming from the Pi. – Samizdis Mar 21 '13 at 13:38
  • 1
    Thank you, I will have a look at Mediatomb and minidlna. Well as I said, I get probably get a hundred exceptions, by just starting coherence, but most of them are somehow related to Tornado: `File "/Users/.../Envs/UPNP/lib/python2.7/site-packages/twisted/internet/selectreactor.py", line 145, in doSelect _logrun(selectable, _drdw, selectable, method, dict) --- --- File "/Users/.../Envs/UPNP/lib/python2.7/site-packages/twisted/python/log.py", line 88, in callWithLogger return callWithContext({"system": lp}, func, *args, **kw)` – WhatIsName Mar 21 '13 at 13:55
  • Did you achieve what you wanted to do ? I'm trying coherence too, but it seems twisted and coherence are not working well together unless you patch the coherences files. – Depado Apr 04 '13 at 16:37
  • 1
    Can you post your code so far? – NoBugs Feb 01 '14 at 18:17
  • DLNA is a complex, proprietary protocol. I'm currently using `minidlna` – johntellsall May 23 '14 at 20:59
  • @Depado Coherence is lagging behind twisted. You need to use an older version of twisted if you want to work with it. – unode Jun 17 '14 at 19:18
  • I've written a small dlna client using PyGTK and Coherence which works more like a folder browser. In my case the streaming is performed by mplayer (once you know the URL(s) it's dead easy). It's not yet public because it's more of a hack for personal use. If you can show us the errors maybe we can add some guidance. I've also patched Coherence to allow download of Subtitles (tested only with minidlna server). You can find the patched version on https://github.com/Unode/Coherence – unode Jun 17 '14 at 19:18
  • That sounds interesting. I like the hackish way. Could you show me some samples of your code ? (Not the whole thing if you don't want to make it public, but the "main" part ?) – Depado Jun 19 '14 at 09:12

3 Answers3

5

There is a lightweight pure python library dlnap which allows playing media on DLNA/UPnP devices in the same local network

1

For audio only, I got good results with rygel. The tricky part is to configure the GstLaunch pulseaudio connector in the .config/rygel.conf. Here is my section, but you can get the right pulseaudio source with the following command:

pactl list | egrep -A2 '^(\*\*\* )?Source #' | grep 'Name: .*\.monitor$' | awk '{print $NF}' | tail -n1

Here is my GstLaunch Section:

[GstLaunch]
enabled=true
launch-items=myaudiowav;myaudiompeg

myaudiowav-title=WAV audio on @HOSTNAME@
myaudiowav-mime=audio/x-wav
myaudiowav-launch=pulsesrc device=alsa_output.pci-0000_00_14.2.analog-stereo.monitor ! audio/x-raw,channels=2 ! wavpackenc

myaudiompeg-title=MPEG audio on @HOSTNAME@
myaudiompeg-mime=audio/mpeg
myaudiompeg-launch=pulsesrc device=alsa_output.pci-0000_00_14.2.analog-stereo.monitor ! audio/x-raw,channels=2 ! lamemp3enc target=quality q
uality=6
eri
  • 3,133
  • 1
  • 23
  • 35
Pivert
  • 755
  • 5
  • 17
1

You can use GUPnP binding for python through the gi.repository. Search the documentation for GUPnP and GSSDP, GUPnP AV.

You can couple them with something like a mini webserver running django+SQLite database to define a kind of content directory service (CDS) also you can use Gstreamer (a python binding exist called Gst). With those elements you can build a custom server using SSDP for the discovered stuff; from gstreamer you can get metadata about each media item, and can also use "rtspsrc" of gstreamer for streaming.

Nathan Tuggy
  • 2,237
  • 27
  • 30
  • 38