]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/imdb.py
   1 from __future__ 
import unicode_literals
 
   5 from .common 
import InfoExtractor
 
  15 class ImdbIE(InfoExtractor
): 
  17     IE_DESC 
= 'Internet Movie Database trailers' 
  18     _VALID_URL 
= r
'https?://(?:www|m)\.imdb\.com/(?:video|title|list).+?[/-]vi(?P<id>\d+)' 
  21         'url': 'http://www.imdb.com/video/imdb/vi2524815897', 
  25             'title': 'No. 2 from Ice Age: Continental Drift (2012)', 
  26             'description': 'md5:87bd0bdc61e351f21f20d2d7441cb4e7', 
  29         'url': 'http://www.imdb.com/video/_/vi2524815897', 
  30         'only_matching': True, 
  32         'url': 'http://www.imdb.com/title/tt1667889/?ref_=ext_shr_eml_vi#lb-vi2524815897', 
  33         'only_matching': True, 
  35         'url': 'http://www.imdb.com/title/tt1667889/#lb-vi2524815897', 
  36         'only_matching': True, 
  38         'url': 'http://www.imdb.com/videoplayer/vi1562949145', 
  39         'only_matching': True, 
  41         'url': 'http://www.imdb.com/title/tt4218696/videoplayer/vi2608641561', 
  42         'only_matching': True, 
  44         'url': 'https://www.imdb.com/list/ls009921623/videoplayer/vi260482329', 
  45         'only_matching': True, 
  48     def _real_extract(self
, url
): 
  49         video_id 
= self
._match
_id
(url
) 
  50         webpage 
= self
._download
_webpage
( 
  51             'https://www.imdb.com/videoplayer/vi' + video_id
, video_id
) 
  52         video_metadata 
= self
._parse
_json
(self
._search
_regex
( 
  53             r
'window\.IMDbReactInitialState\.push\(({.+?})\);', webpage
, 
  54             'video metadata'), video_id
)['videos']['videoMetadata']['vi' + video_id
] 
  55         title 
= self
._html
_search
_meta
( 
  56             ['og:title', 'twitter:title'], webpage
) or self
._html
_search
_regex
( 
  57             r
'<title>(.+?)</title>', webpage
, 'title', fatal
=False) or video_metadata
['title'] 
  59         quality 
= qualities(('SD', '480p', '720p', '1080p')) 
  61         for encoding 
in video_metadata
.get('encodings', []): 
  62             if not encoding 
or not isinstance(encoding
, dict): 
  64             video_url 
= url_or_none(encoding
.get('videoUrl')) 
  67             ext 
= mimetype2ext(encoding
.get( 
  68                 'mimeType')) or determine_ext(video_url
) 
  70                 formats
.extend(self
._extract
_m
3u8_formats
( 
  71                     video_url
, video_id
, 'mp4', entry_protocol
='m3u8_native', 
  72                     m3u8_id
='hls', fatal
=False)) 
  74             format_id 
= encoding
.get('definition') 
  76                 'format_id': format_id
, 
  79                 'quality': quality(format_id
), 
  81         self
._sort
_formats
(formats
) 
  87             'description': video_metadata
.get('description'), 
  88             'thumbnail': video_metadata
.get('slate', {}).get('url'), 
  89             'duration': parse_duration(video_metadata
.get('duration')), 
  93 class ImdbListIE(InfoExtractor
): 
  95     IE_DESC 
= 'Internet Movie Database lists' 
  96     _VALID_URL 
= r
'https?://(?:www\.)?imdb\.com/list/ls(?P<id>\d{9})(?!/videoplayer/vi\d+)' 
  98         'url': 'https://www.imdb.com/list/ls009921623/', 
 101             'title': 'The Bourne Legacy', 
 102             'description': 'A list of trailers, clips, and more from The Bourne Legacy, starring Jeremy Renner and Rachel Weisz.', 
 107     def _real_extract(self
, url
): 
 108         list_id 
= self
._match
_id
(url
) 
 109         webpage 
= self
._download
_webpage
(url
, list_id
) 
 111             self
.url_result('http://www.imdb.com' + m
, 'Imdb') 
 112             for m 
in re
.findall(r
'href="(/list/ls%s/videoplayer/vi[^"]+)"' % list_id
, webpage
)] 
 114         list_title 
= self
._html
_search
_regex
( 
 115             r
'<h1[^>]+class="[^"]*header[^"]*"[^>]*>(.*?)</h1>', 
 116             webpage
, 'list title') 
 117         list_description 
= self
._html
_search
_regex
( 
 118             r
'<div[^>]+class="[^"]*list-description[^"]*"[^>]*><p>(.*?)</p>', 
 119             webpage
, 'list description') 
 121         return self
.playlist_result(entries
, list_id
, list_title
, list_description
)