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.

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