You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
3.1 KiB

  1. # -*- coding: utf-8 -*-
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. qualities,
  7. determine_ext,
  8. )
  9. class TeacherTubeIE(InfoExtractor):
  10. IE_NAME = 'teachertube'
  11. IE_DESC = 'teachertube.com videos'
  12. _VALID_URL = r'https?://(?:www\.)?teachertube\.com/(viewVideo\.php\?video_id=|music\.php\?music_id=)(?P<id>\d+)'
  13. _TESTS = [{
  14. 'url': 'http://www.teachertube.com/viewVideo.php?video_id=339997',
  15. 'md5': 'f9434ef992fd65936d72999951ee254c',
  16. 'info_dict': {
  17. 'id': '339997',
  18. 'ext': 'mp4',
  19. 'title': 'Measures of dispersion from a frequency table_x264',
  20. 'description': 'md5:a3e9853487185e9fcd7181a07164650b',
  21. 'thumbnail': 're:http://.*\.jpg',
  22. },
  23. }, {
  24. 'url': 'http://www.teachertube.com/viewVideo.php?video_id=340064',
  25. 'md5': '0d625ec6bc9bf50f70170942ad580676',
  26. 'info_dict': {
  27. 'id': '340064',
  28. 'ext': 'mp4',
  29. 'title': 'How to Make Paper Dolls _ Paper Art Projects',
  30. 'description': 'md5:2ca52b20cd727773d1dc418b3d6bd07b',
  31. 'thumbnail': 're:http://.*\.jpg',
  32. },
  33. }, {
  34. 'url': 'http://www.teachertube.com/music.php?music_id=8805',
  35. 'md5': '01e8352006c65757caf7b961f6050e21',
  36. 'info_dict': {
  37. 'id': '8805',
  38. 'ext': 'mp3',
  39. 'title': 'PER ASPERA AD ASTRA',
  40. 'description': 'RADIJSKA EMISIJA ZRAKOPLOVNE TEHNIČKE ŠKOLE PER ASPERA AD ASTRA',
  41. },
  42. }]
  43. def _real_extract(self, url):
  44. mobj = re.match(self._VALID_URL, url)
  45. video_id = mobj.group('id')
  46. webpage = self._download_webpage(url, video_id)
  47. quality = qualities(['mp3', 'flv', 'mp4'])
  48. formats = [
  49. {
  50. 'url': media_url,
  51. 'quality': quality(determine_ext(media_url))
  52. } for media_url in set(zip(*re.findall(r'([\'"])file\1\s*:\s*"([^"]+)"', webpage))[1])
  53. ]
  54. self._sort_formats(formats)
  55. return {
  56. 'id': video_id,
  57. 'title': self._og_search_title(webpage),
  58. 'thumbnail': self._og_search_thumbnail(webpage),
  59. 'formats': formats,
  60. 'description': self._og_search_description(webpage),
  61. }
  62. class TeacherTubeClassroomIE(InfoExtractor):
  63. IE_NAME = 'teachertube:classroom'
  64. IE_DESC = 'teachertube.com online classrooms'
  65. _VALID_URL = r'https?://(?:www\.)?teachertube\.com/view_classroom\.php\?user=(?P<user>[0-9a-zA-Z]+)'
  66. def _real_extract(self, url):
  67. mobj = re.match(self._VALID_URL, url)
  68. user_id = mobj.group('user')
  69. rss = self._download_xml('http://www.teachertube.com/rssclassroom.php?mode=user&username=%s' % user_id,
  70. user_id, 'Downloading classroom RSS')
  71. entries = []
  72. for url in rss.findall('.//{http://search.yahoo.com/mrss/}player'):
  73. entries.append(self.url_result(url.attrib['url'], 'TeacherTube'))
  74. return self.playlist_result(entries, user_id)