academicearth.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import re
  2. from .common import InfoExtractor
  3. class AcademicEarthCourseIE(InfoExtractor):
  4. _VALID_URL = r'^https?://(?:www\.)?academicearth\.org/playlists/(?P<id>[^?#/]+)'
  5. IE_NAME = 'AcademicEarth:Course'
  6. _TEST = {
  7. 'url': 'http://academicearth.org/playlists/laws-of-nature/',
  8. 'info_dict': {
  9. 'id': 'laws-of-nature',
  10. 'title': 'Laws of Nature',
  11. 'description': 'Introduce yourself to the laws of nature with these free online college lectures from Yale, Harvard, and MIT.',
  12. },
  13. 'playlist_count': 3,
  14. }
  15. def _real_extract(self, url):
  16. playlist_id = self._match_id(url)
  17. webpage = self._download_webpage(url, playlist_id)
  18. title = self._html_search_regex(
  19. r'<h1 class="playlist-name"[^>]*?>(.*?)</h1>', webpage, 'title')
  20. description = self._html_search_regex(
  21. r'<p class="excerpt"[^>]*?>(.*?)</p>',
  22. webpage, 'description', fatal=False)
  23. urls = re.findall(
  24. r'<li class="lecture-preview">\s*?<a target="_blank" href="([^"]+)">',
  25. webpage)
  26. entries = [self.url_result(u) for u in urls]
  27. return {
  28. '_type': 'playlist',
  29. 'id': playlist_id,
  30. 'title': title,
  31. 'description': description,
  32. 'entries': entries,
  33. }