mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-26 09:11:25 +01:00
Compare commits
No commits in common. "bcace2019aa66d5b11388385a02d7212b38309ea" and "548d50db25254624022bb015b3cc5644265322b5" have entirely different histories.
bcace2019a
...
548d50db25
|
@ -1,11 +1,11 @@
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
|
from ..networking import Request
|
||||||
from ..utils import (
|
from ..utils import (
|
||||||
ExtractorError,
|
ExtractorError,
|
||||||
lowercase_escape,
|
lowercase_escape,
|
||||||
url_or_none,
|
url_or_none,
|
||||||
urlencode_postdata,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -41,48 +41,58 @@ class ChaturbateIE(InfoExtractor):
|
||||||
'only_matching': True,
|
'only_matching': True,
|
||||||
}]
|
}]
|
||||||
|
|
||||||
_ERROR_MAP = {
|
_ROOM_OFFLINE = 'Room is currently offline'
|
||||||
'offline': 'Room is currently offline',
|
_ROOM_PRIVATE = 'Room is currently in a private show'
|
||||||
'private': 'Room is currently in a private show',
|
_ROOM_AWAY = 'Performer is currently away'
|
||||||
'away': 'Performer is currently away',
|
_ROOM_PASSWORD = 'Room is password protected'
|
||||||
'password protected': 'Room is password protected',
|
_ROOM_HIDDEN = 'Hidden session in progress'
|
||||||
'hidden': 'Hidden session in progress',
|
_ROOM_BLOCKED = 'Room is not avaiable in this region'
|
||||||
}
|
|
||||||
|
|
||||||
def _extract_from_api(self, video_id, tld):
|
def _extract_from_api(self, video_id, tld):
|
||||||
response = self._download_json(
|
req = Request(
|
||||||
f'https://chaturbate.{tld}/get_edge_hls_url_ajax/', video_id,
|
f'https://chaturbate.{tld}/get_edge_hls_url_ajax/',
|
||||||
data=urlencode_postdata({'room_slug': video_id}),
|
data=f'room_slug={video_id}'.encode(),
|
||||||
headers={
|
headers={
|
||||||
**self.geo_verification_headers(),
|
|
||||||
'X-Requested-With': 'XMLHttpRequest',
|
'X-Requested-With': 'XMLHttpRequest',
|
||||||
'Accept': 'application/json',
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||||||
}, fatal=False, impersonate=True) or {}
|
},
|
||||||
|
)
|
||||||
|
response = self._download_json(req, video_id, fatal=False)
|
||||||
|
|
||||||
status = response.get('room_status')
|
status = response.get('room_status')
|
||||||
if status != 'public':
|
if status == 'offline':
|
||||||
if error := self._ERROR_MAP.get(status):
|
raise ExtractorError(self._ROOM_OFFLINE, expected=True)
|
||||||
raise ExtractorError(error, expected=True)
|
elif status == 'private':
|
||||||
self.report_warning('Falling back to webpage extraction')
|
raise ExtractorError(self._ROOM_PRIVATE, expected=True)
|
||||||
|
elif status == 'away':
|
||||||
|
raise ExtractorError(self._ROOM_AWAY, expected=True)
|
||||||
|
elif status == 'hidden':
|
||||||
|
raise ExtractorError(self._ROOM_HIDDEN, expected=True)
|
||||||
|
elif status == 'password protected':
|
||||||
|
raise ExtractorError(self._ROOM_PASSWORD, expected=True)
|
||||||
|
elif status != 'public':
|
||||||
return None
|
return None
|
||||||
|
|
||||||
m3u8_url = response.get('url')
|
m3u8_url = response.get('url')
|
||||||
if not m3u8_url:
|
if not m3u8_url:
|
||||||
self.raise_geo_restricted()
|
raise ExtractorError(self._ROOM_BLOCKED, expected=True)
|
||||||
|
|
||||||
|
formats = self._extract_m3u8_formats(
|
||||||
|
m3u8_url, video_id, ext='mp4',
|
||||||
|
fatal=False, live=True)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'id': video_id,
|
'id': video_id,
|
||||||
'title': video_id,
|
'title': video_id,
|
||||||
'thumbnail': f'https://roomimg.stream.highwebmedia.com/ri/{video_id}.jpg',
|
'thumbnail': f'https://roomimg.stream.highwebmedia.com/ri/{video_id}.jpg',
|
||||||
'is_live': True,
|
'is_live': True,
|
||||||
'age_limit': 18,
|
'formats': formats,
|
||||||
'formats': self._extract_m3u8_formats(m3u8_url, video_id, ext='mp4', live=True),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def _extract_from_webpage(self, video_id, tld):
|
def _extract_from_webpage(self, video_id, tld):
|
||||||
webpage = self._download_webpage(
|
webpage = self._download_webpage(
|
||||||
f'https://chaturbate.{tld}/{video_id}/', video_id,
|
f'https://chaturbate.{tld}/{video_id}/', video_id,
|
||||||
headers=self.geo_verification_headers(), impersonate=True)
|
headers=self.geo_verification_headers())
|
||||||
|
|
||||||
found_m3u8_urls = []
|
found_m3u8_urls = []
|
||||||
|
|
||||||
|
@ -120,8 +130,8 @@ class ChaturbateIE(InfoExtractor):
|
||||||
webpage, 'error', group='error', default=None)
|
webpage, 'error', group='error', default=None)
|
||||||
if not error:
|
if not error:
|
||||||
if any(p in webpage for p in (
|
if any(p in webpage for p in (
|
||||||
self._ERROR_MAP['offline'], 'offline_tipping', 'tip_offline')):
|
self._ROOM_OFFLINE, 'offline_tipping', 'tip_offline')):
|
||||||
error = self._ERROR_MAP['offline']
|
error = self._ROOM_OFFLINE
|
||||||
if error:
|
if error:
|
||||||
raise ExtractorError(error, expected=True)
|
raise ExtractorError(error, expected=True)
|
||||||
raise ExtractorError('Unable to find stream URL')
|
raise ExtractorError('Unable to find stream URL')
|
||||||
|
@ -151,4 +161,7 @@ class ChaturbateIE(InfoExtractor):
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
video_id, tld = self._match_valid_url(url).group('id', 'tld')
|
video_id, tld = self._match_valid_url(url).group('id', 'tld')
|
||||||
return self._extract_from_api(video_id, tld) or self._extract_from_webpage(video_id, tld)
|
extraction = self._extract_from_api(video_id, tld)
|
||||||
|
if extraction is None:
|
||||||
|
extraction = self._extract_from_webpage(video_id, tld)
|
||||||
|
return extraction
|
||||||
|
|
Loading…
Reference in New Issue
Block a user