]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/picarto.py
2 from __future__
import unicode_literals
6 from .common
import InfoExtractor
7 from ..compat
import compat_str
17 class PicartoIE(InfoExtractor
):
18 _VALID_URL
= r
'https?://(?:www.)?picarto\.tv/(?P<id>[a-zA-Z0-9]+)'
20 'url': 'https://picarto.tv/Setz',
24 'title': 're:^Setz [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
28 'skip': 'Stream is offline',
32 def suitable(cls
, url
):
33 return False if PicartoVodIE
.suitable(url
) else super(PicartoIE
, cls
).suitable(url
)
35 def _real_extract(self
, url
):
36 channel_id
= self
._match
_id
(url
)
37 stream_page
= self
._download
_webpage
(url
, channel_id
)
39 if '>This channel does not exist' in stream_page
:
41 'Channel %s does not exist' % channel_id
, expected
=True)
43 player
= self
._parse
_json
(
45 r
'(?s)playerSettings\[\d+\]\s*=\s*(\{.+?\}\s*\n)', stream_page
,
47 channel_id
, transform_source
=js_to_json
)
49 if player
.get('online') is False:
50 raise ExtractorError('Stream is offline', expected
=True)
52 cdn_data
= self
._download
_json
(
53 'https://picarto.tv/process/channel', channel_id
,
54 data
=urlencode_postdata({'loadbalancinginfo': channel_id
}),
55 note
='Downloading load balancing info')
58 return try_get(player
, lambda x
: x
['event'][key
], compat_str
) or ''
61 'token': player
.get('token') or '',
62 'ticket': get_event('ticket'),
63 'con': int(time
.time() * 1000),
64 'type': get_event('ticket'),
65 'scope': get_event('scope'),
68 prefered_edge
= cdn_data
.get('preferedEdge')
69 default_tech
= player
.get('defaultTech')
73 for edge
in cdn_data
['edges']:
74 edge_ep
= edge
.get('ep')
75 if not edge_ep
or not isinstance(edge_ep
, compat_str
):
77 edge_id
= edge
.get('id')
78 for tech
in cdn_data
['techs']:
79 tech_label
= tech
.get('label')
80 tech_type
= tech
.get('type')
82 if edge_id
== prefered_edge
:
84 if tech_type
== default_tech
:
88 format_id
.append(edge_id
)
89 if tech_type
== 'application/x-mpegurl' or tech_label
== 'HLS':
90 format_id
.append('hls')
91 formats
.extend(self
._extract
_m
3u8_formats
(
93 'https://%s/hls/%s/index.m3u8'
94 % (edge_ep
, channel_id
), params
),
95 channel_id
, 'mp4', preference
=preference
,
96 m3u8_id
='-'.join(format_id
), fatal
=False))
98 elif tech_type
== 'video/mp4' or tech_label
== 'MP4':
99 format_id
.append('mp4')
101 'url': update_url_query(
102 'https://%s/mp4/%s.mp4' % (edge_ep
, channel_id
),
104 'format_id': '-'.join(format_id
),
105 'preference': preference
,
108 # rtmp format does not seem to work
110 self
._sort
_formats
(formats
)
112 mature
= player
.get('mature')
116 age_limit
= 18 if mature
is True else 0
120 'title': self
._live
_title
(channel_id
),
122 'thumbnail': player
.get('vodThumb'),
123 'age_limit': age_limit
,
128 class PicartoVodIE(InfoExtractor
):
129 _VALID_URL
= r
'https?://(?:www.)?picarto\.tv/videopopout/(?P<id>[^/?#&]+)'
131 'url': 'https://picarto.tv/videopopout/ArtofZod_2017.12.12.00.13.23.flv',
132 'md5': '3ab45ba4352c52ee841a28fb73f2d9ca',
134 'id': 'ArtofZod_2017.12.12.00.13.23.flv',
136 'title': 'ArtofZod_2017.12.12.00.13.23.flv',
137 'thumbnail': r
're:^https?://.*\.jpg'
140 'url': 'https://picarto.tv/videopopout/Plague',
141 'only_matching': True,
144 def _real_extract(self
, url
):
145 video_id
= self
._match
_id
(url
)
147 webpage
= self
._download
_webpage
(url
, video_id
)
149 vod_info
= self
._parse
_json
(
151 r
'(?s)#vod-player["\']\s
*,\s
*(\
{.+?\
})\s
*\
)', webpage,
153 video_id, transform_source=js_to_json)
155 formats = self._extract_m3u8_formats(
156 vod_info['vod
'], video_id, 'mp4
', entry_protocol='m3u8_native
',
158 self._sort_formats(formats)
163 'thumbnail
': vod_info.get('vodThumb
'),