Compare commits

..

No commits in common. "4918dfd46b738b55b969e8b2b320900b4cd7b846" and "b6cc14c7711fec098c6e46b38a8f49c6fd1eeca2" have entirely different histories.

2 changed files with 103 additions and 88 deletions

View File

@ -707,7 +707,7 @@ from .gab import (
GabTVIE,
)
from .gaia import GaiaIE
from .gamedevtv import GameDevTVDashboardIE
from .gamedevtv import GameDevTVIE
from .gamejolt import (
GameJoltCommunityIE,
GameJoltGameIE,

View File

@ -1,108 +1,123 @@
import json
from collections.abc import Generator, Iterable
from .common import InfoExtractor
from ..networking.exceptions import HTTPError
from ..utils import (
ExtractorError,
clean_html,
int_or_none,
join_nonempty,
parse_iso8601,
str_or_none,
url_or_none,
)
from ..utils.traversal import traverse_obj
class GameDevTVDashboardIE(InfoExtractor):
class GameDevTVIE(InfoExtractor):
_VALID_URL = r'https?://(?:www\.)?gamedev\.tv/dashboard/courses/(?P<id>\d+)'
_NETRC_MACHINE = 'gamedevtv'
_TESTS = [{
'url': 'https://www.gamedev.tv/dashboard/courses/25',
'info_dict': {
'id': '25',
'title': 'Complete Blender Creator 3: Learn 3D Modelling for Beginners',
'tags': ['blender', 'course', 'all', 'box modelling', 'sculpting'],
'categories': ['Blender', '3D Art'],
'thumbnail': 'https://gamedev-files.b-cdn.net/courses/qisc9pmu1jdc.jpg',
'upload_date': '20220516',
'timestamp': 1652694420,
'modified_date': '20241027',
'modified_timestamp': 1730049658,
},
'playlist_count': 100,
}]
_API_HEADERS = {}
_TEST = {
'url': 'https://www.gamedev.tv/dashboard/courses/25',
'md5': 'ece542a1071018d5a09e0dc91a843763',
'info_dict': {
'playlist': 'Complete Blender Creator 3: Learn 3D Modelling for Beginners',
'playlist_id': 25,
'chapter_id': '01',
'chapter': 'Introduction & Setup',
'id': '01',
'ext': 'mp4',
'title': 'Section Intro - Introduction To Blender',
},
}
def _perform_login(self, username, password):
try:
response = self._download_json(
'https://api.gamedev.tv/api/students/login', None, 'Logging in',
headers={'Content-Type': 'application/json'},
data=json.dumps({
def _perform_login(self, username: str, password: str) -> None:
"""
Logs in a user to the GameDev.tv API using their credentials.
This function sends a login request and updates the API headers with the received authorization token.
Args:
username (str): The email address of the user.
password (str): The password of the user.
Returns:
None
Raises:
ValueError: If the login fails or the response does not contain the expected data.
Examples:
>>> _perform_login("user@example.com", "securepassword")
"""
response = self._download_json(
'https://api.gamedev.tv/api/students/login',
None,
'Logging in',
headers={'Content-Type': 'application/json'},
data=json.dumps(
{
'email': username,
'password': password,
'cart_items': [],
}).encode())
except ExtractorError as e:
if isinstance(e.cause, HTTPError) and e.cause.status == 401:
raise ExtractorError('Invalid username/password', expected=True)
raise
},
).encode(),
)
self._API_HEADERS['Authorization'] = (
f"{response['token_type']} {response['access_token']}"
)
self._API_HEADERS['Authorization'] = f'{response["token_type"]} {response["access_token"]}'
def _get_lecture_info(self, data: dict, course_id: str) -> Generator:
"""
Extracts lecture information from the provided course data.
This function yields structured information about each lecture, including its title, formats, and subtitles.
def _real_initialize(self):
if not self._API_HEADERS.get('Authorization'):
self.raise_login_required(
'This content is only available with purchase', method='password')
Args:
data (dict): The course data containing sections and lectures.
course_id (str): The unique identifier for the course.
def _entries(self, data, course_id, course_info):
for section in traverse_obj(data, ('sections', ..., {dict})):
section_info = traverse_obj(section, {
'season_id': ('id', {str_or_none}),
'season': ('title', {str}),
'season_number': ('order', {int_or_none}),
})
for lecture in traverse_obj(section, ('lectures', lambda _, v: url_or_none(v['video']['playListUrl']))):
display_id = join_nonempty(course_id, section_info.get('season_id'), lecture.get('id'))
Returns:
Generator: A generator that yields dictionaries containing lecture information.
"""
course_list = []
for section in data['data']['sections']:
for lecture in section['lectures']:
video_id = str(lecture['order']).zfill(2)
title = lecture['title']
formats, subtitles = self._extract_m3u8_formats_and_subtitles(
lecture['video']['playListUrl'], display_id, 'mp4', m3u8_id='hls')
yield {
**course_info,
**section_info,
'id': display_id, # fallback
'display_id': display_id,
'formats': formats,
'subtitles': subtitles,
'series': course_info.get('title'),
'series_id': course_id,
**traverse_obj(lecture, {
'id': ('video', 'guid', {str}),
'title': ('title', {str}),
'alt_title': ('video', 'title', {str}),
'description': ('description', {clean_html}),
'episode': ('title', {str}),
'episode_number': ('order', {int_or_none}),
'duration': ('video', 'duration_in_sec', {int_or_none}),
'timestamp': ('video', 'created_at', {parse_iso8601}),
'modified_timestamp': ('video', 'updated_at', {parse_iso8601}),
'thumbnail': ('video', 'thumbnailUrl', {url_or_none}),
}),
}
lecture['video']['playListUrl'], course_id, 'mp4', m3u8_id='hls',
)
playlist_title = data['data']['title']
playlist_id = data['data']['id']
chapter_id = str(section['order']).zfill(2)
chapter = section['title']
course_list.append(
{
'id': video_id,
'title': title,
'formats': formats,
'subtitles': subtitles,
'playlist': playlist_title,
'playlist_id': playlist_id,
'chapter_id': chapter_id,
'chapter': chapter,
def _real_extract(self, url):
},
)
yield from course_list
def _real_extract(self, url: str) -> Iterable:
"""
Extracts course information from the GameDev.tv API based on the provided URL.
This function retrieves the course data and yields a structured playlist of lectures.
Args:
url (str): The URL of the course to extract information from.
Returns:
Iterable: An iterable containing the structured playlist result of the course lectures.
Raises:
ValueError: If the course ID cannot be matched from the URL or if the data retrieval fails.
"""
course_id = self._match_id(url)
data = self._download_json(
f'https://api.gamedev.tv/api/courses/my/{course_id}', course_id,
headers=self._API_HEADERS)['data']
f'https://api.gamedev.tv/api/courses/my/{course_id}',
course_id,
headers=self._API_HEADERS,
)
course_info = traverse_obj(data, {
'title': ('title', {str}),
'tags': ('tags', ..., 'name', {str}),
'categories': ('categories', ..., 'title', {str}),
'timestamp': ('created_at', {parse_iso8601}),
'modified_timestamp': ('updated_at', {parse_iso8601}),
'thumbnail': ('image', {url_or_none}),
})
course_list = self._get_lecture_info(data, course_id)
return self.playlist_result(self._entries(data, course_id, course_info), course_id, **course_info)
return self.playlist_result(course_list)