1
0
mirror of https://github.com/l1ving/youtube-dl synced 2025-03-14 07:37:25 +08:00

Remove unneeded positional arguments. Add comment explaining why overriding User-Agent is needed.

This commit is contained in:
mars67857 2017-10-15 15:53:51 -07:00
parent 26ab8d70cd
commit 765de0f39c

View File

@ -9,59 +9,74 @@ class CamModelsIE(InfoExtractor):
_VALID_URL = r'https?://(?:www\.)?cammodels\.com/cam/(?P<id>\w+)'
_HEADERS = {
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36'
# Needed because server doesn't return links to video URLs if a browser-like User-Agent is not used
}
def _real_extract(self, url):
video_id = self._match_id(url)
webpage = self._download_webpage(url_or_request=url, video_id=video_id, headers=self._HEADERS)
manifest_url = self._get_manifest_url_from_webpage(video_id=video_id, webpage=webpage)
manifest = self._get_manifest_from_manifest_url(manifest_url=manifest_url, video_id=video_id, webpage=webpage)
formats = self._get_formats_from_manifest(manifest=manifest, video_id=video_id)
webpage = self._download_webpage(
url,
video_id,
headers=self._HEADERS)
manifest_url = self._get_manifest_url_from_webpage(
webpage,
video_id)
manifest = self._get_manifest_from_manifest_url(
manifest_url,
video_id,
webpage)
formats = self._get_formats_from_manifest(
manifest,
video_id)
return {
'id': video_id,
'title': self._live_title(video_id),
'formats': formats
}
def _get_manifest_url_from_webpage(self, video_id, webpage):
def _get_manifest_url_from_webpage(self, webpage, video_id):
manifest_url_root = self._html_search_regex(
pattern=r'manifestUrlRoot=(?P<id>https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*))',
string=webpage,
name='manifest',
r'manifestUrlRoot=(?P<id>https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*))',
webpage,
'manifest',
fatal=False)
if not manifest_url_root:
offline = self._html_search_regex(
pattern=r'(?P<id>I\'m offline, but let\'s stay connected!)',
string=webpage,
name='offline indicator',
r'(?P<id>I\'m offline, but let\'s stay connected!)',
webpage,
'offline indicator',
fatal=False)
if offline:
raise ExtractorError(
msg='This user is currently offline, so nothing can be downloaded.',
'This user is currently offline, so nothing can be downloaded.',
expected=True,
video_id=video_id)
private = self._html_search_regex(
pattern=r'(?P<id>Im in a private show right now)',
string=webpage,
name='private show indicator',
r'(?P<id>Im in a private show right now)',
webpage,
'private show indicator',
fatal=False)
if private:
raise ExtractorError(
msg='This user is doing a private show, which requires payment. This extractor currently does not support private streams.',
'This user is doing a private show, which requires payment. This extractor currently does not support private streams.',
expected=True,
video_id=video_id)
raise ExtractorError(
msg='Unable to find link to stream info on webpage. Room is not offline, so something else is wrong.',
'Unable to find link to stream info on webpage. Room is not offline, so something else is wrong.',
expected=False,
video_id=video_id)
manifest_url = manifest_url_root + video_id + '.json'
return manifest_url
def _get_manifest_from_manifest_url(self, manifest_url, video_id, webpage):
manifest = self._download_json(url_or_request=manifest_url, video_id=video_id, headers=self._HEADERS, fatal=False)
manifest = self._download_json(
manifest_url,
video_id,
headers=self._HEADERS,
fatal=False)
if not manifest:
raise ExtractorError(
msg='Link to stream URLs was found, but we couldn\'t access it.',
'Link to stream URLs was found, but we couldn\'t access it.',
expected=False,
video_id=video_id)
return manifest
@ -84,11 +99,11 @@ class CamModelsIE(InfoExtractor):
except:
manifest_json = json.dumps(manifest)
manifest_links = re.finditer(
pattern=r'(?P<id>rtmp?:\/\/[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#&//=]*))',
string=manifest_json)
r'(?P<id>rtmp?:\/\/[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#&//=]*))',
manifest_json)
if not manifest_links:
raise ExtractorError(
msg='Link to stream info was found, but we couldn\'t read the response. This is probably a bug.',
'Link to stream info was found, but we couldn\'t read the response. This is probably a bug.',
expected=False,
video_id=video_id)
formats = []