mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-29 18:51:24 +01:00
Compare commits
No commits in common. "4918dfd46b738b55b969e8b2b320900b4cd7b846" and "b6cc14c7711fec098c6e46b38a8f49c6fd1eeca2" have entirely different histories.
4918dfd46b
...
b6cc14c771
|
@ -707,7 +707,7 @@ from .gab import (
|
||||||
GabTVIE,
|
GabTVIE,
|
||||||
)
|
)
|
||||||
from .gaia import GaiaIE
|
from .gaia import GaiaIE
|
||||||
from .gamedevtv import GameDevTVDashboardIE
|
from .gamedevtv import GameDevTVIE
|
||||||
from .gamejolt import (
|
from .gamejolt import (
|
||||||
GameJoltCommunityIE,
|
GameJoltCommunityIE,
|
||||||
GameJoltGameIE,
|
GameJoltGameIE,
|
||||||
|
|
|
@ -1,108 +1,123 @@
|
||||||
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 GameDevTVDashboardIE(InfoExtractor):
|
class GameDevTVIE(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'
|
||||||
_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 = {}
|
_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):
|
def _perform_login(self, username: str, password: str) -> None:
|
||||||
try:
|
"""
|
||||||
response = self._download_json(
|
Logs in a user to the GameDev.tv API using their credentials.
|
||||||
'https://api.gamedev.tv/api/students/login', None, 'Logging in',
|
This function sends a login request and updates the API headers with the received authorization token.
|
||||||
headers={'Content-Type': 'application/json'},
|
|
||||||
data=json.dumps({
|
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,
|
'email': username,
|
||||||
'password': password,
|
'password': password,
|
||||||
'cart_items': [],
|
'cart_items': [],
|
||||||
}).encode())
|
},
|
||||||
except ExtractorError as e:
|
).encode(),
|
||||||
if isinstance(e.cause, HTTPError) and e.cause.status == 401:
|
)
|
||||||
raise ExtractorError('Invalid username/password', expected=True)
|
self._API_HEADERS['Authorization'] = (
|
||||||
raise
|
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):
|
Args:
|
||||||
if not self._API_HEADERS.get('Authorization'):
|
data (dict): The course data containing sections and lectures.
|
||||||
self.raise_login_required(
|
course_id (str): The unique identifier for the course.
|
||||||
'This content is only available with purchase', method='password')
|
|
||||||
|
|
||||||
def _entries(self, data, course_id, course_info):
|
Returns:
|
||||||
for section in traverse_obj(data, ('sections', ..., {dict})):
|
Generator: A generator that yields dictionaries containing lecture information.
|
||||||
section_info = traverse_obj(section, {
|
"""
|
||||||
'season_id': ('id', {str_or_none}),
|
course_list = []
|
||||||
'season': ('title', {str}),
|
for section in data['data']['sections']:
|
||||||
'season_number': ('order', {int_or_none}),
|
for lecture in section['lectures']:
|
||||||
})
|
video_id = str(lecture['order']).zfill(2)
|
||||||
for lecture in traverse_obj(section, ('lectures', lambda _, v: url_or_none(v['video']['playListUrl']))):
|
title = lecture['title']
|
||||||
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'], display_id, 'mp4', m3u8_id='hls')
|
lecture['video']['playListUrl'], course_id, 'mp4', m3u8_id='hls',
|
||||||
yield {
|
)
|
||||||
**course_info,
|
playlist_title = data['data']['title']
|
||||||
**section_info,
|
playlist_id = data['data']['id']
|
||||||
'id': display_id, # fallback
|
chapter_id = str(section['order']).zfill(2)
|
||||||
'display_id': display_id,
|
chapter = section['title']
|
||||||
'formats': formats,
|
course_list.append(
|
||||||
'subtitles': subtitles,
|
{
|
||||||
'series': course_info.get('title'),
|
'id': video_id,
|
||||||
'series_id': course_id,
|
'title': title,
|
||||||
**traverse_obj(lecture, {
|
'formats': formats,
|
||||||
'id': ('video', 'guid', {str}),
|
'subtitles': subtitles,
|
||||||
'title': ('title', {str}),
|
'playlist': playlist_title,
|
||||||
'alt_title': ('video', 'title', {str}),
|
'playlist_id': playlist_id,
|
||||||
'description': ('description', {clean_html}),
|
'chapter_id': chapter_id,
|
||||||
'episode': ('title', {str}),
|
'chapter': chapter,
|
||||||
'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}', course_id,
|
f'https://api.gamedev.tv/api/courses/my/{course_id}',
|
||||||
headers=self._API_HEADERS)['data']
|
course_id,
|
||||||
|
headers=self._API_HEADERS,
|
||||||
|
)
|
||||||
|
|
||||||
course_info = traverse_obj(data, {
|
course_list = self._get_lecture_info(data, course_id)
|
||||||
'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(self._entries(data, course_id, course_info), course_id, **course_info)
|
return self.playlist_result(course_list)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user