]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/imdb.py
   1 from __future__ 
import unicode_literals
 
   5 from .common 
import InfoExtractor
 
  13 class ImdbIE(InfoExtractor
): 
  15     IE_DESC 
= 'Internet Movie Database trailers' 
  16     _VALID_URL 
= r
'https?://(?:www|m)\.imdb\.com/(?:video/[^/]+/|title/tt\d+.*?#lb-)vi(?P<id>\d+)' 
  19         'url': 'http://www.imdb.com/video/imdb/vi2524815897', 
  23             'title': 'Ice Age: Continental Drift Trailer (No. 2)', 
  24             'description': 'md5:9061c2219254e5d14e03c25c98e96a81', 
  27         'url': 'http://www.imdb.com/video/_/vi2524815897', 
  28         'only_matching': True, 
  30         'url': 'http://www.imdb.com/title/tt1667889/?ref_=ext_shr_eml_vi#lb-vi2524815897', 
  31         'only_matching': True, 
  33         'url': 'http://www.imdb.com/title/tt1667889/#lb-vi2524815897', 
  34         'only_matching': True, 
  37     def _real_extract(self
, url
): 
  38         video_id 
= self
._match
_id
(url
) 
  39         webpage 
= self
._download
_webpage
('http://www.imdb.com/video/imdb/vi%s' % video_id
, video_id
) 
  40         descr 
= self
._html
_search
_regex
( 
  41             r
'(?s)<span itemprop="description">(.*?)</span>', 
  42             webpage
, 'description', fatal
=False) 
  43         player_url 
= 'http://www.imdb.com/video/imdb/vi%s/imdb/single' % video_id
 
  44         player_page 
= self
._download
_webpage
( 
  45             player_url
, video_id
, 'Downloading player page') 
  46         # the player page contains the info for the default format, we have to 
  47         # fetch other pages for the rest of the formats 
  48         extra_formats 
= re
.findall(r
'href="(?P<url>%s.*?)".*?>(?P<name>.*?)<' % re
.escape(player_url
), player_page
) 
  50             self
._download
_webpage
( 
  51                 f_url
, video_id
, 'Downloading info for %s format' % f_name
) 
  52             for f_url
, f_name 
in extra_formats
] 
  53         format_pages
.append(player_page
) 
  55         quality 
= qualities(('SD', '480p', '720p', '1080p')) 
  57         for format_page 
in format_pages
: 
  58             json_data 
= self
._search
_regex
( 
  59                 r
'<script[^>]+class="imdb-player-data"[^>]*?>(.*?)</script>', 
  60                 format_page
, 'json data', flags
=re
.DOTALL
) 
  61             info 
= self
._parse
_json
(json_data
, video_id
, fatal
=False) 
  64             format_info 
= info
.get('videoPlayerObject', {}).get('video', {}) 
  67             video_info_list 
= format_info
.get('videoInfoList') 
  68             if not video_info_list 
or not isinstance(video_info_list
, list): 
  70             video_info 
= video_info_list
[0] 
  71             if not video_info 
or not isinstance(video_info
, dict): 
  73             video_url 
= video_info
.get('videoUrl') 
  76             format_id 
= format_info
.get('ffname') 
  78                 'format_id': format_id
, 
  80                 'ext': mimetype2ext(video_info
.get('videoMimeType')), 
  81                 'quality': quality(format_id
), 
  83         self
._sort
_formats
(formats
) 
  87             'title': remove_end(self
._og
_search
_title
(webpage
), ' - IMDb'), 
  90             'thumbnail': format_info
.get('slate'), 
  94 class ImdbListIE(InfoExtractor
): 
  96     IE_DESC 
= 'Internet Movie Database lists' 
  97     _VALID_URL 
= r
'https?://(?:www\.)?imdb\.com/list/(?P<id>[\da-zA-Z_-]{11})' 
  99         'url': 'http://www.imdb.com/list/JFs9NWw6XI0', 
 102             'title': 'March 23, 2012 Releases', 
 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="(/video/imdb/vi[^"]+)"\s+data-type="playlist"', webpage
)] 
 114         list_title 
= self
._html
_search
_regex
( 
 115             r
'<h1 class="header">(.*?)</h1>', webpage
, 'list title') 
 117         return self
.playlist_result(entries
, list_id
, list_title
)