lecture2go.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import re
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. determine_ext,
  5. determine_protocol,
  6. parse_duration,
  7. int_or_none,
  8. )
  9. class Lecture2GoIE(InfoExtractor):
  10. _VALID_URL = r'https?://lecture2go\.uni-hamburg\.de/veranstaltungen/-/v/(?P<id>\d+)'
  11. _TEST = {
  12. 'url': 'https://lecture2go.uni-hamburg.de/veranstaltungen/-/v/17473',
  13. 'md5': 'ac02b570883020d208d405d5a3fd2f7f',
  14. 'info_dict': {
  15. 'id': '17473',
  16. 'ext': 'mp4',
  17. 'title': '2 - Endliche Automaten und reguläre Sprachen',
  18. 'creator': 'Frank Heitmann',
  19. 'duration': 5220,
  20. },
  21. 'params': {
  22. # m3u8 download
  23. 'skip_download': True,
  24. }
  25. }
  26. def _real_extract(self, url):
  27. video_id = self._match_id(url)
  28. webpage = self._download_webpage(url, video_id)
  29. title = self._html_search_regex(r'<em[^>]+class="title">(.+)</em>', webpage, 'title')
  30. formats = []
  31. for url in set(re.findall(r'var\s+playerUri\d+\s*=\s*"([^"]+)"', webpage)):
  32. ext = determine_ext(url)
  33. protocol = determine_protocol({'url': url})
  34. if ext == 'f4m':
  35. formats.extend(self._extract_f4m_formats(url, video_id, f4m_id='hds'))
  36. elif ext == 'm3u8':
  37. formats.extend(self._extract_m3u8_formats(url, video_id, ext='mp4', m3u8_id='hls'))
  38. else:
  39. if protocol == 'rtmp':
  40. continue # XXX: currently broken
  41. formats.append({
  42. 'format_id': protocol,
  43. 'url': url,
  44. })
  45. creator = self._html_search_regex(
  46. r'<div[^>]+id="description">([^<]+)</div>', webpage, 'creator', fatal=False)
  47. duration = parse_duration(self._html_search_regex(
  48. r'Duration:\s*</em>\s*<em[^>]*>([^<]+)</em>', webpage, 'duration', fatal=False))
  49. view_count = int_or_none(self._html_search_regex(
  50. r'Views:\s*</em>\s*<em[^>]+>(\d+)</em>', webpage, 'view count', fatal=False))
  51. return {
  52. 'id': video_id,
  53. 'title': title,
  54. 'formats': formats,
  55. 'creator': creator,
  56. 'duration': duration,
  57. 'view_count': view_count,
  58. }