/python-packages/youtube_dl/extractor/imdb.py

https://gitlab.com/gregtyka/ka-lite · Python · 85 lines · 73 code · 12 blank · 0 comment · 2 complexity · 93963d222f17a6aa6f34bc332f80f983 MD5 · raw file

  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. )
  8. class ImdbIE(InfoExtractor):
  9. IE_NAME = 'imdb'
  10. IE_DESC = 'Internet Movie Database trailers'
  11. _VALID_URL = r'http://(?:www|m)\.imdb\.com/video/imdb/vi(?P<id>\d+)'
  12. _TEST = {
  13. 'url': 'http://www.imdb.com/video/imdb/vi2524815897',
  14. 'md5': '9f34fa777ade3a6e57a054fdbcb3a068',
  15. 'info_dict': {
  16. 'id': '2524815897',
  17. 'ext': 'mp4',
  18. 'title': 'Ice Age: Continental Drift Trailer (No. 2) - IMDb',
  19. 'description': 'md5:9061c2219254e5d14e03c25c98e96a81',
  20. }
  21. }
  22. def _real_extract(self, url):
  23. video_id = self._match_id(url)
  24. webpage = self._download_webpage('http://www.imdb.com/video/imdb/vi%s' % video_id, video_id)
  25. descr = self._html_search_regex(
  26. r'(?s)<span itemprop="description">(.*?)</span>',
  27. webpage, 'description', fatal=False)
  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. _TEST = {
  58. 'url': 'http://www.imdb.com/list/JFs9NWw6XI0',
  59. 'info_dict': {
  60. 'id': 'JFs9NWw6XI0',
  61. 'title': 'March 23, 2012 Releases',
  62. },
  63. 'playlist_count': 7,
  64. }
  65. def _real_extract(self, url):
  66. list_id = self._match_id(url)
  67. webpage = self._download_webpage(url, list_id)
  68. entries = [
  69. self.url_result('http://www.imdb.com' + m, 'Imdb')
  70. for m in re.findall(r'href="(/video/imdb/vi[^"]+)"\s+data-type="playlist"', webpage)]
  71. list_title = self._html_search_regex(
  72. r'<h1 class="header">(.*?)</h1>', webpage, 'list title')
  73. return self.playlist_result(entries, list_id, list_title)