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.

82 lines
2.8 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
  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. webpage = self._download_webpage(url, list_id)
  61. list_code = self._search_regex(
  62. r'(?s)<div\s+class="list\sdetail">(.*?)class="see-more"',
  63. webpage, 'list code')
  64. entries = [
  65. self.url_result('http://www.imdb.com' + m, 'Imdb')
  66. for m in re.findall(r'href="(/video/imdb/vi[^"]+)"', webpage)]
  67. list_title = self._html_search_regex(
  68. r'<h1 class="header">(.*?)</h1>', webpage, 'list title')
  69. return self.playlist_result(entries, list_id, list_title)