0
0
Fork 0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2024-11-17 01:25:11 +00:00

[niconico] Fix ignored --netrc flag

See issue #3753
This commit is contained in:
Naglis Jonaitis 2014-10-12 23:18:42 +03:00
parent 772ece3571
commit 23d83ad4d5

View file

@ -39,18 +39,17 @@ class NiconicoIE(InfoExtractor):
_VALID_URL = r'https?://(?:www\.|secure\.)?nicovideo\.jp/watch/((?:[a-z]{2})?[0-9]+)' _VALID_URL = r'https?://(?:www\.|secure\.)?nicovideo\.jp/watch/((?:[a-z]{2})?[0-9]+)'
_NETRC_MACHINE = 'niconico' _NETRC_MACHINE = 'niconico'
# Determine whether the downloader uses authentication to download video # Determine whether the downloader used authentication to download video
_AUTHENTICATE = False _AUTHENTICATED = False
def _real_initialize(self): def _real_initialize(self):
if self._downloader.params.get('username', None) is not None: self._login()
self._AUTHENTICATE = True
if self._AUTHENTICATE:
self._login()
def _login(self): def _login(self):
(username, password) = self._get_login_info() (username, password) = self._get_login_info()
# No authentication to be performed
if not username:
return True
# Log in # Log in
login_form_strs = { login_form_strs = {
@ -68,6 +67,8 @@ def _login(self):
if re.search(r'(?i)<h1 class="mb8p4">Log in error</h1>', login_results) is not None: if re.search(r'(?i)<h1 class="mb8p4">Log in error</h1>', login_results) is not None:
self._downloader.report_warning('unable to log in: bad username or password') self._downloader.report_warning('unable to log in: bad username or password')
return False return False
# Successful login
self._AUTHENTICATED = True
return True return True
def _real_extract(self, url): def _real_extract(self, url):
@ -82,7 +83,7 @@ def _real_extract(self, url):
'http://ext.nicovideo.jp/api/getthumbinfo/' + video_id, video_id, 'http://ext.nicovideo.jp/api/getthumbinfo/' + video_id, video_id,
note='Downloading video info page') note='Downloading video info page')
if self._AUTHENTICATE: if self._AUTHENTICATED:
# Get flv info # Get flv info
flv_info_webpage = self._download_webpage( flv_info_webpage = self._download_webpage(
'http://flapi.nicovideo.jp/api/getflv?v=' + video_id, 'http://flapi.nicovideo.jp/api/getflv?v=' + video_id,