Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Camsoda] Add new extractor #22036

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions youtube_dl/extractor/camsoda.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# coding: utf-8
from __future__ import unicode_literals

from .common import InfoExtractor
import random
from ..utils import ExtractorError


class CamsodaIE(InfoExtractor):
_VALID_URL = r'https?://(?:www\.)?camsoda\.com/(?P<id>\S+)'
_TEST = {
'url': 'https://camsoda.com/valeryromero',
'info_dict': {
'id': 'valeryromero',
'ext': 'mp4',
'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)
JChris246 marked this conversation as resolved.
Show resolved Hide resolved

if not user_data.get('status'):
raise ExtractorError('No broadcaster found', expected=True)

user = user_data.get('user')
if user:
thumb = user.get('thumb') or user.get('profile_picture')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Breaks on non dict user.

else:
thumb = None

video_data = self._download_json(
'https://www.camsoda.com/api/v1/video/vtoken/%s?username=guest_%s' %
JChris246 marked this conversation as resolved.
Show resolved Hide resolved
(video_id, str(random.randint(1000, 99999))),
JChris246 marked this conversation as resolved.
Show resolved Hide resolved
'Downloading stream token', video_id)

if not video_data.get('edge_servers'):
raise ExtractorError('Stream is not available', expected=True)

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'],
token=video_data['token'])

formats = []
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline.

formats.extend(self._extract_m3u8_formats(
m3u8_url, video_id, ext='mp4', live=True))

return {
'id': video_id,
'title': self._live_title(video_id),
'is_live': True,
'thumbnail': thumb,
'formats': formats,
'age_limit': 18,
}
1 change: 1 addition & 0 deletions youtube_dl/extractor/extractors.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
CamdemyFolderIE
)
from .cammodels import CamModelsIE
from .camsoda import CamsodaIE
from .camtube import CamTubeIE
from .camwithher import CamWithHerIE
from .canalplus import CanalplusIE
Expand Down