From 1174b97fb87c08b87893847c9a27a9f91816be69 Mon Sep 17 00:00:00 2001 From: mars67857 Date: Sun, 15 Oct 2017 15:38:29 -0700 Subject: [PATCH] Inlined strings that were only used once --- youtube_dl/extractor/cammodels.py | 56 +++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 18 deletions(-) diff --git a/youtube_dl/extractor/cammodels.py b/youtube_dl/extractor/cammodels.py index 931701af9..03370f708 100644 --- a/youtube_dl/extractor/cammodels.py +++ b/youtube_dl/extractor/cammodels.py @@ -7,15 +7,6 @@ import re class CamModelsIE(InfoExtractor): _VALID_URL = r'https?://(?:www\.)?cammodels\.com/cam/(?P\w+)' - _MANIFEST_URL = r'manifestUrlRoot=(?Phttps?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*))' - _MANIFEST_URL_CONSOLE_ERROR = 'Unable to find link to stream info on webpage. Room is not offline, so something else is wrong.' - _OFFLINE = r'(?PI\'m offline, but let\'s stay connected!)' - _OFFLINE_CONSOLE_ERROR = 'This user is currently offline, so nothing can be downloaded.' - _PRIVATE = r'(?PI’m in a private show right now)' - _PRIVATE_CONSOLE_ERROR = 'This user is doing a private show, which requires payment. This extractor currently does not support private streams.' - _MANIFEST_CONSOLE_ERROR = 'Link to stream info was found, but we couldn\'t access it. This stream may require login.' - _RTMP_URL_FALLBACK = r'(?Prtmp?:\/\/[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#&//=]*))' - _RTMP_URL_FALLBACK_CONSOLE_ERROR = 'Link to stream info was found, but we couldn\'t read the response. This is probably a bug.' _HEADERS = { 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36' } @@ -33,22 +24,46 @@ class CamModelsIE(InfoExtractor): } def _get_manifest_url_from_webpage(self, video_id, webpage): - manifest_url_root = self._html_search_regex(pattern=self._MANIFEST_URL, string=webpage, name='manifest', fatal=False) + manifest_url_root = self._html_search_regex( + pattern=r'manifestUrlRoot=(?Phttps?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*))', + string=webpage, + name='manifest', + fatal=False) if not manifest_url_root: - offline = self._html_search_regex(pattern=self._OFFLINE, string=webpage, name='offline indicator', fatal=False) + offline = self._html_search_regex( + pattern=r'(?PI\'m offline, but let\'s stay connected!)', + string=webpage, + name='offline indicator', + fatal=False) if offline: - raise ExtractorError(msg=self._OFFLINE_CONSOLE_ERROR, expected=True, video_id=video_id) - private = self._html_search_regex(pattern=self._PRIVATE, string=webpage, name='private show indicator', fatal=False) + raise ExtractorError( + msg='This user is currently offline, so nothing can be downloaded.', + expected=True, + video_id=video_id) + private = self._html_search_regex( + pattern=r'(?PI’m in a private show right now)', + string=webpage, + name='private show indicator', + fatal=False) if private: - raise ExtractorError(msg=self._PRIVATE_CONSOLE_ERROR, expected=True, video_id=video_id) - raise ExtractorError(msg=self._MANIFEST_URL_CONSOLE_ERROR, expected=False, video_id=video_id) + raise ExtractorError( + msg='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.', + 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) if not manifest: - raise ExtractorError(msg=self._MANIFEST_CONSOLE_ERROR, expected=False, video_id=video_id) + raise ExtractorError( + msg='Link to stream info was found, but we couldn\'t access it. This stream may require login.', + expected=False, + video_id=video_id) return manifest def _get_formats_from_manifest(self, manifest, video_id): @@ -68,9 +83,14 @@ class CamModelsIE(InfoExtractor): # If they change the JSON format, then fallback to parsing out RTMP links via regex. except: manifest_json = json.dumps(manifest) - manifest_links = re.finditer(pattern=self._RTMP_URL_FALLBACK, string=manifest_json) + manifest_links = re.finditer( + pattern=r'(?Prtmp?:\/\/[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#&//=]*))', + string=manifest_json) if not manifest_links: - raise ExtractorError(msg=self._RTMP_URL_FALLBACK_CONSOLE_ERROR, expected=False, video_id=video_id) + raise ExtractorError( + msg='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 = [] for manifest_link in manifest_links: url = manifest_link.group('id')