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.

85 lines
3.3 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. }
  52. class ImdbListIE(InfoExtractor):
  53. IE_NAME = u'imdb:list'
  54. IE_DESC = u'Internet Movie Database lists'
  55. _VALID_URL = r'http://www\.imdb\.com/list/(?P<id>[\da-zA-Z_-]{11})'
  56. def _real_extract(self, url):
  57. mobj = re.match(self._VALID_URL, url)
  58. list_id = mobj.group('id')
  59. # RSS XML is sometimes malformed
  60. rss = self._download_webpage('http://rss.imdb.com/list/%s' % list_id, list_id, u'Downloading list RSS')
  61. list_title = self._html_search_regex(r'<title>(.*?)</title>', rss, u'list title')
  62. # Export is independent of actual author_id, but returns 404 if no author_id is provided.
  63. # However, passing dummy author_id seems to be enough.
  64. csv = self._download_webpage('http://www.imdb.com/list/export?list_id=%s&author_id=ur00000000' % list_id,
  65. list_id, u'Downloading list CSV')
  66. entries = []
  67. for item in csv.split('\n')[1:]:
  68. cols = item.split(',')
  69. if len(cols) < 2:
  70. continue
  71. item_id = cols[1][1:-1]
  72. if item_id.startswith('vi'):
  73. entries.append(self.url_result('http://www.imdb.com/video/imdb/%s' % item_id, 'Imdb'))
  74. return self.playlist_result(entries, list_id, list_title)