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.

59 lines
2.1 KiB

  1. import re
  2. import json
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. compat_urlparse,
  6. get_element_by_attribute,
  7. )
  8. class ImdbIE(InfoExtractor):
  9. IE_NAME = u'imdb'
  10. IE_DESC = u'Internet Movie Database trailers'
  11. _VALID_URL = r'http://www\.imdb\.com/video/imdb/vi(?P<id>\d+)'
  12. _TEST = {
  13. u'url': u'http://www.imdb.com/video/imdb/vi2524815897',
  14. u'md5': u'9f34fa777ade3a6e57a054fdbcb3a068',
  15. u'info_dict': {
  16. u'id': u'2524815897',
  17. u'ext': u'mp4',
  18. u'title': u'Ice Age: Continental Drift Trailer (No. 2) - IMDb',
  19. u'description': u'md5:9061c2219254e5d14e03c25c98e96a81',
  20. u'duration': 151,
  21. }
  22. }
  23. def _real_extract(self, url):
  24. mobj = re.match(self._VALID_URL, url)
  25. video_id = mobj.group('id')
  26. webpage = self._download_webpage(url,video_id)
  27. descr = get_element_by_attribute('itemprop', 'description', webpage)
  28. available_formats = re.findall(
  29. r'case \'(?P<f_id>.*?)\' :$\s+url = \'(?P<path>.*?)\'', webpage,
  30. flags=re.MULTILINE)
  31. formats = []
  32. for f_id, f_path in available_formats:
  33. format_page = self._download_webpage(
  34. compat_urlparse.urljoin(url, f_path),
  35. u'Downloading info for %s format' % f_id)
  36. json_data = self._search_regex(
  37. r'<script[^>]+class="imdb-player-data"[^>]*?>(.*?)</script>',
  38. format_page, u'json data', flags=re.DOTALL)
  39. info = json.loads(json_data)
  40. format_info = info['videoPlayerObject']['video']
  41. formats.append({
  42. 'format_id': f_id,
  43. 'url': format_info['url'],
  44. 'height': int(info['titleObject']['encoding']['selected'][:-1]),
  45. })
  46. return {
  47. 'id': video_id,
  48. 'title': self._og_search_title(webpage),
  49. 'formats': formats,
  50. 'description': descr,
  51. 'thumbnail': format_info['slate'],
  52. 'duration': int(info['titleObject']['title']['duration_seconds']),
  53. }