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