diff --git a/youtube_dl/extractor/camsoda.py b/youtube_dl/extractor/camsoda.py index 036d0428f..9add4383a 100644 --- a/youtube_dl/extractor/camsoda.py +++ b/youtube_dl/extractor/camsoda.py @@ -9,30 +9,43 @@ from ..utils import ExtractorError class CamsodaIE(InfoExtractor): _VALID_URL = r'https?://(?:www\.)?camsoda\.com/(?P\S+)' _TEST = { - 'url': 'https://camsoda.com/bustynasha', - 'md5': 'TODO: md5 sum of the first 10241 bytes of the video file (use --test)', + 'url': 'https://camsoda.com/valeryromero', 'info_dict': { 'id': '42', 'ext': 'mp4', - 'title': 're:^bustynasha [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$', + 'title': 're:^valeryromero [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$', 'age_limit': 18, 'is_live': True, - } + }, + 'params': { + 'skip_download': True, + }, + 'skip': 'User is offline', } def _real_extract(self, url): video_id = self._match_id(url) - user_data = self._download_json('https://www.camsoda.com/api/v1/user/%s' % video_id, 'Downloading user data', video_id) + user_data = self._download_json('https://www.camsoda.com/api/v1/user/%s' % + video_id, 'Downloading user data', video_id) if not user_data.get('status'): + raise ExtractorError('Not a valid user', expected=True) + + video_data = self._download_json( + 'https://www.camsoda.com/api/v1/video/vtoken/%s?username=guest_%s' % + (video_id, str(random.randint(1000, 99999))), + 'Downloading second json', video_id + ) + + if not video_data.get('edge_servers'): raise ExtractorError('Stream is not available', expected=True) - # TODO more code goes here, for example ... - video_data = self._download_json('https://www.camsoda.com/api/v1/video/vtoken/%s?username=guest_%s' % - (video_id, str(random.randint(1000, 99999))), 'Downloading second json', video_id) + user = user_data.get('user') + if user: + thumb = user.get('thumb') or user.get('profile_picture') - HLS_URL_VIDEO = 'https://{server}/{app}/mp4:{stream_name}_aac/playlist.m3u8?token={token}' - hls_url = HLS_URL_VIDEO.format( + VIDEO_URL = 'https://{server}/{app}/mp4:{stream_name}_aac/playlist.m3u8?token={token}' + m3u8_url = VIDEO_URL.format( server=video_data['edge_servers'][0], app=video_data['app'], stream_name=video_data['stream_name'], @@ -41,7 +54,7 @@ class CamsodaIE(InfoExtractor): formats = [] formats.extend(self._extract_m3u8_formats( - hls_url, video_id, ext='mp4', + m3u8_url, video_id, ext='mp4', fatal=False, live=True) ) @@ -49,5 +62,6 @@ class CamsodaIE(InfoExtractor): 'id': video_id, 'title': self._live_title(video_id), 'is_live': True, + 'thumbnail': thumb, 'formats': formats, } diff --git a/youtube_dl/extractor/extractors.py b/youtube_dl/extractor/extractors.py index 06de556b7..e1d9696c3 100644 --- a/youtube_dl/extractor/extractors.py +++ b/youtube_dl/extractor/extractors.py @@ -139,6 +139,7 @@ from .camdemy import ( CamdemyFolderIE ) from .cammodels import CamModelsIE +from .camsoda import CamsodaIE from .camtube import CamTubeIE from .camwithher import CamWithHerIE from .canalplus import CanalplusIE