]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/teachertube.py
4d9666c6b14980d6b04ebe1bd07cc3e79a9dd2bd
[youtubedl] / youtube_dl / extractor / teachertube.py
1 # -*- coding: utf-8 -*-
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import (
8 qualities,
9 determine_ext,
10 )
11
12
13 class TeacherTubeIE(InfoExtractor):
14 IE_NAME = 'teachertube'
15 IE_DESC = 'teachertube.com videos'
16
17 _VALID_URL = r'https?://(?:www\.)?teachertube\.com/(viewVideo\.php\?video_id=|music\.php\?music_id=)(?P<id>\d+)'
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',
25 'title': 'Measures of dispersion from a frequency table_x264',
26 'description': 'md5:a3e9853487185e9fcd7181a07164650b',
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',
36 'description': 'md5:2ca52b20cd727773d1dc418b3d6bd07b',
37 'thumbnail': 're:http://.*\.jpg',
38 },
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',
46 'description': 'RADIJSKA EMISIJA ZRAKOPLOVNE TEHNIČKE ŠKOLE PER ASPERA AD ASTRA',
47 },
48 }]
49
50 def _real_extract(self, url):
51 mobj = re.match(self._VALID_URL, url)
52 video_id = mobj.group('id')
53
54 webpage = self._download_webpage(url, video_id)
55
56 quality = qualities(['mp3', 'flv', 'mp4'])
57
58 _, media_urls = zip(*re.findall(r'([\'"])file\1\s*:\s*"([^"]+)"', webpage))
59
60 formats = [
61 {
62 'url': media_url,
63 'quality': quality(determine_ext(media_url))
64 } for media_url in set(media_urls)
65 ]
66
67 self._sort_formats(formats)
68
69 return {
70 'id': video_id,
71 'title': self._og_search_title(webpage),
72 'thumbnail': self._og_search_thumbnail(webpage),
73 'formats': formats,
74 'description': self._og_search_description(webpage),
75 }
76
77
78 class TeacherTubeClassroomIE(InfoExtractor):
79 IE_NAME = 'teachertube:classroom'
80 IE_DESC = 'teachertube.com online classrooms'
81
82 _VALID_URL = r'https?://(?:www\.)?teachertube\.com/view_classroom\.php\?user=(?P<user>[0-9a-zA-Z]+)'
83
84 def _real_extract(self, url):
85 mobj = re.match(self._VALID_URL, url)
86 user_id = mobj.group('user')
87
88 rss = self._download_xml('http://www.teachertube.com/rssclassroom.php?mode=user&username=%s' % user_id,
89 user_id, 'Downloading classroom RSS')
90
91 entries = []
92 for url in rss.findall('.//{http://search.yahoo.com/mrss/}player'):
93 entries.append(self.url_result(url.attrib['url'], 'TeacherTube'))
94
95 return self.playlist_result(entries, user_id)