1 # -*- coding: utf-8 -*-
2 from __future__ import unicode_literals
6 from .common import InfoExtractor
13 class TeacherTubeIE(InfoExtractor):
14 IE_NAME = 'teachertube'
15 IE_DESC = 'teachertube.com videos'
17 _VALID_URL = r'https?://(?:www\.)?teachertube\.com/(viewVideo\.php\?video_id=|music\.php\?music_id=|video/(?:[\da-z-]+-)?|audio/)(?P<id>\d+)'
20 'url': 'http://www.teachertube.com/viewVideo.php?video_id=339997',
21 'md5': 'f9434ef992fd65936d72999951ee254c',
25 'title': 'Measures of dispersion from a frequency table',
26 'description': 'Measures of dispersion from a frequency table',
27 'thumbnail': 're:http://.*\.jpg',
30 'url': 'http://www.teachertube.com/viewVideo.php?video_id=340064',
31 'md5': '0d625ec6bc9bf50f70170942ad580676',
35 'title': 'How to Make Paper Dolls _ Paper Art Projects',
36 'description': 'Learn how to make paper dolls in this simple',
37 'thumbnail': 're:http://.*\.jpg',
40 'url': 'http://www.teachertube.com/music.php?music_id=8805',
41 'md5': '01e8352006c65757caf7b961f6050e21',
45 'title': 'PER ASPERA AD ASTRA',
46 'description': 'RADIJSKA EMISIJA ZRAKOPLOVNE TEHNI?KE ?KOLE P',
49 'url': 'http://www.teachertube.com/video/intro-video-schleicher-297790',
50 'md5': '9c79fbb2dd7154823996fc28d4a26998',
54 'title': 'Intro Video - Schleicher',
55 'description': 'Intro Video - Why to flip, how flipping will',
59 def _real_extract(self, url):
60 video_id = self._match_id(url)
61 webpage = self._download_webpage(url, video_id)
63 title = self._html_search_meta('title', webpage, 'title', fatal=True)
64 TITLE_SUFFIX = ' - TeacherTube'
65 if title.endswith(TITLE_SUFFIX):
66 title = title[:-len(TITLE_SUFFIX)].strip()
68 description = self._html_search_meta('description', webpage, 'description')
70 description = description.strip()
72 quality = qualities(['mp3', 'flv', 'mp4'])
74 media_urls = re.findall(r'data-contenturl="([^"]+)"', webpage)
75 media_urls.extend(re.findall(r'var\s+filePath\s*=\s*"([^"]+)"', webpage))
76 media_urls.extend(re.findall(r'\'file\'\s*:\s*["\']([^"\']+)["\'],', webpage))
81 'quality': quality(determine_ext(media_url))
82 } for media_url in set(media_urls)
85 self._sort_formats(formats)
90 'thumbnail': self._html_search_regex(r'\'image\'\s*:\s*["\']([^"\']+)["\']', webpage, 'thumbnail'),
92 'description': description,
96 class TeacherTubeUserIE(InfoExtractor):
97 IE_NAME = 'teachertube:user:collection'
98 IE_DESC = 'teachertube.com user and collection videos'
100 _VALID_URL = r'https?://(?:www\.)?teachertube\.com/(user/profile|collection)/(?P<user>[0-9a-zA-Z]+)/?'
102 _MEDIA_RE = r'''(?sx)
103 class="?sidebar_thumb_time"?>[0-9:]+</div>
105 <a\s+href="(https?://(?:www\.)?teachertube\.com/(?:video|audio)/[^"]+)"
108 'url': 'http://www.teachertube.com/user/profile/rbhagwati2',
112 'playlist_mincount': 179,
115 def _real_extract(self, url):
116 mobj = re.match(self._VALID_URL, url)
117 user_id = mobj.group('user')
120 webpage = self._download_webpage(url, user_id)
121 urls.extend(re.findall(self._MEDIA_RE, webpage))
123 pages = re.findall(r'/ajax-user/user-videos/%s\?page=([0-9]+)' % user_id, webpage)[:-1]
125 more = 'http://www.teachertube.com/ajax-user/user-videos/%s?page=%s' % (user_id, p)
126 webpage = self._download_webpage(more, user_id, 'Downloading page %s/%s' % (p, len(pages)))
127 video_urls = re.findall(self._MEDIA_RE, webpage)
128 urls.extend(video_urls)
130 entries = [self.url_result(vurl, 'TeacherTube') for vurl in urls]
131 return self.playlist_result(entries, user_id)