furas

dumpert.nl video url

Jun 13th, 2016
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.25 KB | None | 0 0
  1. #!/usr/bin/env python3
  2.  
  3. import requests
  4. import lxml.html
  5. import base64
  6. import json
  7. import sys
  8.  
  9. url = 'http://www.dumpert.nl/mediabase/6801277/9f7c6290/max_verdedigt_tegen_rosberg.html'
  10.  
  11. # read web page
  12. r = requests.get(url)
  13.  
  14. #print('Status code:', r.status_code)
  15. #print('OK:', r.ok)
  16.  
  17. # convert html text to html object
  18. html = lxml.html.fromstring(r.text)
  19.  
  20. # get data-files from html object
  21. data = html.xpath('//@data-files')[0]
  22.  
  23. # decode base64
  24. data = base64.b64decode(data)
  25.  
  26. # convert bytes to string (Python 3)
  27. data = data.decode('utf-8')
  28.  
  29. # convert json string into python dictionary
  30. data = json.loads(data)
  31.  
  32. #print(data.keys())
  33.  
  34. # get video url from dictionary
  35. print('mobile:', data['mobile'])
  36. print(' table:', data['tablet'])
  37. print('  720p:', data['720p'])
  38. print(' image:', data['still'])
  39.  
  40. # download video file
  41. video_url = data['tablet']
  42. local_filename = video_url.split('/')[-1]
  43.  
  44. r = requests.get(video_url, stream=True)
  45.  
  46. with open(local_filename, 'wb') as f:
  47.     for chunk in r.iter_content(chunk_size=4096):
  48.         if chunk:
  49.             f.write(chunk)
  50.             # show something on screen
  51.             print('.', end='')
  52.             sys.stdout.flush() # send on screen without buffering
  53.            
  54. print('\n Done.')
Add Comment
Please, Sign In to add comment