logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

gamedevtv.py (6266B)


  1. import json
  2. from .common import InfoExtractor
  3. from ..networking.exceptions import HTTPError
  4. from ..utils import (
  5. ExtractorError,
  6. clean_html,
  7. int_or_none,
  8. join_nonempty,
  9. parse_iso8601,
  10. str_or_none,
  11. url_or_none,
  12. )
  13. from ..utils.traversal import traverse_obj
  14. class GameDevTVDashboardIE(InfoExtractor):
  15. _VALID_URL = r'https?://(?:www\.)?gamedev\.tv/dashboard/courses/(?P<course_id>\d+)(?:/(?P<lecture_id>\d+))?'
  16. _NETRC_MACHINE = 'gamedevtv'
  17. _TESTS = [{
  18. 'url': 'https://www.gamedev.tv/dashboard/courses/25',
  19. 'info_dict': {
  20. 'id': '25',
  21. 'title': 'Complete Blender Creator 3: Learn 3D Modelling for Beginners',
  22. 'tags': ['blender', 'course', 'all', 'box modelling', 'sculpting'],
  23. 'categories': ['Blender', '3D Art'],
  24. 'thumbnail': 'https://gamedev-files.b-cdn.net/courses/qisc9pmu1jdc.jpg',
  25. 'upload_date': '20220516',
  26. 'timestamp': 1652694420,
  27. 'modified_date': '20241027',
  28. 'modified_timestamp': 1730049658,
  29. },
  30. 'playlist_count': 100,
  31. }, {
  32. 'url': 'https://www.gamedev.tv/dashboard/courses/63/2279',
  33. 'info_dict': {
  34. 'id': 'df04f4d8-68a4-4756-a71b-9ca9446c3a01',
  35. 'ext': 'mp4',
  36. 'modified_timestamp': 1701695752,
  37. 'upload_date': '20230504',
  38. 'episode': 'MagicaVoxel Community Course Introduction',
  39. 'series_id': '63',
  40. 'title': 'MagicaVoxel Community Course Introduction',
  41. 'timestamp': 1683195397,
  42. 'modified_date': '20231204',
  43. 'categories': ['3D Art', 'MagicaVoxel'],
  44. 'season': 'MagicaVoxel Community Course',
  45. 'tags': ['MagicaVoxel', 'all', 'course'],
  46. 'series': 'MagicaVoxel 3D Art Mini Course',
  47. 'duration': 1405,
  48. 'episode_number': 1,
  49. 'season_number': 1,
  50. 'season_id': '219',
  51. 'description': 'md5:a378738c5bbec1c785d76c067652d650',
  52. 'display_id': '63-219-2279',
  53. 'alt_title': '1_CC_MVX MagicaVoxel Community Course Introduction.mp4',
  54. 'thumbnail': 'https://vz-23691c65-6fa.b-cdn.net/df04f4d8-68a4-4756-a71b-9ca9446c3a01/thumbnail.jpg',
  55. },
  56. }]
  57. _API_HEADERS = {}
  58. def _perform_login(self, username, password):
  59. try:
  60. response = self._download_json(
  61. 'https://api.gamedev.tv/api/students/login', None, 'Logging in',
  62. headers={'Content-Type': 'application/json'},
  63. data=json.dumps({
  64. 'email': username,
  65. 'password': password,
  66. 'cart_items': [],
  67. }).encode())
  68. except ExtractorError as e:
  69. if isinstance(e.cause, HTTPError) and e.cause.status == 401:
  70. raise ExtractorError('Invalid username/password', expected=True)
  71. raise
  72. self._API_HEADERS['Authorization'] = f'{response["token_type"]} {response["access_token"]}'
  73. def _real_initialize(self):
  74. if not self._API_HEADERS.get('Authorization'):
  75. self.raise_login_required(
  76. 'This content is only available with purchase', method='password')
  77. def _entries(self, data, course_id, course_info, selected_lecture):
  78. for section in traverse_obj(data, ('sections', ..., {dict})):
  79. section_info = traverse_obj(section, {
  80. 'season_id': ('id', {str_or_none}),
  81. 'season': ('title', {str}),
  82. 'season_number': ('order', {int_or_none}),
  83. })
  84. for lecture in traverse_obj(section, ('lectures', lambda _, v: url_or_none(v['video']['playListUrl']))):
  85. if selected_lecture and str(lecture.get('id')) != selected_lecture:
  86. continue
  87. display_id = join_nonempty(course_id, section_info.get('season_id'), lecture.get('id'))
  88. formats, subtitles = self._extract_m3u8_formats_and_subtitles(
  89. lecture['video']['playListUrl'], display_id, 'mp4', m3u8_id='hls')
  90. yield {
  91. **course_info,
  92. **section_info,
  93. 'id': display_id, # fallback
  94. 'display_id': display_id,
  95. 'formats': formats,
  96. 'subtitles': subtitles,
  97. 'series': course_info.get('title'),
  98. 'series_id': course_id,
  99. **traverse_obj(lecture, {
  100. 'id': ('video', 'guid', {str}),
  101. 'title': ('title', {str}),
  102. 'alt_title': ('video', 'title', {str}),
  103. 'description': ('description', {clean_html}),
  104. 'episode': ('title', {str}),
  105. 'episode_number': ('order', {int_or_none}),
  106. 'duration': ('video', 'duration_in_sec', {int_or_none}),
  107. 'timestamp': ('video', 'created_at', {parse_iso8601}),
  108. 'modified_timestamp': ('video', 'updated_at', {parse_iso8601}),
  109. 'thumbnail': ('video', 'thumbnailUrl', {url_or_none}),
  110. }),
  111. }
  112. def _real_extract(self, url):
  113. course_id, lecture_id = self._match_valid_url(url).group('course_id', 'lecture_id')
  114. data = self._download_json(
  115. f'https://api.gamedev.tv/api/courses/my/{course_id}', course_id,
  116. headers=self._API_HEADERS)['data']
  117. course_info = traverse_obj(data, {
  118. 'title': ('title', {str}),
  119. 'tags': ('tags', ..., 'name', {str}),
  120. 'categories': ('categories', ..., 'title', {str}),
  121. 'timestamp': ('created_at', {parse_iso8601}),
  122. 'modified_timestamp': ('updated_at', {parse_iso8601}),
  123. 'thumbnail': ('image', {url_or_none}),
  124. })
  125. entries = self._entries(data, course_id, course_info, lecture_id)
  126. if lecture_id:
  127. lecture = next(entries, None)
  128. if not lecture:
  129. raise ExtractorError('Lecture not found')
  130. return lecture
  131. return self.playlist_result(entries, course_id, **course_info)