I wanted to grab the actual stream URL when casting a video from my phone to the TV. Not to watch it on the TV — I wanted the raw m3u8 link so I could record it with ffmpeg or play it in VLC on my laptop.
Turns out, DLNA casting works by sending the media URL from the phone app to the TV via a standard SOAP request (SetAVTransportURI). The TV then fetches and plays the stream on its own. The phone is just a remote control.
So... what if your computer pretended to be a TV?
The idea
If you advertise a fake UPnP MediaRenderer on the local network, any app that supports DLNA casting (Bilibili, iQiyi, Youku, TikTok, and many more) will happily send you the real stream URL when you hit "cast."
The app can't tell the difference — it's standard protocol, same as talking to a Samsung or Sony TV.
How it works
-
SSDP multicast on
239.255.255.250:1900— announce ourselves as a MediaRenderer - UPnP device description — reply with a minimal XML descriptor when queried
-
SOAP control — the app sends
SetAVTransportURIwith the actual stream URL. We extract it and we're done.
The whole thing is ~500 lines of Python stdlib. No dependencies.
Usage
pip install wechat-finder-dlna
# Print the captured URL
wechat-finder-dlna
# Record directly with ffmpeg
wechat-finder-dlna --record stream.mp4 --duration 01:00:00
# Pipe to VLC
wechat-finder-dlna | xargs vlc
Or use it as a library:
from wechat_finder_dlna import capture
url = capture(name="Living Room TV")
# url is the raw m3u8/mp4 link — do whatever you want with it
Phone and computer need to be on the same WiFi. That's it.
Why not just use an existing DLNA library?
I looked at a few (like dlnap, macast), but they're full renderers — they actually play the video. I just wanted the URL. So I built the smallest possible MediaRenderer that only implements device discovery and SetAVTransportURI.
Zero external dependencies. Pure stdlib (http.server, socket, threading, xml).
What apps work with this?
Anything that supports DLNA/UPnP casting. I've tested with several Chinese streaming apps (they all use DLNA for casting), but it should work with any app that can cast to a smart TV on your network.
The project is at github.com/gtoxlili/wechat-finder-dlna. Feedback welcome — especially if you've tested it with apps I haven't tried.
Top comments (0)