]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/yandexdisk.py
2 from __future__
import unicode_literals
4 from .common
import InfoExtractor
5 from ..compat
import compat_str
15 class YandexDiskIE(InfoExtractor
):
16 _VALID_URL
= r
'https?://yadi\.sk/[di]/(?P<id>[^/?#&]+)'
19 'url': 'https://yadi.sk/i/VdOeDou8eZs6Y',
20 'md5': '33955d7ae052f15853dc41f35f17581c',
22 'id': 'VdOeDou8eZs6Y',
26 'uploader': 'y.botova',
27 'uploader_id': '300043621',
31 'url': 'https://yadi.sk/d/h3WAXvDS3Li3Ce',
32 'only_matching': True,
35 def _real_extract(self
, url
):
36 video_id
= self
._match
_id
(url
)
38 status
= self
._download
_webpage
(
39 'https://disk.yandex.com/auth/status', video_id
, query
={
45 sk
= self
._search
_regex
(
46 r
'(["\'])sk(?
:External
)?\
1\s
*:\s
*(["\'])(?P<value>(?:(?!\2).)+)\2',
47 status, 'sk', group='value')
49 webpage = self._download_webpage(url, video_id)
51 models = self._parse_json(
53 r'<script[^>]+id=["\']models
-client
[^
>]+>\s
*(\
[.+?\
])\s
*</script
',
54 webpage, 'video JSON
'),
58 model['data
'] for model in models
59 if model.get('model
') == 'resource
')
61 video_hash = data['id']
64 models = self._download_json(
65 'https
://disk
.yandex
.com
/models
/', video_id,
66 data=urlencode_postdata({
67 '_model
.0': 'videoInfo
',
69 '_model
.1': 'do
-get
-resource
-url
',
73 }), query={'_m
': 'videoInfo
'})['models
']
75 videos = try_get(models, lambda x: x[0]['data
']['videos
'], list) or []
77 models, lambda x: x[1]['data
']['file'], compat_str)
83 'format_id
': 'source
',
84 'ext
': determine_ext(title, 'mp4
'),
88 format_url = video.get('url
')
91 if determine_ext(format_url) == 'm3u8
':
92 formats.extend(self._extract_m3u8_formats(
93 format_url, video_id, 'mp4
', entry_protocol='m3u8_native
',
94 m3u8_id='hls
', fatal=False))
99 self._sort_formats(formats)
101 duration = float_or_none(try_get(
102 models, lambda x: x[0]['data
']['duration
']), 1000)
104 data, lambda x: x['user
']['display_name
'], compat_str)
105 uploader_id = try_get(
106 data, lambda x: x['user
']['uid
'], compat_str)
107 view_count = int_or_none(try_get(
108 data, lambda x: x['meta
']['views_counter
']))
113 'duration
': duration,
114 'uploader
': uploader,
115 'uploader_id
': uploader_id,
116 'view_count
': view_count,