]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/sandia.py
   2 from __future__ 
import unicode_literals
 
   8 from .common 
import InfoExtractor
 
   9 from ..compat 
import compat_urlparse
 
  19 class SandiaIE(InfoExtractor
): 
  20     IE_DESC 
= 'Sandia National Laboratories' 
  21     _VALID_URL 
= r
'https?://digitalops\.sandia\.gov/Mediasite/Play/(?P<id>[0-9a-f]+)' 
  23         'url': 'http://digitalops.sandia.gov/Mediasite/Play/24aace4429fc450fb5b38cdbf424a66e1d', 
  24         'md5': '9422edc9b9a60151727e4b6d8bef393d', 
  26             'id': '24aace4429fc450fb5b38cdbf424a66e1d', 
  28             'title': 'Xyce Software Training - Section 1', 
  29             'description': 're:(?s)SAND Number: SAND 2013-7800.{200,}', 
  30             'upload_date': '20120904', 
  35     def _real_extract(self
, url
): 
  36         video_id 
= self
._match
_id
(url
) 
  38         req 
= sanitized_Request(url
) 
  39         req
.add_header('Cookie', 'MediasitePlayerCaps=ClientPlugins=4') 
  40         webpage 
= self
._download
_webpage
(req
, video_id
) 
  42         js_path 
= self
._search
_regex
( 
  43             r
'<script type="text/javascript" src="(/Mediasite/FileServer/Presentation/[^"]+)"', 
  44             webpage
, 'JS code URL') 
  45         js_url 
= compat_urlparse
.urljoin(url
, js_path
) 
  47         js_code 
= self
._download
_webpage
( 
  48             js_url
, video_id
, note
='Downloading player') 
  50         def extract_str(key
, **args
): 
  51             return self
._search
_regex
( 
  52                 r
'Mediasite\.PlaybackManifest\.%s\s*=\s*(.+);\s*?\n' % re
.escape(key
), 
  55         def extract_data(key
, **args
): 
  56             data_json 
= extract_str(key
, **args
) 
  59             return self
._parse
_json
( 
  60                 data_json
, video_id
, transform_source
=js_to_json
) 
  63         for i 
in itertools
.count(): 
  64             fd 
= extract_data('VideoUrls[%d]' % i
, default
=None) 
  68                 'format_id': '%s' % i
, 
  69                 'format_note': fd
['MimeType'].partition('/')[2], 
  70                 'ext': mimetype2ext(fd
['MimeType']), 
  71                 'url': fd
['Location'], 
  72                 'protocol': 'f4m' if fd
['MimeType'] == 'video/x-mp4-fragmented' else None, 
  74         self
._sort
_formats
(formats
) 
  76         slide_baseurl 
= compat_urlparse
.urljoin( 
  77             url
, extract_data('SlideBaseUrl')) 
  78         slide_template 
= slide_baseurl 
+ re
.sub( 
  79             r
'\{0:D?([0-9+])\}', r
'%0\1d', extract_data('SlideImageFileNameTemplate')) 
  82         for i 
in itertools
.count(1): 
  83             sd 
= extract_str('Slides[%d]' % i
, default
=None) 
  86             timestamp 
= int_or_none(self
._search
_regex
( 
  87                 r
'^Mediasite\.PlaybackManifest\.CreateSlide\("[^"]*"\s*,\s*([0-9]+),', 
  88                 sd
, 'slide %s timestamp' % i
, fatal
=False)) 
  90                 'url': slide_template 
% i
, 
  91                 'duration': timestamp 
- last_slide_time
, 
  93             last_slide_time 
= timestamp
 
  95             'format_id': 'slides', 
  96             'protocol': 'slideshow', 
  97             'url': json
.dumps(slides
), 
  98             'preference': -10000,  # Downloader not yet written 
 100         self
._sort
_formats
(formats
) 
 102         title 
= extract_data('Title') 
 103         description 
= extract_data('Description', fatal
=False) 
 104         duration 
= int_or_none(extract_data( 
 105             'Duration', fatal
=False), scale
=1000) 
 106         upload_date 
= unified_strdate(extract_data('AirDate', fatal
=False)) 
 111             'description': description
, 
 113             'upload_date': upload_date
, 
 114             'duration': duration
,