use --username/--password, --netrc for API Key
This commit is contained in:
parent
a72b74c6f9
commit
fc75a2d468
@ -33,13 +33,7 @@ class CBAIE(InfoExtractor):
|
|||||||
'audio/ogg': {'id': '1', 'ext': 'ogg', 'preference': 100},
|
'audio/ogg': {'id': '1', 'ext': 'ogg', 'preference': 100},
|
||||||
'audio/mpeg': {'id': '2', 'ext': 'mp3', 'preference': 50}
|
'audio/mpeg': {'id': '2', 'ext': 'mp3', 'preference': 50}
|
||||||
}
|
}
|
||||||
_API_KEY = None
|
_NETRC_MACHINE = 'cba'
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
try:
|
|
||||||
self._API_KEY = os.environ["CBA_API_KEY"]
|
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
video_id = self._match_id(url)
|
video_id = self._match_id(url)
|
||||||
@ -65,14 +59,14 @@ class CBAIE(InfoExtractor):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
(_, api_key) = self._get_login_info()
|
||||||
|
api_key_msg = " (without API_KEY)"
|
||||||
|
if api_key:
|
||||||
|
api_key_msg = " (using API_KEY '%s')" % api_key
|
||||||
|
api_media_url = update_url_query(api_media_url, {'c': api_key})
|
||||||
|
|
||||||
api_key_str = " (without API_KEY)"
|
media_result = self._download_json(api_media_url, video_id, 'query media api-endpoint%s' % api_key_msg,
|
||||||
if self._API_KEY:
|
'unable to qeury media api-endpoint%s' % api_key_msg, encoding='utf-8-sig')
|
||||||
api_key_str = " (using API_KEY '%s')" % self._API_KEY
|
|
||||||
api_media_url = update_url_query(api_media_url, {'c': self._API_KEY})
|
|
||||||
|
|
||||||
media_result = self._download_json(api_media_url, video_id, 'query media api-endpoint%s' % api_key_str,
|
|
||||||
'unable to qeury media api-endpoint%s' % api_key_str, encoding='utf-8-sig')
|
|
||||||
for media in media_result:
|
for media in media_result:
|
||||||
try:
|
try:
|
||||||
url = media['source_url']
|
url = media['source_url']
|
||||||
@ -92,10 +86,10 @@ class CBAIE(InfoExtractor):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
if not formats:
|
if not formats:
|
||||||
if self._API_KEY:
|
if api_key:
|
||||||
raise ExtractorError('unable to fetch CBA entry')
|
raise ExtractorError('unable to fetch CBA entry')
|
||||||
else:
|
else:
|
||||||
raise UnavailableVideoError('you may need an API key to download copyright protected files')
|
self.raise_login_required('you need an API key to download copyright protected files')
|
||||||
|
|
||||||
self._sort_formats(formats)
|
self._sort_formats(formats)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user