2 from __future__ import unicode_literals
6 from .common import InfoExtractor
14 class TeacherTubeIE(InfoExtractor):
15 IE_NAME = 'teachertube'
16 IE_DESC = 'teachertube.com videos'
18 _VALID_URL = r'https?://(?:www\.)?teachertube\.com/(viewVideo\.php\?video_id=|music\.php\?music_id=|video/(?:[\da-z-]+-)?|audio/)(?P<id>\d+)'
22 'url': 'http://www.teachertube.com/viewVideo.php?video_id=339997',
23 'md5': 'f9434ef992fd65936d72999951ee254c',
27 'title': 'Measures of dispersion from a frequency table',
28 'description': 'Measures of dispersion from a frequency table',
29 'thumbnail': r're:https?://.*\.(?:jpg|png)',
33 'url': 'http://www.teachertube.com/music.php?music_id=8805',
34 'md5': '01e8352006c65757caf7b961f6050e21',
38 'title': 'PER ASPERA AD ASTRA',
39 'description': 'RADIJSKA EMISIJA ZRAKOPLOVNE TEHNI?KE ?KOLE P',
43 'url': 'http://www.teachertube.com/video/intro-video-schleicher-297790',
44 'only_matching': True,
47 def _real_extract(self, url):
48 video_id = self._match_id(url)
49 webpage = self._download_webpage(url, video_id)
51 error = self._search_regex(
52 r'<div\b[^>]+\bclass=["\']msgBox error[^>]+>([^<]+)', webpage,
53 'error', default=None)
55 raise ExtractorError('%s said: %s' % (self.IE_NAME, error), expected=True)
57 title = self._html_search_meta('title', webpage, 'title', fatal=True)
58 TITLE_SUFFIX = ' - TeacherTube'
59 if title.endswith(TITLE_SUFFIX):
60 title = title[:-len(TITLE_SUFFIX)].strip()
62 description = self._html_search_meta('description', webpage, 'description')
64 description = description.strip()
66 quality = qualities(['mp3', 'flv', 'mp4'])
68 media_urls = re.findall(r'data-contenturl="([^"]+)"', webpage)
69 media_urls.extend(re.findall(r'var\s+filePath\s*=\s*"([^"]+)"', webpage))
70 media_urls.extend(re.findall(r'\'file\'\s*:\s*["\']([^"\']+)["\'],', webpage))
75 'quality': quality(determine_ext(media_url))
76 } for media_url in set(media_urls)
79 self._sort_formats(formats)
81 thumbnail = self._og_search_thumbnail(
82 webpage, default=None) or self._html_search_meta(
88 'description': description,
89 'thumbnail': thumbnail,
94 class TeacherTubeUserIE(InfoExtractor):
95 IE_NAME = 'teachertube:user:collection'
96 IE_DESC = 'teachertube.com user and collection videos'
98 _VALID_URL = r'https?://(?:www\.)?teachertube\.com/(user/profile|collection)/(?P<user>[0-9a-zA-Z]+)/?'
100 _MEDIA_RE = r'''(?sx)
101 class="?sidebar_thumb_time"?>[0-9:]+</div>
103 <a\s+href="(https?://(?:www\.)?teachertube\.com/(?:video|audio)/[^"]+)"
106 'url': 'http://www.teachertube.com/user/profile/rbhagwati2',
110 'playlist_mincount': 179,
113 def _real_extract(self, url):
114 mobj = re.match(self._VALID_URL, url)
115 user_id = mobj.group('user')
118 webpage = self._download_webpage(url, user_id)
119 urls.extend(re.findall(self._MEDIA_RE, webpage))
121 pages = re.findall(r'/ajax-user/user-videos/%s\?page=([0-9]+)' % user_id, webpage)[:-1]
123 more = 'http://www.teachertube.com/ajax-user/user-videos/%s?page=%s' % (user_id, p)
124 webpage = self._download_webpage(more, user_id, 'Downloading page %s/%s' % (p, len(pages)))
125 video_urls = re.findall(self._MEDIA_RE, webpage)
126 urls.extend(video_urls)
128 entries = [self.url_result(vurl, 'TeacherTube') for vurl in urls]
129 return self.playlist_result(entries, user_id)