]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/techtalks.py
[extractor] Common function `_match_valid_url`
[yt-dlp.git] / yt_dlp / extractor / techtalks.py
CommitLineData
c1a3c9dd
S
1from __future__ import unicode_literals
2
d21ab292
JMF
3import re
4
5from .common import InfoExtractor
6from ..utils import (
7 get_element_by_attribute,
8 clean_html,
9)
10
11
12class TechTalksIE(InfoExtractor):
6eb5503b 13 _VALID_URL = r'https?://techtalks\.tv/talks/(?:[^/]+/)?(?P<id>\d+)'
d21ab292 14
6eb5503b 15 _TESTS = [{
c1a3c9dd
S
16 'url': 'http://techtalks.tv/talks/learning-topic-models-going-beyond-svd/57758/',
17 'info_dict': {
18 'id': '57758',
19 'title': 'Learning Topic Models --- Going beyond SVD',
20 },
21 'playlist': [
d21ab292 22 {
c1a3c9dd
S
23 'info_dict': {
24 'id': '57758',
25 'ext': 'flv',
26 'title': 'Learning Topic Models --- Going beyond SVD',
d21ab292
JMF
27 },
28 },
29 {
c1a3c9dd
S
30 'info_dict': {
31 'id': '57758-slides',
32 'ext': 'flv',
33 'title': 'Learning Topic Models --- Going beyond SVD',
d21ab292
JMF
34 },
35 },
36 ],
c1a3c9dd 37 'params': {
d21ab292 38 # rtmp download
c1a3c9dd 39 'skip_download': True,
d21ab292 40 },
6eb5503b
S
41 }, {
42 'url': 'http://techtalks.tv/talks/57758',
43 'only_matching': True,
44 }]
d21ab292
JMF
45
46 def _real_extract(self, url):
5ad28e7f 47 mobj = self._match_valid_url(url)
d21ab292
JMF
48 talk_id = mobj.group('id')
49 webpage = self._download_webpage(url, talk_id)
c1a3c9dd
S
50 rtmp_url = self._search_regex(
51 r'netConnectionUrl: \'(.*?)\'', webpage, 'rtmp url')
52 play_path = self._search_regex(
53 r'href=\'(.*?)\' [^>]*id="flowplayer_presenter"',
54 webpage, 'presenter play path')
d21ab292
JMF
55 title = clean_html(get_element_by_attribute('class', 'title', webpage))
56 video_info = {
c1a3c9dd
S
57 'id': talk_id,
58 'title': title,
59 'url': rtmp_url,
60 'play_path': play_path,
61 'ext': 'flv',
62 }
d21ab292
JMF
63 m_slides = re.search(r'<a class="slides" href=\'(.*?)\'', webpage)
64 if m_slides is None:
65 return video_info
66 else:
c1a3c9dd
S
67 return {
68 '_type': 'playlist',
69 'id': talk_id,
70 'title': title,
71 'entries': [
72 video_info,
73 # The slides video
74 {
75 'id': talk_id + '-slides',
76 'title': title,
77 'url': rtmp_url,
78 'play_path': m_slides.group(1),
79 'ext': 'flv',
80 },
81 ],
82 }