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.

69 lines
2.4 KiB

  1. from __future__ import unicode_literals
  2. import json
  3. import os.path
  4. import re
  5. from .common import InfoExtractor
  6. from ..utils import (
  7. int_or_none,
  8. parse_iso8601,
  9. )
  10. class VultureIE(InfoExtractor):
  11. IE_NAME = 'vulture.com'
  12. _VALID_URL = r'https?://video\.vulture\.com/video/(?P<display_id>[^/]+)/'
  13. _TEST = {
  14. 'url': 'http://video.vulture.com/video/Mindy-Kaling-s-Harvard-Speech/player?layout=compact&read_more=1',
  15. 'md5': '8d997845642a2b5152820f7257871bc8',
  16. 'info_dict': {
  17. 'id': '6GHRQL3RV7MSD1H4',
  18. 'ext': 'mp4',
  19. 'title': 'kaling-speech-2-MAGNIFY STANDARD CONTAINER REVISED',
  20. 'uploader_id': 'Sarah',
  21. 'thumbnail': 're:^http://.*\.jpg$',
  22. 'timestamp': 1401288564,
  23. 'upload_date': '20140528',
  24. 'description': 'Uplifting and witty, as predicted.',
  25. 'duration': 1015,
  26. }
  27. }
  28. def _real_extract(self, url):
  29. mobj = re.match(self._VALID_URL, url)
  30. display_id = mobj.group('display_id')
  31. webpage = self._download_webpage(url, display_id)
  32. query_string = self._search_regex(
  33. r"queryString\s*=\s*'([^']+)'", webpage, 'query string')
  34. video_id = self._search_regex(
  35. r'content=([^&]+)', query_string, 'video ID')
  36. query_url = 'http://video.vulture.com/embed/player/container/1000/1000/?%s' % query_string
  37. query_webpage = self._download_webpage(
  38. query_url, display_id, note='Downloading query page')
  39. params_json = self._search_regex(
  40. r'(?sm)new MagnifyEmbeddablePlayer\({.*?contentItem:\s*(\{.*?\})\n?,\n',
  41. query_webpage,
  42. 'player params')
  43. params = json.loads(params_json)
  44. upload_timestamp = parse_iso8601(params['posted'].replace(' ', 'T'))
  45. uploader_id = params.get('user', {}).get('handle')
  46. media_item = params['media_item']
  47. title = os.path.splitext(media_item['title'])[0]
  48. duration = int_or_none(media_item.get('duration_seconds'))
  49. return {
  50. 'id': video_id,
  51. 'display_id': display_id,
  52. 'url': media_item['pipeline_xid'],
  53. 'title': title,
  54. 'timestamp': upload_timestamp,
  55. 'thumbnail': params.get('thumbnail_url'),
  56. 'uploader_id': uploader_id,
  57. 'description': params.get('description'),
  58. 'duration': duration,
  59. }