mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-29 18:51:24 +01:00
Compare commits
5 Commits
b6cc14c771
...
4918dfd46b
Author | SHA1 | Date | |
---|---|---|---|
|
4918dfd46b | ||
|
61007bb684 | ||
|
5aa715915b | ||
|
bf0cf9995d | ||
|
2309b88c1a |
|
@ -707,7 +707,7 @@ from .gab import (
|
|||
GabTVIE,
|
||||
)
|
||||
from .gaia import GaiaIE
|
||||
from .gamedevtv import GameDevTVIE
|
||||
from .gamedevtv import GameDevTVDashboardIE
|
||||
from .gamejolt import (
|
||||
GameJoltCommunityIE,
|
||||
GameJoltGameIE,
|
||||
|
|
|
@ -1,123 +1,108 @@
|
|||
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 GameDevTVIE(InfoExtractor):
|
||||
class GameDevTVDashboardIE(InfoExtractor):
|
||||
_VALID_URL = r'https?://(?:www\.)?gamedev\.tv/dashboard/courses/(?P<id>\d+)'
|
||||
_NETRC_MACHINE = 'gamedevtv'
|
||||
_API_HEADERS = {}
|
||||
_TEST = {
|
||||
_TESTS = [{
|
||||
'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',
|
||||
'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 = {}
|
||||
|
||||
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")
|
||||
"""
|
||||
def _perform_login(self, username, password):
|
||||
try:
|
||||
response = self._download_json(
|
||||
'https://api.gamedev.tv/api/students/login',
|
||||
None,
|
||||
'Logging in',
|
||||
'https://api.gamedev.tv/api/students/login', None, 'Logging in',
|
||||
headers={'Content-Type': 'application/json'},
|
||||
data=json.dumps(
|
||||
{
|
||||
data=json.dumps({
|
||||
'email': username,
|
||||
'password': password,
|
||||
'cart_items': [],
|
||||
},
|
||||
).encode(),
|
||||
)
|
||||
self._API_HEADERS['Authorization'] = (
|
||||
f"{response['token_type']} {response['access_token']}"
|
||||
)
|
||||
}).encode())
|
||||
except ExtractorError as e:
|
||||
if isinstance(e.cause, HTTPError) and e.cause.status == 401:
|
||||
raise ExtractorError('Invalid username/password', expected=True)
|
||||
raise
|
||||
|
||||
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.
|
||||
self._API_HEADERS['Authorization'] = f'{response["token_type"]} {response["access_token"]}'
|
||||
|
||||
Args:
|
||||
data (dict): The course data containing sections and lectures.
|
||||
course_id (str): The unique identifier for the course.
|
||||
def _real_initialize(self):
|
||||
if not self._API_HEADERS.get('Authorization'):
|
||||
self.raise_login_required(
|
||||
'This content is only available with purchase', method='password')
|
||||
|
||||
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']
|
||||
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'))
|
||||
formats, subtitles = self._extract_m3u8_formats_and_subtitles(
|
||||
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,
|
||||
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,
|
||||
'playlist': playlist_title,
|
||||
'playlist_id': playlist_id,
|
||||
'chapter_id': chapter_id,
|
||||
'chapter': chapter,
|
||||
'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}),
|
||||
}),
|
||||
}
|
||||
|
||||
},
|
||||
)
|
||||
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.
|
||||
"""
|
||||
def _real_extract(self, url):
|
||||
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,
|
||||
)
|
||||
f'https://api.gamedev.tv/api/courses/my/{course_id}', course_id,
|
||||
headers=self._API_HEADERS)['data']
|
||||
|
||||
course_list = self._get_lecture_info(data, course_id)
|
||||
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}),
|
||||
})
|
||||
|
||||
return self.playlist_result(course_list)
|
||||
return self.playlist_result(self._entries(data, course_id, course_info), course_id, **course_info)
|
||||
|
|
Loading…
Reference in New Issue
Block a user