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.

89 lines
3.3 KiB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
  1. from __future__ import unicode_literals
  2. import re
  3. import json
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. compat_urlparse,
  7. get_element_by_attribute,
  8. )
  9. class ImdbIE(InfoExtractor):
  10. IE_NAME = 'imdb'
  11. IE_DESC = 'Internet Movie Database trailers'
  12. _VALID_URL = r'http://(?:www|m)\.imdb\.com/video/imdb/vi(?P<id>\d+)'
  13. _TEST = {
  14. 'url': 'http://www.imdb.com/video/imdb/vi2524815897',
  15. 'md5': '9f34fa777ade3a6e57a054fdbcb3a068',
  16. 'info_dict': {
  17. 'id': '2524815897',
  18. 'ext': 'mp4',
  19. 'title': 'Ice Age: Continental Drift Trailer (No. 2) - IMDb',
  20. 'description': 'md5:9061c2219254e5d14e03c25c98e96a81',
  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('http://www.imdb.com/video/imdb/vi%s' % video_id, 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. f_path = f_path.strip()
  34. format_page = self._download_webpage(
  35. compat_urlparse.urljoin(url, f_path),
  36. 'Downloading info for %s format' % f_id)
  37. json_data = self._search_regex(
  38. r'<script[^>]+class="imdb-player-data"[^>]*?>(.*?)</script>',
  39. format_page, 'json data', flags=re.DOTALL)
  40. info = json.loads(json_data)
  41. format_info = info['videoPlayerObject']['video']
  42. formats.append({
  43. 'format_id': f_id,
  44. 'url': format_info['url'],
  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. }
  53. class ImdbListIE(InfoExtractor):
  54. IE_NAME = 'imdb:list'
  55. IE_DESC = 'Internet Movie Database lists'
  56. _VALID_URL = r'http://www\.imdb\.com/list/(?P<id>[\da-zA-Z_-]{11})'
  57. def _real_extract(self, url):
  58. mobj = re.match(self._VALID_URL, url)
  59. list_id = mobj.group('id')
  60. # RSS XML is sometimes malformed
  61. rss = self._download_webpage('http://rss.imdb.com/list/%s' % list_id, list_id, 'Downloading list RSS')
  62. list_title = self._html_search_regex(r'<title>(.*?)</title>', rss, 'list title')
  63. # Export is independent of actual author_id, but returns 404 if no author_id is provided.
  64. # However, passing dummy author_id seems to be enough.
  65. csv = self._download_webpage('http://www.imdb.com/list/export?list_id=%s&author_id=ur00000000' % list_id,
  66. list_id, 'Downloading list CSV')
  67. entries = []
  68. for item in csv.split('\n')[1:]:
  69. cols = item.split(',')
  70. if len(cols) < 2:
  71. continue
  72. item_id = cols[1][1:-1]
  73. if item_id.startswith('vi'):
  74. entries.append(self.url_result('http://www.imdb.com/video/imdb/%s' % item_id, 'Imdb'))
  75. return self.playlist_result(entries, list_id, list_title)