From c98ff70f1f4a403edaddff26daba0dc165602588 Mon Sep 17 00:00:00 2001 From: Jian-Long Huang Date: Thu, 24 Dec 2015 01:28:39 +0800 Subject: [PATCH 1/2] niconico: Support authentication with cookie --- youtube_dl/extractor/niconico.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/youtube_dl/extractor/niconico.py b/youtube_dl/extractor/niconico.py index 586e52a4a..6608dc0c0 100644 --- a/youtube_dl/extractor/niconico.py +++ b/youtube_dl/extractor/niconico.py @@ -92,8 +92,14 @@ class NiconicoIE(InfoExtractor): def _login(self): (username, password) = self._get_login_info() - # No authentication to be performed if not username: + # Check session cookie + for cookie in self._downloader.cookiejar: + if cookie.name == 'user_session': + self._AUTHENTICATED = True + return True + + # No authentication to be performed return True # Log in From 665d63d0c4322af9f849ba9f0fea9ab75366ba46 Mon Sep 17 00:00:00 2001 From: Jian-Long Huang Date: Fri, 25 Dec 2015 15:28:31 +0800 Subject: [PATCH 2/2] Try to download flv info in second way if the session is expired. --- youtube_dl/extractor/niconico.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/youtube_dl/extractor/niconico.py b/youtube_dl/extractor/niconico.py index 6608dc0c0..dd74845c2 100644 --- a/youtube_dl/extractor/niconico.py +++ b/youtube_dl/extractor/niconico.py @@ -134,12 +134,15 @@ class NiconicoIE(InfoExtractor): 'http://ext.nicovideo.jp/api/getthumbinfo/' + video_id, video_id, note='Downloading video info page') + flv_info_webpage = '' + if self._AUTHENTICATED: # Get flv info flv_info_webpage = self._download_webpage( 'http://flapi.nicovideo.jp/api/getflv/' + video_id + '?as3=1', video_id, 'Downloading flv info') - else: + + if not self._AUTHENTICATED or 'closed=1' in flv_info_webpage: # Get external player info ext_player_info = self._download_webpage( 'http://ext.nicovideo.jp/thumb_watch/' + video_id, video_id)