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.

131 lines
4.5 KiB

10 years ago
  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=|video/(?:[\da-z-]+-)?|audio/)(?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',
  20. 'description': 'Measures of dispersion from a frequency table',
  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': 'Learn how to make paper dolls in this simple',
  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 P',
  41. },
  42. }, {
  43. 'url': 'http://www.teachertube.com/video/intro-video-schleicher-297790',
  44. 'md5': '9c79fbb2dd7154823996fc28d4a26998',
  45. 'info_dict': {
  46. 'id': '297790',
  47. 'ext': 'mp4',
  48. 'title': 'Intro Video - Schleicher',
  49. 'description': 'Intro Video - Why to flip, how flipping will',
  50. },
  51. }]
  52. def _real_extract(self, url):
  53. video_id = self._match_id(url)
  54. webpage = self._download_webpage(url, video_id)
  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. description = self._html_search_meta('description', webpage, 'description')
  60. if description:
  61. description = description.strip()
  62. quality = qualities(['mp3', 'flv', 'mp4'])
  63. media_urls = re.findall(r'data-contenturl="([^"]+)"', webpage)
  64. media_urls.extend(re.findall(r'var\s+filePath\s*=\s*"([^"]+)"', webpage))
  65. media_urls.extend(re.findall(r'\'file\'\s*:\s*["\']([^"\']+)["\'],', webpage))
  66. formats = [
  67. {
  68. 'url': media_url,
  69. 'quality': quality(determine_ext(media_url))
  70. } for media_url in set(media_urls)
  71. ]
  72. self._sort_formats(formats)
  73. return {
  74. 'id': video_id,
  75. 'title': title,
  76. 'thumbnail': self._html_search_regex(r'\'image\'\s*:\s*["\']([^"\']+)["\']', webpage, 'thumbnail'),
  77. 'formats': formats,
  78. 'description': description,
  79. }
  80. class TeacherTubeUserIE(InfoExtractor):
  81. IE_NAME = 'teachertube:user:collection'
  82. IE_DESC = 'teachertube.com user and collection videos'
  83. _VALID_URL = r'https?://(?:www\.)?teachertube\.com/(user/profile|collection)/(?P<user>[0-9a-zA-Z]+)/?'
  84. _MEDIA_RE = r'''(?sx)
  85. class="?sidebar_thumb_time"?>[0-9:]+</div>
  86. \s*
  87. <a\s+href="(https?://(?:www\.)?teachertube\.com/(?:video|audio)/[^"]+)"
  88. '''
  89. _TEST = {
  90. 'url': 'http://www.teachertube.com/user/profile/rbhagwati2',
  91. 'info_dict': {
  92. 'id': 'rbhagwati2'
  93. },
  94. 'playlist_mincount': 179,
  95. }
  96. def _real_extract(self, url):
  97. mobj = re.match(self._VALID_URL, url)
  98. user_id = mobj.group('user')
  99. urls = []
  100. webpage = self._download_webpage(url, user_id)
  101. urls.extend(re.findall(self._MEDIA_RE, webpage))
  102. pages = re.findall(r'/ajax-user/user-videos/%s\?page=([0-9]+)' % user_id, webpage)[:-1]
  103. for p in pages:
  104. more = 'http://www.teachertube.com/ajax-user/user-videos/%s?page=%s' % (user_id, p)
  105. webpage = self._download_webpage(more, user_id, 'Downloading page %s/%s' % (p, len(pages)))
  106. video_urls = re.findall(self._MEDIA_RE, webpage)
  107. urls.extend(video_urls)
  108. entries = [self.url_result(vurl, 'TeacherTube') for vurl in urls]
  109. return self.playlist_result(entries, user_id)