]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/infoq.py
Merge remote-tracking branch 'lenaten/8tracks'
[yt-dlp.git] / youtube_dl / extractor / infoq.py
CommitLineData
d882161d
JMF
1from __future__ import unicode_literals
2
fda7d31a 3import base64
fda7d31a
PH
4
5from .common import InfoExtractor
1cc79574 6from ..compat import (
fda7d31a 7 compat_urllib_parse,
fda7d31a
PH
8)
9
10
11class InfoQIE(InfoExtractor):
d55433bb 12 _VALID_URL = r'https?://(?:www\.)?infoq\.com/[^/]+/(?P<id>[^/]+)$'
282cb9c7 13
9d069c47 14 _TEST = {
c0a7c608 15 'url': 'http://www.infoq.com/presentations/A-Few-of-My-Favorite-Python-Things',
edec83a0 16 'md5': 'b5ca0e0a8c1fed93b0e65e48e462f9a2',
c0a7c608
PH
17 'info_dict': {
18 'id': '12-jan-pythonthings',
19 'ext': 'mp4',
20 'description': 'Mike Pirnat presents some tips and tricks, standard libraries and third party packages that make programming in Python a richer experience.',
21 'title': 'A Few of My Favorite [Python] Things',
9d069c47 22 },
9d069c47 23 }
fda7d31a
PH
24
25 def _real_extract(self, url):
1cc79574 26 video_id = self._match_id(url)
d55433bb 27 webpage = self._download_webpage(url, video_id)
fda7d31a 28
282cb9c7
KW
29 video_title = self._html_search_regex(r'<title>(.*?)</title>', webpage, 'title')
30 video_description = self._html_search_meta('description', webpage, 'description')
fda7d31a 31
7560096d 32 # The server URL is hardcoded
282cb9c7 33 video_url = 'rtmpe://video.infoq.com/cfx/st/'
7560096d
KW
34
35 # Extract video URL
edec83a0
PH
36 encoded_id = self._search_regex(
37 r"jsclassref\s*=\s*'([^']*)'", webpage, 'encoded id')
7560096d
KW
38 real_id = compat_urllib_parse.unquote(base64.b64decode(encoded_id.encode('ascii')).decode('utf-8'))
39 playpath = 'mp4:' + real_id
fda7d31a 40
282cb9c7 41 video_filename = playpath.split('/')[-1]
fda7d31a
PH
42 video_id, extension = video_filename.split('.')
43
edec83a0
PH
44 http_base = self._search_regex(
45 r'EXPRESSINSTALL_SWF\s*=\s*"(https?://[^/"]+/)', webpage,
46 'HTTP base URL')
47
48 formats = [{
49 'format_id': 'rtmp',
50 'url': video_url,
51 'ext': extension,
52 'play_path': playpath,
53 }, {
54 'format_id': 'http',
55 'url': http_base + real_id,
56 }]
57 self._sort_formats(formats)
58
c0a7c608 59 return {
fda7d31a 60 'id': video_id,
fda7d31a 61 'title': video_title,
fda7d31a 62 'description': video_description,
edec83a0 63 'formats': formats,
c0a7c608 64 }