]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/npo.py
f36d446d2dd398ac48168f2181299bdfc920797f
   1 from __future__ 
import unicode_literals
 
   5 from .common 
import InfoExtractor
 
  14 class NPOIE(InfoExtractor
): 
  16     _VALID_URL 
= r
'https?://www\.npo\.nl/[^/]+/[^/]+/(?P<id>[^/?]+)' 
  20             'url': 'http://www.npo.nl/nieuwsuur/22-06-2014/VPWON_1220719', 
  21             'md5': '4b3f9c429157ec4775f2c9cb7b911016', 
  23                 'id': 'VPWON_1220719', 
  26                 'description': 'Dagelijks tussen tien en elf: nieuws, sport en achtergronden.', 
  27                 'upload_date': '20140622', 
  31             'url': 'http://www.npo.nl/de-mega-mike-mega-thomas-show/27-02-2009/VARA_101191800', 
  32             'md5': 'da50a5787dbfc1603c4ad80f31c5120b', 
  34                 'id': 'VARA_101191800', 
  36                 'title': 'De Mega Mike & Mega Thomas show', 
  37                 'description': 'md5:3b74c97fc9d6901d5a665aac0e5400f4', 
  38                 'upload_date': '20090227', 
  43             'url': 'http://www.npo.nl/tegenlicht/25-02-2013/VPWON_1169289', 
  44             'md5': 'f8065e4e5a7824068ed3c7e783178f2c', 
  46                 'id': 'VPWON_1169289', 
  48                 'title': 'Tegenlicht', 
  49                 'description': 'md5:d6476bceb17a8c103c76c3b708f05dd1', 
  50                 'upload_date': '20130225', 
  56     def _real_extract(self
, url
): 
  57         mobj 
= re
.match(self
._VALID
_URL
, url
) 
  58         video_id 
= mobj
.group('id') 
  59         return self
._get
_info
(video_id
) 
  61     def _get_info(self
, video_id
): 
  62         metadata 
= self
._download
_json
( 
  63             'http://e.omroep.nl/metadata/aflevering/%s' % video_id
, 
  65             # We have to remove the javascript callback 
  66             transform_source
=lambda j
: re
.sub(r
'parseMetadata\((.*?)\);\n//.*$', r
'\1', j
) 
  68         token_page 
= self
._download
_webpage
( 
  69             'http://ida.omroep.nl/npoplayer/i.js', 
  71             note
='Downloading token' 
  73         token 
= self
._search
_regex
(r
'npoplayer\.token = "(.+?)"', token_page
, 'token') 
  76         quality 
= qualities(['adaptive', 'wmv_sb', 'h264_sb', 'wmv_bb', 'h264_bb', 'wvc1_std', 'h264_std']) 
  77         for format_id 
in metadata
['pubopties']: 
  78             format_info 
= self
._download
_json
( 
  79                 'http://ida.omroep.nl/odi/?prid=%s&puboptions=%s&adaptive=yes&token=%s' % (video_id
, format_id
, token
), 
  80                 video_id
, 'Downloading %s JSON' % format_id
) 
  81             if format_info
.get('error_code', 0) or format_info
.get('errorcode', 0): 
  83             streams 
= format_info
.get('streams') 
  85                 video_info 
= self
._download
_json
( 
  86                     streams
[0] + '&type=json', 
  87                     video_id
, 'Downloading %s stream JSON' % format_id
) 
  89                 video_info 
= format_info
 
  90             video_url 
= video_info
.get('url') 
  93             if format_id 
== 'adaptive': 
  94                 formats
.extend(self
._extract
_m
3u8_formats
(video_url
, video_id
)) 
  98                     'format_id': format_id
, 
  99                     'quality': quality(format_id
), 
 101         self
._sort
_formats
(formats
) 
 105             'title': metadata
['titel'], 
 106             'description': metadata
['info'], 
 107             'thumbnail': metadata
.get('images', [{'url': None}])[-1]['url'], 
 108             'upload_date': unified_strdate(metadata
.get('gidsdatum')), 
 109             'duration': parse_duration(metadata
.get('tijdsduur')), 
 114 class TegenlichtVproIE(NPOIE
): 
 115     IE_NAME 
= 'tegenlicht.vpro.nl' 
 116     _VALID_URL 
= r
'https?://tegenlicht\.vpro\.nl/afleveringen/.*?' 
 120             'url': 'http://tegenlicht.vpro.nl/afleveringen/2012-2013/de-toekomst-komt-uit-afrika.html', 
 121             'md5': 'f8065e4e5a7824068ed3c7e783178f2c', 
 123                 'id': 'VPWON_1169289', 
 125                 'title': 'Tegenlicht', 
 126                 'description': 'md5:d6476bceb17a8c103c76c3b708f05dd1', 
 127                 'upload_date': '20130225', 
 132     def _real_extract(self
, url
): 
 133         name 
= url_basename(url
) 
 134         webpage 
= self
._download
_webpage
(url
, name
) 
 135         urn 
= self
._html
_search
_meta
('mediaurn', webpage
) 
 136         info_page 
= self
._download
_json
( 
 137             'http://rs.vpro.nl/v2/api/media/%s.json' % urn
, name
) 
 138         return self
._get
_info
(info_page
['mid'])