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.

85 lines
2.7 KiB

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