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.

84 lines
2.9 KiB

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