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,
|
GabTVIE,
|
||||||
)
|
)
|
||||||
from .gaia import GaiaIE
|
from .gaia import GaiaIE
|
||||||
from .gamedevtv import GameDevTVIE
|
from .gamedevtv import GameDevTVDashboardIE
|
||||||
from .gamejolt import (
|
from .gamejolt import (
|
||||||
GameJoltCommunityIE,
|
GameJoltCommunityIE,
|
||||||
GameJoltGameIE,
|
GameJoltGameIE,
|
||||||
|
|
|
@ -1,123 +1,108 @@
|
||||||
import json
|
import json
|
||||||
from collections.abc import Generator, Iterable
|
|
||||||
|
|
||||||
from .common import InfoExtractor
|
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+)'
|
_VALID_URL = r'https?://(?:www\.)?gamedev\.tv/dashboard/courses/(?P<id>\d+)'
|
||||||
_NETRC_MACHINE = 'gamedevtv'
|
_NETRC_MACHINE = 'gamedevtv'
|
||||||
_API_HEADERS = {}
|
_TESTS = [{
|
||||||
_TEST = {
|
|
||||||
'url': 'https://www.gamedev.tv/dashboard/courses/25',
|
'url': 'https://www.gamedev.tv/dashboard/courses/25',
|
||||||
'md5': 'ece542a1071018d5a09e0dc91a843763',
|
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'playlist': 'Complete Blender Creator 3: Learn 3D Modelling for Beginners',
|
'id': '25',
|
||||||
'playlist_id': 25,
|
'title': 'Complete Blender Creator 3: Learn 3D Modelling for Beginners',
|
||||||
'chapter_id': '01',
|
'tags': ['blender', 'course', 'all', 'box modelling', 'sculpting'],
|
||||||
'chapter': 'Introduction & Setup',
|
'categories': ['Blender', '3D Art'],
|
||||||
'id': '01',
|
'thumbnail': 'https://gamedev-files.b-cdn.net/courses/qisc9pmu1jdc.jpg',
|
||||||
'ext': 'mp4',
|
'upload_date': '20220516',
|
||||||
'title': 'Section Intro - Introduction To Blender',
|
'timestamp': 1652694420,
|
||||||
|
'modified_date': '20241027',
|
||||||
|
'modified_timestamp': 1730049658,
|
||||||
},
|
},
|
||||||
}
|
'playlist_count': 100,
|
||||||
|
}]
|
||||||
|
_API_HEADERS = {}
|
||||||
|
|
||||||
def _perform_login(self, username: str, password: str) -> None:
|
def _perform_login(self, username, password):
|
||||||
"""
|
try:
|
||||||
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(
|
response = self._download_json(
|
||||||
'https://api.gamedev.tv/api/students/login',
|
'https://api.gamedev.tv/api/students/login', None, 'Logging in',
|
||||||
None,
|
|
||||||
'Logging in',
|
|
||||||
headers={'Content-Type': 'application/json'},
|
headers={'Content-Type': 'application/json'},
|
||||||
data=json.dumps(
|
data=json.dumps({
|
||||||
{
|
|
||||||
'email': username,
|
'email': username,
|
||||||
'password': password,
|
'password': password,
|
||||||
'cart_items': [],
|
'cart_items': [],
|
||||||
},
|
}).encode())
|
||||||
).encode(),
|
except ExtractorError as e:
|
||||||
)
|
if isinstance(e.cause, HTTPError) and e.cause.status == 401:
|
||||||
self._API_HEADERS['Authorization'] = (
|
raise ExtractorError('Invalid username/password', expected=True)
|
||||||
f"{response['token_type']} {response['access_token']}"
|
raise
|
||||||
)
|
|
||||||
|
|
||||||
def _get_lecture_info(self, data: dict, course_id: str) -> Generator:
|
self._API_HEADERS['Authorization'] = f'{response["token_type"]} {response["access_token"]}'
|
||||||
"""
|
|
||||||
Extracts lecture information from the provided course data.
|
|
||||||
This function yields structured information about each lecture, including its title, formats, and subtitles.
|
|
||||||
|
|
||||||
Args:
|
def _real_initialize(self):
|
||||||
data (dict): The course data containing sections and lectures.
|
if not self._API_HEADERS.get('Authorization'):
|
||||||
course_id (str): The unique identifier for the course.
|
self.raise_login_required(
|
||||||
|
'This content is only available with purchase', method='password')
|
||||||
|
|
||||||
Returns:
|
def _entries(self, data, course_id, course_info):
|
||||||
Generator: A generator that yields dictionaries containing lecture information.
|
for section in traverse_obj(data, ('sections', ..., {dict})):
|
||||||
"""
|
section_info = traverse_obj(section, {
|
||||||
course_list = []
|
'season_id': ('id', {str_or_none}),
|
||||||
for section in data['data']['sections']:
|
'season': ('title', {str}),
|
||||||
for lecture in section['lectures']:
|
'season_number': ('order', {int_or_none}),
|
||||||
video_id = str(lecture['order']).zfill(2)
|
})
|
||||||
title = lecture['title']
|
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(
|
formats, subtitles = self._extract_m3u8_formats_and_subtitles(
|
||||||
lecture['video']['playListUrl'], course_id, 'mp4', m3u8_id='hls',
|
lecture['video']['playListUrl'], display_id, 'mp4', m3u8_id='hls')
|
||||||
)
|
yield {
|
||||||
playlist_title = data['data']['title']
|
**course_info,
|
||||||
playlist_id = data['data']['id']
|
**section_info,
|
||||||
chapter_id = str(section['order']).zfill(2)
|
'id': display_id, # fallback
|
||||||
chapter = section['title']
|
'display_id': display_id,
|
||||||
course_list.append(
|
|
||||||
{
|
|
||||||
'id': video_id,
|
|
||||||
'title': title,
|
|
||||||
'formats': formats,
|
'formats': formats,
|
||||||
'subtitles': subtitles,
|
'subtitles': subtitles,
|
||||||
'playlist': playlist_title,
|
'series': course_info.get('title'),
|
||||||
'playlist_id': playlist_id,
|
'series_id': course_id,
|
||||||
'chapter_id': chapter_id,
|
**traverse_obj(lecture, {
|
||||||
'chapter': chapter,
|
'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}),
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
|
||||||
},
|
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)
|
course_id = self._match_id(url)
|
||||||
|
|
||||||
data = self._download_json(
|
data = self._download_json(
|
||||||
f'https://api.gamedev.tv/api/courses/my/{course_id}',
|
f'https://api.gamedev.tv/api/courses/my/{course_id}', course_id,
|
||||||
course_id,
|
headers=self._API_HEADERS)['data']
|
||||||
headers=self._API_HEADERS,
|
|
||||||
)
|
|
||||||
|
|
||||||
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