rbgtum.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. import re
  2. from .common import InfoExtractor
  3. from ..utils import ExtractorError, parse_qs, remove_start, traverse_obj
  4. class RbgTumIE(InfoExtractor):
  5. _VALID_URL = r'https?://(?:live\.rbg\.tum\.de|tum\.live)/w/(?P<id>[^?#]+)'
  6. _TESTS = [{
  7. # Combined view
  8. 'url': 'https://live.rbg.tum.de/w/cpp/22128',
  9. 'md5': '53a5e7b3e07128e33bbf36687fe1c08f',
  10. 'info_dict': {
  11. 'id': 'cpp/22128',
  12. 'ext': 'mp4',
  13. 'title': 'Lecture: October 18. 2022',
  14. 'series': 'Concepts of C++ programming (IN2377)',
  15. },
  16. }, {
  17. # Presentation only
  18. 'url': 'https://live.rbg.tum.de/w/I2DL/12349/PRES',
  19. 'md5': '36c584272179f3e56b0db5d880639cba',
  20. 'info_dict': {
  21. 'id': 'I2DL/12349/PRES',
  22. 'ext': 'mp4',
  23. 'title': 'Lecture 3: Introduction to Neural Networks',
  24. 'series': 'Introduction to Deep Learning (IN2346)',
  25. },
  26. }, {
  27. # Camera only
  28. 'url': 'https://live.rbg.tum.de/w/fvv-info/16130/CAM',
  29. 'md5': 'e04189d92ff2f56aedf5cede65d37aad',
  30. 'info_dict': {
  31. 'id': 'fvv-info/16130/CAM',
  32. 'ext': 'mp4',
  33. 'title': 'Fachschaftsvollversammlung',
  34. 'series': 'Fachschaftsvollversammlung Informatik',
  35. },
  36. }, {
  37. 'url': 'https://tum.live/w/linalginfo/27102',
  38. 'only_matching': True,
  39. }]
  40. def _real_extract(self, url):
  41. video_id = self._match_id(url)
  42. webpage = self._download_webpage(url, video_id)
  43. m3u8 = self._html_search_regex(r'"(https://[^"]+\.m3u8[^"]*)', webpage, 'm3u8')
  44. lecture_title = self._html_search_regex(r'<h1[^>]*>([^<]+)</h1>', webpage, 'title', fatal=False)
  45. lecture_series_title = remove_start(self._html_extract_title(webpage), 'TUM-Live | ')
  46. formats = self._extract_m3u8_formats(m3u8, video_id, 'mp4', entry_protocol='m3u8_native', m3u8_id='hls')
  47. return {
  48. 'id': video_id,
  49. 'title': lecture_title,
  50. 'series': lecture_series_title,
  51. 'formats': formats,
  52. }
  53. class RbgTumCourseIE(InfoExtractor):
  54. _VALID_URL = r'https?://(?P<hostname>(?:live\.rbg\.tum\.de|tum\.live))/old/course/(?P<id>(?P<year>\d+)/(?P<term>\w+)/(?P<slug>[^/?#]+))'
  55. _TESTS = [{
  56. 'url': 'https://live.rbg.tum.de/old/course/2022/S/fpv',
  57. 'info_dict': {
  58. 'title': 'Funktionale Programmierung und Verifikation (IN0003)',
  59. 'id': '2022/S/fpv',
  60. },
  61. 'params': {
  62. 'noplaylist': False,
  63. },
  64. 'playlist_count': 13,
  65. }, {
  66. 'url': 'https://live.rbg.tum.de/old/course/2022/W/set',
  67. 'info_dict': {
  68. 'title': 'SET FSMPIC',
  69. 'id': '2022/W/set',
  70. },
  71. 'params': {
  72. 'noplaylist': False,
  73. },
  74. 'playlist_count': 6,
  75. }, {
  76. 'url': 'https://tum.live/old/course/2023/S/linalginfo',
  77. 'only_matching': True,
  78. }]
  79. def _real_extract(self, url):
  80. course_id, hostname, year, term, slug = self._match_valid_url(url).group('id', 'hostname', 'year', 'term', 'slug')
  81. meta = self._download_json(
  82. f'https://{hostname}/api/courses/{slug}/', course_id, fatal=False,
  83. query={'year': year, 'term': term}) or {}
  84. lecture_series_title = meta.get('Name')
  85. lectures = [self.url_result(f'https://{hostname}/w/{slug}/{stream_id}', RbgTumIE)
  86. for stream_id in traverse_obj(meta, ('Streams', ..., 'ID'))]
  87. if not lectures:
  88. webpage = self._download_webpage(url, course_id)
  89. lecture_series_title = remove_start(self._html_extract_title(webpage), 'TUM-Live | ')
  90. lectures = [self.url_result(f'https://{hostname}{lecture_path}', RbgTumIE)
  91. for lecture_path in re.findall(r'href="(/w/[^/"]+/[^/"]+)"', webpage)]
  92. return self.playlist_result(lectures, course_id, lecture_series_title)
  93. class RbgTumNewCourseIE(InfoExtractor):
  94. _VALID_URL = r'https?://(?P<hostname>(?:live\.rbg\.tum\.de|tum\.live))/\?'
  95. _TESTS = [{
  96. 'url': 'https://live.rbg.tum.de/?year=2022&term=S&slug=fpv&view=3',
  97. 'info_dict': {
  98. 'title': 'Funktionale Programmierung und Verifikation (IN0003)',
  99. 'id': '2022/S/fpv',
  100. },
  101. 'params': {
  102. 'noplaylist': False,
  103. },
  104. 'playlist_count': 13,
  105. }, {
  106. 'url': 'https://live.rbg.tum.de/?year=2022&term=W&slug=set&view=3',
  107. 'info_dict': {
  108. 'title': 'SET FSMPIC',
  109. 'id': '2022/W/set',
  110. },
  111. 'params': {
  112. 'noplaylist': False,
  113. },
  114. 'playlist_count': 6,
  115. }, {
  116. 'url': 'https://tum.live/?year=2023&term=S&slug=linalginfo&view=3',
  117. 'only_matching': True,
  118. }]
  119. def _real_extract(self, url):
  120. query = parse_qs(url)
  121. errors = [key for key in ('year', 'term', 'slug') if not query.get(key)]
  122. if errors:
  123. raise ExtractorError(f'Input URL is missing query parameters: {", ".join(errors)}')
  124. year, term, slug = query['year'][0], query['term'][0], query['slug'][0]
  125. hostname = self._match_valid_url(url).group('hostname')
  126. return self.url_result(f'https://{hostname}/old/course/{year}/{term}/{slug}', RbgTumCourseIE)