tweakers.py 2.0 KB

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