]>
Commit | Line | Data |
---|---|---|
b4e74474 | 1 | # -*- coding: utf-8 -*- |
2 | from __future__ import unicode_literals | |
3 | ||
4 | import re | |
5 | ||
6 | from .common import InfoExtractor | |
f0a6c3d2 S |
7 | from ..utils import ( |
8 | qualities, | |
9 | determine_ext, | |
10 | ) | |
b4e74474 | 11 | |
12 | ||
13 | class TeacherTubeIE(InfoExtractor): | |
14 | IE_NAME = 'teachertube' | |
15 | IE_DESC = 'teachertube.com videos' | |
16 | ||
1e07fea2 | 17 | _VALID_URL = r'https?://(?:www\.)?teachertube\.com/(viewVideo\.php\?video_id=|music\.php\?music_id=|video/(?:[\da-z-]+-)?|audio/)(?P<id>\d+)' |
b4e74474 | 18 | |
19 | _TESTS = [{ | |
20 | 'url': 'http://www.teachertube.com/viewVideo.php?video_id=339997', | |
21 | 'md5': 'f9434ef992fd65936d72999951ee254c', | |
22 | 'info_dict': { | |
23 | 'id': '339997', | |
24 | 'ext': 'mp4', | |
9a2dc4f7 S |
25 | 'title': 'Measures of dispersion from a frequency table', |
26 | 'description': 'Measures of dispersion from a frequency table', | |
b4e74474 | 27 | 'thumbnail': 're:http://.*\.jpg', |
28 | }, | |
29 | }, { | |
30 | 'url': 'http://www.teachertube.com/viewVideo.php?video_id=340064', | |
31 | 'md5': '0d625ec6bc9bf50f70170942ad580676', | |
32 | 'info_dict': { | |
33 | 'id': '340064', | |
34 | 'ext': 'mp4', | |
35 | 'title': 'How to Make Paper Dolls _ Paper Art Projects', | |
9a2dc4f7 | 36 | 'description': 'Learn how to make paper dolls in this simple', |
b4e74474 | 37 | 'thumbnail': 're:http://.*\.jpg', |
38 | }, | |
f0a6c3d2 S |
39 | }, { |
40 | 'url': 'http://www.teachertube.com/music.php?music_id=8805', | |
41 | 'md5': '01e8352006c65757caf7b961f6050e21', | |
42 | 'info_dict': { | |
43 | 'id': '8805', | |
44 | 'ext': 'mp3', | |
45 | 'title': 'PER ASPERA AD ASTRA', | |
9a2dc4f7 | 46 | 'description': 'RADIJSKA EMISIJA ZRAKOPLOVNE TEHNI?KE ?KOLE P', |
f0a6c3d2 | 47 | }, |
1e07fea2 S |
48 | }, { |
49 | 'url': 'http://www.teachertube.com/video/intro-video-schleicher-297790', | |
50 | 'md5': '9c79fbb2dd7154823996fc28d4a26998', | |
51 | 'info_dict': { | |
52 | 'id': '297790', | |
53 | 'ext': 'mp4', | |
54 | 'title': 'Intro Video - Schleicher', | |
55 | 'description': 'Intro Video - Why to flip, how flipping will', | |
56 | }, | |
b4e74474 | 57 | }] |
58 | ||
59 | def _real_extract(self, url): | |
60 | mobj = re.match(self._VALID_URL, url) | |
61 | video_id = mobj.group('id') | |
62 | ||
63 | webpage = self._download_webpage(url, video_id) | |
64 | ||
1a30deca | 65 | title = self._html_search_meta('title', webpage, 'title', fatal=True) |
9a2dc4f7 S |
66 | TITLE_SUFFIX = ' - TeacherTube' |
67 | if title.endswith(TITLE_SUFFIX): | |
68 | title = title[:-len(TITLE_SUFFIX)].strip() | |
69 | ||
70 | description = self._html_search_meta('description', webpage, 'description') | |
71 | if description: | |
72 | description = description.strip() | |
73 | ||
f0a6c3d2 S |
74 | quality = qualities(['mp3', 'flv', 'mp4']) |
75 | ||
9a2dc4f7 S |
76 | media_urls = re.findall(r'data-contenturl="([^"]+)"', webpage) |
77 | media_urls.extend(re.findall(r'var\s+filePath\s*=\s*"([^"]+)"', webpage)) | |
c7df67ed | 78 | media_urls.extend(re.findall(r'\'file\'\s*:\s*["\']([^"\']+)["\'],', webpage)) |
702e5220 | 79 | |
f0a6c3d2 S |
80 | formats = [ |
81 | { | |
82 | 'url': media_url, | |
83 | 'quality': quality(determine_ext(media_url)) | |
702e5220 | 84 | } for media_url in set(media_urls) |
f0a6c3d2 | 85 | ] |
b4e74474 | 86 | |
87 | self._sort_formats(formats) | |
88 | ||
89 | return { | |
90 | 'id': video_id, | |
9a2dc4f7 | 91 | 'title': title, |
c7df67ed | 92 | 'thumbnail': self._html_search_regex(r'\'image\'\s*:\s*["\']([^"\']+)["\']', webpage, 'thumbnail'), |
b4e74474 | 93 | 'formats': formats, |
9a2dc4f7 | 94 | 'description': description, |
b4e74474 | 95 | } |
96 | ||
97 | ||
31a196d7 PP |
98 | class TeacherTubeUserIE(InfoExtractor): |
99 | IE_NAME = 'teachertube:user:collection' | |
100 | IE_DESC = 'teachertube.com user and collection videos' | |
b4e74474 | 101 | |
31a196d7 | 102 | _VALID_URL = r'https?://(?:www\.)?teachertube\.com/(user/profile|collection)/(?P<user>[0-9a-zA-Z]+)/?' |
b4e74474 | 103 | |
1a30deca PH |
104 | _MEDIA_RE = r'''(?sx) |
105 | class="?sidebar_thumb_time"?>[0-9:]+</div> | |
106 | \s* | |
107 | <a\s+href="(https?://(?:www\.)?teachertube\.com/(?:video|audio)/[^"]+)" | |
108 | ''' | |
22a6f150 PH |
109 | _TEST = { |
110 | 'url': 'http://www.teachertube.com/user/profile/rbhagwati2', | |
111 | 'info_dict': { | |
112 | 'id': 'rbhagwati2' | |
113 | }, | |
114 | 'playlist_mincount': 179, | |
115 | } | |
7aeb67b3 | 116 | |
b4e74474 | 117 | def _real_extract(self, url): |
118 | mobj = re.match(self._VALID_URL, url) | |
119 | user_id = mobj.group('user') | |
120 | ||
31a196d7 PP |
121 | urls = [] |
122 | webpage = self._download_webpage(url, user_id) | |
7aeb67b3 | 123 | urls.extend(re.findall(self._MEDIA_RE, webpage)) |
5f6a1245 | 124 | |
1a30deca | 125 | pages = re.findall(r'/ajax-user/user-videos/%s\?page=([0-9]+)' % user_id, webpage)[:-1] |
31a196d7 PP |
126 | for p in pages: |
127 | more = 'http://www.teachertube.com/ajax-user/user-videos/%s?page=%s' % (user_id, p) | |
1a30deca PH |
128 | webpage = self._download_webpage(more, user_id, 'Downloading page %s/%s' % (p, len(pages))) |
129 | video_urls = re.findall(self._MEDIA_RE, webpage) | |
130 | urls.extend(video_urls) | |
b4e74474 | 131 | |
1a30deca | 132 | entries = [self.url_result(vurl, 'TeacherTube') for vurl in urls] |
b4e74474 | 133 | return self.playlist_result(entries, user_id) |