tweakers.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. class TweakersIE(InfoExtractor):
  6. _VALID_URL = r'https?://tweakers\.net/video/(?P<id>[0-9]+).*'
  7. _TEST = {
  8. 'url': 'https://tweakers.net/video/9926/new-nintendo-3ds-xl-op-alle-fronten-beter.html',
  9. 'md5': 'f7f7f3027166a7f32f024b4ae6571ced',
  10. 'info_dict': {
  11. 'id': '9926',
  12. 'ext': 'mp4',
  13. 'title': 'New-Nintendo-3Ds-Xl-Op-Alle-Fronten-Beter',
  14. # TODO more properties, either as:
  15. # * A value
  16. # * MD5 checksum; start the string with md5:
  17. # * A regular expression; start the string with re:
  18. # * Any Python type (for example int or float)
  19. }
  20. }
  21. def _real_extract(self, url):
  22. splitted_url = re.split('.html|/', url)
  23. del splitted_url[-1] # To remove extra '/' at the end
  24. video_id = splitted_url[4]
  25. title = splitted_url[5].title() # Retrieve title for URL and capitalize
  26. splitted_url[3] = splitted_url[3] + '/player' # Add /player to get the player page
  27. player_url = '/'.join(splitted_url) + '.html'
  28. player_page = self._download_webpage(player_url, video_id)
  29. return {
  30. 'id': video_id,
  31. 'ext': 'mp4',
  32. 'title': title,
  33. 'url': re.findall('http.*mp4', player_page)[0],
  34. }