/youtube_dl/extractor/imdb.py

https://gitlab.com/shinvdu/youtube-dl · Python · 84 lines · 72 code · 12 blank · 0 comment · 2 complexity · 8f0a8389a89d2ae9fdfc3582a55536a1 MD5 · raw file

  1. from __future__ import unicode_literals
  2. import re
  3. import json
  4. from .common import InfoExtractor
  5. from ..compat 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. 'info_dict': {
  15. 'id': '2524815897',
  16. 'ext': 'mp4',
  17. 'title': 'Ice Age: Continental Drift Trailer (No. 2) - IMDb',
  18. 'description': 'md5:9061c2219254e5d14e03c25c98e96a81',
  19. }
  20. }
  21. def _real_extract(self, url):
  22. video_id = self._match_id(url)
  23. webpage = self._download_webpage('http://www.imdb.com/video/imdb/vi%s' % video_id, video_id)
  24. descr = self._html_search_regex(
  25. r'(?s)<span itemprop="description">(.*?)</span>',
  26. webpage, 'description', fatal=False)
  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. 'Downloading info for %s format' % f_id)
  36. json_data = self._search_regex(
  37. r'<script[^>]+class="imdb-player-data"[^>]*?>(.*?)</script>',
  38. format_page, '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 = 'imdb:list'
  54. IE_DESC = 'Internet Movie Database lists'
  55. _VALID_URL = r'http://www\.imdb\.com/list/(?P<id>[\da-zA-Z_-]{11})'
  56. _TEST = {
  57. 'url': 'http://www.imdb.com/list/JFs9NWw6XI0',
  58. 'info_dict': {
  59. 'id': 'JFs9NWw6XI0',
  60. 'title': 'March 23, 2012 Releases',
  61. },
  62. 'playlist_count': 7,
  63. }
  64. def _real_extract(self, url):
  65. list_id = self._match_id(url)
  66. webpage = self._download_webpage(url, list_id)
  67. entries = [
  68. self.url_result('http://www.imdb.com' + m, 'Imdb')
  69. for m in re.findall(r'href="(/video/imdb/vi[^"]+)"\s+data-type="playlist"', webpage)]
  70. list_title = self._html_search_regex(
  71. r'<h1 class="header">(.*?)</h1>', webpage, 'list title')
  72. return self.playlist_result(entries, list_id, list_title)