Skip to content

Instantly share code, notes, and snippets.

@rumpelsepp
Last active February 23, 2016 18:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rumpelsepp/edd9bdfa4a8703a65f52 to your computer and use it in GitHub Desktop.
Save rumpelsepp/edd9bdfa4a8703a65f52 to your computer and use it in GitHub Desktop.
A quick and dirty extractor for rtmpdump to download n24 videos, see also: http://anthropophobist.wordpress.com/2013/05/04/rtmp-streams-von-diversen-mediatheken-speichern
#!/usr/bin/env python3
#
# The MIT License (MIT)
#
# Copyright (c) 2015 Stefan Tatschner
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
import re
import sys
import subprocess
import urllib.request
from urllib.parse import urlparse
url = sys.argv[1]
url_parsed = urlparse(url)
response = urllib.request.urlopen(url)
html = response.read().decode()
regex = re.compile(
r'<title.*?>(?P<title>.+?)</title>|'
r'(?:_n24VideoCfg.flash.videoFlashconnectionUrl = )["\'](?P<param_r>.*)["\'];|'
r'(?:_n24VideoCfg.flash.SWFUrl = )["\'](?P<param_W>.*)["\'];|'
r'(?:_n24VideoCfg.flash.videoFlashSource = )["\'](?P<param_y>.*)["\'];|'
)
title = ''
rtmpdump_params = {}
for match in regex.finditer(html):
typ = match.lastgroup
if typ == 'title':
title = match.group('title')
elif typ == 'param_r':
rtmpdump_params['-r'] = match.group('param_r')
elif typ == 'param_W':
rtmpdump_params['-W'] = match.group('param_W')
elif typ == 'param_y':
rtmpdump_params['-y'] = match.group('param_y')
subprocess.call([
'rtmpdump',
'-r', rtmpdump_params['-r'],
'-W', url_parsed[0] + '://' + url_parsed[1] + rtmpdump_params['-W'],
'-y', rtmpdump_params['-y'],
'-o', title + '.mp4'
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment