Skip to content

Instantly share code, notes, and snippets.

@p3t3r67x0
Created March 17, 2018 07:22
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 p3t3r67x0/47e3ef79608a9678f282e0233b997ae5 to your computer and use it in GitHub Desktop.
Save p3t3r67x0/47e3ef79608a9678f282e0233b997ae5 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import json
import requests
from lxml import html
from urlparse import urlparse
from fake_useragent import UserAgent
ua = UserAgent()
def make_title(title):
return title.replace('//', '').replace(' ', '_').replace(u'–', '').replace('?', '').replace('!', '').replace('-', '').replace('__', '_').replace(':', '').replace(',', '').lower()
def find_js_url(text):
document = html.document_fromstring(text)
target_url = document.xpath('//a/@data-extension')
json_obj = json.loads(target_url[0])
return json_obj['mediaObj']['url']
def request_content(url, origin, ua_string):
headers = {'User-Agent': ua_string, 'Origin': origin}
response = requests.get(url, headers=headers)
if response.status_code == 200:
return response.text
def main():
if len(sys.argv) > 1:
wdr_url = sys.argv[1]
else:
print 'Enter the wdr.de url you want to download the m3u8 source!'
sys.exit(1)
useragent = ua.chrome
html_document = request_content(wdr_url, 'https://www1.wdr.de', useragent)
js_url = find_js_url(html_document)
media_url = request_content(js_url, sys.argv[1], useragent)
json_obj = json.loads(media_url.replace('$mediaObject.jsonpHelper.storeAndPlay(', '').replace(');', ''))
url = json_obj['mediaResource']['dflt']['videoURL'].replace('//', '')
title = u'{}.m3u8'.format(json_obj['trackerData']['trackerClipTitle'])
print make_title(title).replace('_.', '.')
print url
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment