]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/mangomolo.py
1885ac7df59684767022f95c5c35ffeb65cd33d5
[youtubedl] / youtube_dl / extractor / mangomolo.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import base64
5
6 from .common import InfoExtractor
7 from ..compat import compat_urllib_parse_unquote
8 from ..utils import (
9 int_or_none,
10 )
11
12
13 class MangomoloBaseIE(InfoExtractor):
14 def _get_real_id(self, page_id):
15 return page_id
16
17 def _real_extract(self, url):
18 page_id = self._get_real_id(self._match_id(url))
19 webpage = self._download_webpage(url, page_id)
20 hidden_inputs = self._hidden_inputs(webpage)
21 m3u8_entry_protocol = 'm3u8' if self._IS_LIVE else 'm3u8_native'
22
23 format_url = self._html_search_regex(
24 [
25 r'file\s*:\s*"(https?://[^"]+?/playlist.m3u8)',
26 r'<a[^>]+href="(rtsp://[^"]+)"'
27 ], webpage, 'format url')
28 formats = self._extract_wowza_formats(
29 format_url, page_id, m3u8_entry_protocol, ['smil'])
30 self._sort_formats(formats)
31
32 return {
33 'id': page_id,
34 'title': self._live_title(page_id) if self._IS_LIVE else page_id,
35 'uploader_id': hidden_inputs.get('userid'),
36 'duration': int_or_none(hidden_inputs.get('duration')),
37 'is_live': self._IS_LIVE,
38 'formats': formats,
39 }
40
41
42 class MangomoloVideoIE(MangomoloBaseIE):
43 IE_NAME = 'mangomolo:video'
44 _VALID_URL = r'https?://admin\.mangomolo\.com/analytics/index\.php/customers/embed/video\?.*?\bid=(?P<id>\d+)'
45 _IS_LIVE = False
46
47
48 class MangomoloLiveIE(MangomoloBaseIE):
49 IE_NAME = 'mangomolo:live'
50 _VALID_URL = r'https?://admin\.mangomolo\.com/analytics/index\.php/customers/embed/index\?.*?\bchannelid=(?P<id>(?:[A-Za-z0-9+/=]|%2B|%2F|%3D)+)'
51 _IS_LIVE = True
52
53 def _get_real_id(self, page_id):
54 return base64.b64decode(compat_urllib_parse_unquote(page_id).encode()).decode()