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.

57 lines
2.0 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|m)\.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. }
  21. }
  22. def _real_extract(self, url):
  23. mobj = re.match(self._VALID_URL, url)
  24. video_id = mobj.group('id')
  25. webpage = self._download_webpage('http://www.imdb.com/video/imdb/vi%s' % video_id, video_id)
  26. descr = get_element_by_attribute('itemprop', 'description', webpage)
  27. available_formats = re.findall(
  28. r'case \'(?P<f_id>.*?)\' :$\s+url = \'(?P<path>.*?)\'', webpage,
  29. flags=re.MULTILINE)
  30. formats = []
  31. for f_id, f_path in available_formats:
  32. f_path = f_path.strip()
  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. })
  45. return {
  46. 'id': video_id,
  47. 'title': self._og_search_title(webpage),
  48. 'formats': formats,
  49. 'description': descr,
  50. 'thumbnail': format_info['slate'],
  51. }