]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/ntvru.py
   2 from __future__ 
import unicode_literals
 
   4 from .common 
import InfoExtractor
 
  12 class NTVRuIE(InfoExtractor
): 
  14     _VALID_URL 
= r
'https?://(?:www\.)?ntv\.ru/(?:[^/]+/)*(?P<id>[^/?#&]+)' 
  17         'url': 'http://www.ntv.ru/novosti/863142/', 
  18         'md5': 'ba7ea172a91cb83eb734cad18c10e723', 
  22             'title': 'Командующий Черноморским флотом провел переговоры в штабе ВМС Украины', 
  23             'description': 'Командующий Черноморским флотом провел переговоры в штабе ВМС Украины', 
  24             'thumbnail': r
're:^http://.*\.jpg', 
  28         'url': 'http://www.ntv.ru/video/novosti/750370/', 
  29         'md5': 'adecff79691b4d71e25220a191477124', 
  33             'title': 'Родные пассажиров пропавшего Boeing не верят в трагический исход', 
  34             'description': 'Родные пассажиров пропавшего Boeing не верят в трагический исход', 
  35             'thumbnail': r
're:^http://.*\.jpg', 
  39         'url': 'http://www.ntv.ru/peredacha/segodnya/m23700/o232416', 
  40         'md5': '82dbd49b38e3af1d00df16acbeab260c', 
  44             'title': '«Сегодня». 21 марта 2014 года. 16:00', 
  45             'description': '«Сегодня». 21 марта 2014 года. 16:00', 
  46             'thumbnail': r
're:^http://.*\.jpg', 
  50         'url': 'http://www.ntv.ru/kino/Koma_film', 
  51         'md5': 'f825770930937aa7e5aca0dc0d29319a', 
  55             'title': 'Остросюжетный фильм «Кома»', 
  56             'description': 'Остросюжетный фильм «Кома»', 
  57             'thumbnail': r
're:^http://.*\.jpg', 
  61         'url': 'http://www.ntv.ru/serial/Delo_vrachey/m31760/o233916/', 
  62         'md5': '9320cd0e23f3ea59c330dc744e06ff3b', 
  66             'title': '«Дело врачей»: «Деревце жизни»', 
  67             'description': '«Дело врачей»: «Деревце жизни»', 
  68             'thumbnail': r
're:^http://.*\.jpg', 
  74         r
'<meta property="og:url" content="http://www\.ntv\.ru/video/(\d+)', 
  75         r
'<video embed=[^>]+><id>(\d+)</id>', 
  76         r
'<video restriction[^>]+><key>(\d+)</key>', 
  79     def _real_extract(self
, url
): 
  80         video_id 
= self
._match
_id
(url
) 
  82         webpage 
= self
._download
_webpage
(url
, video_id
) 
  84         video_url 
= self
._og
_search
_property
( 
  85             ('video', 'video:iframe'), webpage
, default
=None) 
  87             video_id 
= self
._search
_regex
( 
  88                 r
'https?://(?:www\.)?ntv\.ru/video/(?:embed/)?(\d+)', 
  89                 video_url
, 'video id', default
=None) 
  92             video_id 
= self
._html
_search
_regex
( 
  93                 self
._VIDEO
_ID
_REGEXES
, webpage
, 'video id') 
  95         player 
= self
._download
_xml
( 
  96             'http://www.ntv.ru/vi%s/' % video_id
, 
  97             video_id
, 'Downloading video XML') 
  99         title 
= clean_html(xpath_text(player
, './data/title', 'title', fatal
=True)) 
 100         description 
= clean_html(xpath_text(player
, './data/description', 'description')) 
 102         video 
= player
.find('./data/video') 
 103         video_id 
= xpath_text(video
, './id', 'video id') 
 104         thumbnail 
= xpath_text(video
, './splash', 'thumbnail') 
 105         duration 
= int_or_none(xpath_text(video
, './totaltime', 'duration')) 
 106         view_count 
= int_or_none(xpath_text(video
, './views', 'view count')) 
 108         token 
= self
._download
_webpage
( 
 109             'http://stat.ntv.ru/services/access/token', 
 110             video_id
, 'Downloading access token') 
 113         for format_id 
in ['', 'hi', 'webm']: 
 114             file_ 
= video
.find('./%sfile' % format_id
) 
 117             size 
= video
.find('./%ssize' % format_id
) 
 119                 'url': 'http://media2.ntv.ru/vod/%s&tok=%s' % (file_
.text
, token
), 
 120                 'filesize': int_or_none(size
.text 
if size 
is not None else None), 
 122         self
._sort
_formats
(formats
) 
 127             'description': description
, 
 128             'thumbnail': thumbnail
, 
 129             'duration': duration
, 
 130             'view_count': view_count
,