]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/vessel.py
2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
14 class VesselIE(InfoExtractor
):
15 _VALID_URL
= r
'https?://(?:www\.)?vessel\.com/videos/(?P<id>[0-9a-zA-Z]+)'
16 _API_URL_TEMPLATE
= 'https://www.vessel.com/api/view/items/%s'
17 _LOGIN_URL
= 'https://www.vessel.com/api/account/login'
18 _NETRC_MACHINE
= 'vessel'
20 'url': 'https://www.vessel.com/videos/HDN7G5UMs',
21 'md5': '455cdf8beb71c6dd797fd2f3818d05c4',
25 'title': 'Nvidia GeForce GTX Titan X - The Best Video Card on the Market?',
26 'thumbnail': 're:^https?://.*\.jpg$',
27 'upload_date': '20150317',
28 'description': 'Did Nvidia pull out all the stops on the Titan X, or does its performance leave something to be desired?',
34 def make_json_request(url
, data
):
35 payload
= json
.dumps(data
).encode('utf-8')
36 req
= sanitized_Request(url
, payload
)
37 req
.add_header('Content-Type', 'application/json; charset=utf-8')
41 def find_assets(data
, asset_type
, asset_id
=None):
42 for asset
in data
.get('assets', []):
43 if not asset
.get('type') == asset_type
:
45 elif asset_id
is not None and not asset
.get('id') == asset_id
:
50 def _check_access_rights(self
, data
):
51 access_info
= data
.get('__view', {})
52 if not access_info
.get('allow_access', True):
53 err_code
= access_info
.get('error_code') or ''
54 if err_code
== 'ITEM_PAID_ONLY':
56 'This video requires subscription.', expected
=True)
59 'Access to this content is restricted. (%s said: %s)' % (self
.IE_NAME
, err_code
), expected
=True)
62 (username
, password
) = self
._get
_login
_info
()
72 login_request
= VesselIE
.make_json_request(self
._LOGIN
_URL
, data
)
73 self
._download
_webpage
(login_request
, None, False, 'Wrong login info')
75 def _real_initialize(self
):
78 def _real_extract(self
, url
):
79 video_id
= self
._match
_id
(url
)
81 webpage
= self
._download
_webpage
(url
, video_id
)
82 data
= self
._parse
_json
(self
._search
_regex
(
83 r
'App\.bootstrapData\((.*?)\);', webpage
, 'data'), video_id
)
84 asset_id
= data
['model']['data']['id']
86 req
= VesselIE
.make_json_request(
87 self
._API
_URL
_TEMPLATE
% asset_id
, {'client': 'web'})
88 data
= self
._download
_json
(req
, video_id
)
89 video_asset_id
= data
.get('main_video_asset')
91 self
._check
_access
_rights
(data
)
95 VesselIE
.find_assets(data
, 'video', asset_id
=video_asset_id
))
97 raise ExtractorError('No video assets found')
100 for f
in video_asset
.get('sources', []):
101 if f
['name'] == 'hls-index':
102 formats
.extend(self
._extract
_m
3u8_formats
(
103 f
['location'], video_id
, ext
='mp4', m3u8_id
='m3u8'))
106 'format_id': f
['name'],
107 'tbr': f
.get('bitrate'),
108 'height': f
.get('height'),
109 'width': f
.get('width'),
110 'url': f
['location'],
112 self
._sort
_formats
(formats
)
115 for im_asset
in VesselIE
.find_assets(data
, 'image'):
117 'url': im_asset
['location'],
118 'width': im_asset
.get('width', 0),
119 'height': im_asset
.get('height', 0),
124 'title': data
['title'],
126 'thumbnails': thumbnails
,
127 'description': data
.get('short_description'),
128 'duration': data
.get('duration'),
129 'comment_count': data
.get('comment_count'),
130 'like_count': data
.get('like_count'),
131 'view_count': data
.get('view_count'),
132 'timestamp': parse_iso8601(data
.get('released_at')),