]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/imdb.py
4bafa54a21e5abbc294a3686b6b974a9bb6d4eb3
   1 from __future__ 
import unicode_literals
 
   5 from .common 
import InfoExtractor
 
   6 from ..compat 
import compat_str
 
  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 
= encoding
.get('videoUrl') 
  65             if not video_url 
or not isinstance(video_url
, compat_str
): 
  67             ext 
= determine_ext(video_url
, mimetype2ext(encoding
.get('mimeType'))) 
  69                 formats
.extend(self
._extract
_m
3u8_formats
( 
  70                     video_url
, video_id
, 'mp4', entry_protocol
='m3u8_native', 
  71                     m3u8_id
='hls', fatal
=False)) 
  73             format_id 
= encoding
.get('definition') 
  75                 'format_id': format_id
, 
  78                 'quality': quality(format_id
), 
  80         self
._sort
_formats
(formats
) 
  86             'description': video_metadata
.get('description'), 
  87             'thumbnail': video_metadata
.get('slate', {}).get('url'), 
  88             'duration': parse_duration(video_metadata
.get('duration')), 
  92 class ImdbListIE(InfoExtractor
): 
  94     IE_DESC 
= 'Internet Movie Database lists' 
  95     _VALID_URL 
= r
'https?://(?:www\.)?imdb\.com/list/ls(?P<id>\d{9})(?!/videoplayer/vi\d+)' 
  97         'url': 'https://www.imdb.com/list/ls009921623/', 
 100             'title': 'The Bourne Legacy', 
 101             'description': 'A list of trailers, clips, and more from The Bourne Legacy, starring Jeremy Renner and Rachel Weisz.', 
 106     def _real_extract(self
, url
): 
 107         list_id 
= self
._match
_id
(url
) 
 108         webpage 
= self
._download
_webpage
(url
, list_id
) 
 110             self
.url_result('http://www.imdb.com' + m
, 'Imdb') 
 111             for m 
in re
.findall(r
'href="(/list/ls%s/videoplayer/vi[^"]+)"' % list_id
, webpage
)] 
 113         list_title 
= self
._html
_search
_regex
( 
 114             r
'<h1[^>]+class="[^"]*header[^"]*"[^>]*>(.*?)</h1>', 
 115             webpage
, 'list title') 
 116         list_description 
= self
._html
_search
_regex
( 
 117             r
'<div[^>]+class="[^"]*list-description[^"]*"[^>]*><p>(.*?)</p>', 
 118             webpage
, 'list description') 
 120         return self
.playlist_result(entries
, list_id
, list_title
, list_description
)