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.

62 lines
2.1 KiB

  1. from __future__ import unicode_literals
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. int_or_none,
  5. determine_ext,
  6. mimetype2ext,
  7. )
  8. class TweakersIE(InfoExtractor):
  9. _VALID_URL = r'https?://tweakers\.net/video/(?P<id>\d+)'
  10. _TEST = {
  11. 'url': 'https://tweakers.net/video/9926/new-nintendo-3ds-xl-op-alle-fronten-beter.html',
  12. 'md5': 'fe73e417c093a788e0160c4025f88b15',
  13. 'info_dict': {
  14. 'id': '9926',
  15. 'ext': 'mp4',
  16. 'title': 'New Nintendo 3DS XL - Op alle fronten beter',
  17. 'description': 'md5:3789b21fed9c0219e9bcaacd43fab280',
  18. 'thumbnail': 're:^https?://.*\.jpe?g$',
  19. 'duration': 386,
  20. 'uploader_id': 's7JeEm',
  21. }
  22. }
  23. def _real_extract(self, url):
  24. video_id = self._match_id(url)
  25. video_data = self._download_json(
  26. 'https://tweakers.net/video/s1playlist/%s/1920/1080/playlist.json' % video_id,
  27. video_id)['items'][0]
  28. title = video_data['title']
  29. formats = []
  30. for location in video_data.get('locations', {}).get('progressive', []):
  31. format_id = location.get('label')
  32. width = int_or_none(location.get('width'))
  33. height = int_or_none(location.get('height'))
  34. for source in location.get('sources', []):
  35. source_url = source.get('src')
  36. if not source_url:
  37. continue
  38. ext = mimetype2ext(source.get('type')) or determine_ext(source_url)
  39. formats.append({
  40. 'format_id': format_id,
  41. 'url': source_url,
  42. 'width': width,
  43. 'height': height,
  44. 'ext': ext,
  45. })
  46. self._sort_formats(formats)
  47. return {
  48. 'id': video_id,
  49. 'title': title,
  50. 'description': video_data.get('description'),
  51. 'thumbnail': video_data.get('poster'),
  52. 'duration': int_or_none(video_data.get('duration')),
  53. 'uploader_id': video_data.get('account'),
  54. 'formats': formats,
  55. }