You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.2 KiB

  1. from __future__ import unicode_literals
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. xpath_text,
  5. xpath_with_ns,
  6. int_or_none,
  7. float_or_none,
  8. )
  9. class TweakersIE(InfoExtractor):
  10. _VALID_URL = r'https?://tweakers\.net/video/(?P<id>\d+)'
  11. _TEST = {
  12. 'url': 'https://tweakers.net/video/9926/new-nintendo-3ds-xl-op-alle-fronten-beter.html',
  13. 'md5': '1b5afa817403bb5baa08359dca31e6df',
  14. 'info_dict': {
  15. 'id': '9926',
  16. 'ext': 'mp4',
  17. 'title': 'New Nintendo 3DS XL - Op alle fronten beter',
  18. 'description': 'md5:f97324cc71e86e11c853f0763820e3ba',
  19. 'thumbnail': 're:^https?://.*\.jpe?g$',
  20. 'duration': 386,
  21. }
  22. }
  23. def _real_extract(self, url):
  24. video_id = self._match_id(url)
  25. playlist = self._download_xml(
  26. 'https://tweakers.net/video/s1playlist/%s/playlist.xspf' % video_id,
  27. video_id)
  28. NS_MAP = {
  29. 'xspf': 'http://xspf.org/ns/0/',
  30. 's1': 'http://static.streamone.nl/player/ns/0',
  31. }
  32. track = playlist.find(xpath_with_ns('./xspf:trackList/xspf:track', NS_MAP))
  33. title = xpath_text(
  34. track, xpath_with_ns('./xspf:title', NS_MAP), 'title')
  35. description = xpath_text(
  36. track, xpath_with_ns('./xspf:annotation', NS_MAP), 'description')
  37. thumbnail = xpath_text(
  38. track, xpath_with_ns('./xspf:image', NS_MAP), 'thumbnail')
  39. duration = float_or_none(
  40. xpath_text(track, xpath_with_ns('./xspf:duration', NS_MAP), 'duration'),
  41. 1000)
  42. formats = [{
  43. 'url': location.text,
  44. 'format_id': location.get(xpath_with_ns('s1:label', NS_MAP)),
  45. 'width': int_or_none(location.get(xpath_with_ns('s1:width', NS_MAP))),
  46. 'height': int_or_none(location.get(xpath_with_ns('s1:height', NS_MAP))),
  47. } for location in track.findall(xpath_with_ns('./xspf:location', NS_MAP))]
  48. return {
  49. 'id': video_id,
  50. 'title': title,
  51. 'description': description,
  52. 'thumbnail': thumbnail,
  53. 'duration': duration,
  54. 'formats': formats,
  55. }