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.

56 lines
1.8 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. compat_str,
  6. )
  7. class FiveMinIE(InfoExtractor):
  8. IE_NAME = '5min'
  9. _VALID_URL = r'''(?x)
  10. (?:https?://[^/]*?5min\.com/Scripts/PlayerSeed\.js\?(.*?&)?playList=|
  11. 5min:)
  12. (?P<id>\d+)
  13. '''
  14. _TEST = {
  15. # From http://www.engadget.com/2013/11/15/ipad-mini-retina-display-review/
  16. 'url': 'http://pshared.5min.com/Scripts/PlayerSeed.js?sid=281&width=560&height=345&playList=518013791',
  17. 'md5': '4f7b0b79bf1a470e5004f7112385941d',
  18. 'info_dict': {
  19. 'id': '518013791',
  20. 'ext': 'mp4',
  21. 'title': 'iPad Mini with Retina Display Review',
  22. },
  23. }
  24. @classmethod
  25. def _build_result(cls, video_id):
  26. return cls.url_result('5min:%s' % video_id, cls.ie_key())
  27. def _real_extract(self, url):
  28. mobj = re.match(self._VALID_URL, url)
  29. video_id = mobj.group('id')
  30. info = self._download_json(
  31. 'https://syn.5min.com/handlers/SenseHandler.ashx?func=GetResults&'
  32. 'playlist=%s&url=https' % video_id,
  33. video_id)['binding'][0]
  34. second_id = compat_str(int(video_id[:-2]) + 1)
  35. formats = []
  36. for quality, height in [(1, 320), (2, 480), (4, 720), (8, 1080)]:
  37. if any(r['ID'] == quality for r in info['Renditions']):
  38. formats.append({
  39. 'format_id': compat_str(quality),
  40. 'url': 'http://avideos.5min.com/%s/%s/%s_%s.mp4' % (second_id[-3:], second_id, video_id, quality),
  41. 'height': height,
  42. })
  43. return {
  44. 'id': video_id,
  45. 'title': info['Title'],
  46. 'formats': formats,
  47. }