]>
Commit | Line | Data |
---|---|---|
1 | import re | |
2 | ||
3 | from .common import InfoExtractor | |
4 | from ..utils import ( | |
5 | ExtractorError, | |
6 | determine_ext, | |
7 | qualities, | |
8 | ) | |
9 | ||
10 | ||
11 | class TeacherTubeIE(InfoExtractor): | |
12 | _WORKING = False | |
13 | IE_NAME = 'teachertube' | |
14 | IE_DESC = 'teachertube.com videos' | |
15 | ||
16 | _VALID_URL = r'https?://(?:www\.)?teachertube\.com/(viewVideo\.php\?video_id=|music\.php\?music_id=|video/(?:[\da-z-]+-)?|audio/)(?P<id>\d+)' | |
17 | ||
18 | _TESTS = [{ | |
19 | # flowplayer | |
20 | 'url': 'http://www.teachertube.com/viewVideo.php?video_id=339997', | |
21 | 'md5': 'f9434ef992fd65936d72999951ee254c', | |
22 | 'info_dict': { | |
23 | 'id': '339997', | |
24 | 'ext': 'mp4', | |
25 | 'title': 'Measures of dispersion from a frequency table', | |
26 | 'description': 'Measures of dispersion from a frequency table', | |
27 | 'thumbnail': r're:https?://.*\.(?:jpg|png)', | |
28 | }, | |
29 | }, { | |
30 | # jwplayer | |
31 | 'url': 'http://www.teachertube.com/music.php?music_id=8805', | |
32 | 'md5': '01e8352006c65757caf7b961f6050e21', | |
33 | 'info_dict': { | |
34 | 'id': '8805', | |
35 | 'ext': 'mp3', | |
36 | 'title': 'PER ASPERA AD ASTRA', | |
37 | 'description': 'RADIJSKA EMISIJA ZRAKOPLOVNE TEHNI?KE ?KOLE P', | |
38 | }, | |
39 | }, { | |
40 | # unavailable video | |
41 | 'url': 'http://www.teachertube.com/video/intro-video-schleicher-297790', | |
42 | 'only_matching': True, | |
43 | }] | |
44 | ||
45 | def _real_extract(self, url): | |
46 | video_id = self._match_id(url) | |
47 | webpage = self._download_webpage(url, video_id) | |
48 | ||
49 | error = self._search_regex( | |
50 | r'<div\b[^>]+\bclass=["\']msgBox error[^>]+>([^<]+)', webpage, | |
51 | 'error', default=None) | |
52 | if error: | |
53 | raise ExtractorError('%s said: %s' % (self.IE_NAME, error), expected=True) | |
54 | ||
55 | title = self._html_search_meta('title', webpage, 'title', fatal=True) | |
56 | TITLE_SUFFIX = ' - TeacherTube' | |
57 | if title.endswith(TITLE_SUFFIX): | |
58 | title = title[:-len(TITLE_SUFFIX)].strip() | |
59 | ||
60 | description = self._html_search_meta('description', webpage, 'description') | |
61 | if description: | |
62 | description = description.strip() | |
63 | ||
64 | quality = qualities(['mp3', 'flv', 'mp4']) | |
65 | ||
66 | media_urls = re.findall(r'data-contenturl="([^"]+)"', webpage) | |
67 | media_urls.extend(re.findall(r'var\s+filePath\s*=\s*"([^"]+)"', webpage)) | |
68 | media_urls.extend(re.findall(r'\'file\'\s*:\s*["\']([^"\']+)["\'],', webpage)) | |
69 | ||
70 | formats = [ | |
71 | { | |
72 | 'url': media_url, | |
73 | 'quality': quality(determine_ext(media_url)) | |
74 | } for media_url in set(media_urls) | |
75 | ] | |
76 | ||
77 | thumbnail = self._og_search_thumbnail( | |
78 | webpage, default=None) or self._html_search_meta( | |
79 | 'thumbnail', webpage) | |
80 | ||
81 | return { | |
82 | 'id': video_id, | |
83 | 'title': title, | |
84 | 'description': description, | |
85 | 'thumbnail': thumbnail, | |
86 | 'formats': formats, | |
87 | } | |
88 | ||
89 | ||
90 | class TeacherTubeUserIE(InfoExtractor): | |
91 | _WORKING = False | |
92 | IE_NAME = 'teachertube:user:collection' | |
93 | IE_DESC = 'teachertube.com user and collection videos' | |
94 | ||
95 | _VALID_URL = r'https?://(?:www\.)?teachertube\.com/(user/profile|collection)/(?P<user>[0-9a-zA-Z]+)/?' | |
96 | ||
97 | _MEDIA_RE = r'''(?sx) | |
98 | class="?sidebar_thumb_time"?>[0-9:]+</div> | |
99 | \s* | |
100 | <a\s+href="(https?://(?:www\.)?teachertube\.com/(?:video|audio)/[^"]+)" | |
101 | ''' | |
102 | _TEST = { | |
103 | 'url': 'http://www.teachertube.com/user/profile/rbhagwati2', | |
104 | 'info_dict': { | |
105 | 'id': 'rbhagwati2' | |
106 | }, | |
107 | 'playlist_mincount': 179, | |
108 | } | |
109 | ||
110 | def _real_extract(self, url): | |
111 | mobj = self._match_valid_url(url) | |
112 | user_id = mobj.group('user') | |
113 | ||
114 | urls = [] | |
115 | webpage = self._download_webpage(url, user_id) | |
116 | urls.extend(re.findall(self._MEDIA_RE, webpage)) | |
117 | ||
118 | pages = re.findall(r'/ajax-user/user-videos/%s\?page=([0-9]+)' % user_id, webpage)[:-1] | |
119 | for p in pages: | |
120 | more = 'http://www.teachertube.com/ajax-user/user-videos/%s?page=%s' % (user_id, p) | |
121 | webpage = self._download_webpage(more, user_id, 'Downloading page %s/%s' % (p, len(pages))) | |
122 | video_urls = re.findall(self._MEDIA_RE, webpage) | |
123 | urls.extend(video_urls) | |
124 | ||
125 | entries = [self.url_result(vurl, 'TeacherTube') for vurl in urls] | |
126 | return self.playlist_result(entries, user_id) |