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.

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