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.

88 lines
3.0 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. compat_str,
  6. compat_urllib_parse,
  7. ExtractorError,
  8. )
  9. class FiveMinIE(InfoExtractor):
  10. IE_NAME = '5min'
  11. _VALID_URL = r'''(?x)
  12. (?:https?://[^/]*?5min\.com/Scripts/PlayerSeed\.js\?(.*?&)?playList=|
  13. 5min:)
  14. (?P<id>\d+)
  15. '''
  16. _TESTS = [
  17. {
  18. # From http://www.engadget.com/2013/11/15/ipad-mini-retina-display-review/
  19. 'url': 'http://pshared.5min.com/Scripts/PlayerSeed.js?sid=281&width=560&height=345&playList=518013791',
  20. 'md5': '4f7b0b79bf1a470e5004f7112385941d',
  21. 'info_dict': {
  22. 'id': '518013791',
  23. 'ext': 'mp4',
  24. 'title': 'iPad Mini with Retina Display Review',
  25. },
  26. },
  27. {
  28. # From http://on.aol.com/video/how-to-make-a-next-level-fruit-salad-518086247
  29. 'url': '5min:518086247',
  30. 'md5': 'e539a9dd682c288ef5a498898009f69e',
  31. 'info_dict': {
  32. 'id': '518086247',
  33. 'ext': 'mp4',
  34. 'title': 'How to Make a Next-Level Fruit Salad',
  35. },
  36. },
  37. ]
  38. @classmethod
  39. def _build_result(cls, video_id):
  40. return cls.url_result('5min:%s' % video_id, cls.ie_key())
  41. def _real_extract(self, url):
  42. mobj = re.match(self._VALID_URL, url)
  43. video_id = mobj.group('id')
  44. embed_url = 'https://embed.5min.com/playerseed/?playList=%s' % video_id
  45. embed_page = self._download_webpage(embed_url, video_id,
  46. 'Downloading embed page')
  47. sid = self._search_regex(r'sid=(\d+)', embed_page, 'sid')
  48. query = compat_urllib_parse.urlencode({
  49. 'func': 'GetResults',
  50. 'playlist': video_id,
  51. 'sid': sid,
  52. 'isPlayerSeed': 'true',
  53. 'url': embed_url,
  54. })
  55. response = self._download_json(
  56. 'https://syn.5min.com/handlers/SenseHandler.ashx?' + query,
  57. video_id)
  58. if not response['success']:
  59. err_msg = response['errorMessage']
  60. if err_msg == 'ErrorVideoUserNotGeo':
  61. msg = 'Video not available from your location'
  62. else:
  63. msg = 'Aol said: %s' % err_msg
  64. raise ExtractorError(msg, expected=True, video_id=video_id)
  65. info = response['binding'][0]
  66. second_id = compat_str(int(video_id[:-2]) + 1)
  67. formats = []
  68. for quality, height in [(1, 320), (2, 480), (4, 720), (8, 1080)]:
  69. if any(r['ID'] == quality for r in info['Renditions']):
  70. formats.append({
  71. 'format_id': compat_str(quality),
  72. 'url': 'http://avideos.5min.com/%s/%s/%s_%s.mp4' % (second_id[-3:], second_id, video_id, quality),
  73. 'height': height,
  74. })
  75. return {
  76. 'id': video_id,
  77. 'title': info['Title'],
  78. 'formats': formats,
  79. }