X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=youtube_dl%2Fextractor%2Fniconico.py;h=dd16d0042edae363914a1870092a7dd7dafff459;hb=b2e8e7dab567ed9b27817c5dd0cf173bc7fb8cfa;hp=ddec7b3387f98e8bc86ab44feefd175676d40489;hpb=d08225edf454dd28d0bc15d94b23d62c4deab7f4;p=youtube-dl diff --git a/youtube_dl/extractor/niconico.py b/youtube_dl/extractor/niconico.py index ddec7b338..dd16d0042 100644 --- a/youtube_dl/extractor/niconico.py +++ b/youtube_dl/extractor/niconico.py @@ -3,6 +3,7 @@ from __future__ import unicode_literals import re import json +import datetime from .common import InfoExtractor from ..compat import ( @@ -14,7 +15,9 @@ from ..utils import ( ExtractorError, int_or_none, parse_duration, - unified_strdate, + parse_iso8601, + xpath_text, + determine_ext, ) @@ -32,29 +35,37 @@ class NiconicoIE(InfoExtractor): 'uploader': 'takuya0301', 'uploader_id': '2698420', 'upload_date': '20131123', + 'timestamp': 1385182762, 'description': '(c) copyright 2008, Blender Foundation / www.bigbuckbunny.org', 'duration': 33, }, - 'params': { - 'username': 'ydl.niconico@gmail.com', - 'password': 'youtube-dl', - }, }, { + # File downloaded with and without credentials are different, so omit + # the md5 field 'url': 'http://www.nicovideo.jp/watch/nm14296458', - 'md5': '8db08e0158457cf852a31519fceea5bc', 'info_dict': { 'id': 'nm14296458', 'ext': 'swf', 'title': 'ãé¡é³ãªã³ãDance on mediaããªãªã¸ãã«ãtake2!', - 'description': 'md5:', + 'description': 'md5:689f066d74610b3b22e0f1739add0f58', 'uploader': 'ãããã', 'uploader_id': '18822557', 'upload_date': '20110429', + 'timestamp': 1304065916, 'duration': 209, }, - 'params': { - 'username': 'ydl.niconico@gmail.com', - 'password': 'youtube-dl', + }, { + # 'video exists but is marked as "deleted" + # md5 is unstable + 'url': 'http://www.nicovideo.jp/watch/sm10000', + 'info_dict': { + 'id': 'sm10000', + 'ext': 'unknown_video', + 'description': 'deleted', + 'title': 'ãã©ãããã¨ã¿ã¼ãã«ç¬¬3話ã決æ¦ç¬¬3æ°æ±äº¬å¸ãï¼åç·¨ï¼', + 'upload_date': '20071224', + 'timestamp': 1198527840, # timestamp field has different value if logged in + 'duration': 304, }, }] @@ -95,9 +106,10 @@ class NiconicoIE(InfoExtractor): def _real_extract(self, url): video_id = self._match_id(url) - # Get video webpage. We are not actually interested in it, but need - # the cookies in order to be able to download the info webpage - self._download_webpage('http://www.nicovideo.jp/watch/' + video_id, video_id) + # Get video webpage. We are not actually interested in it for normal + # cases, but need the cookies in order to be able to download the + # info webpage + webpage = self._download_webpage('http://www.nicovideo.jp/watch/' + video_id, video_id) video_info = self._download_xml( 'http://ext.nicovideo.jp/api/getthumbinfo/' + video_id, video_id, @@ -127,22 +139,78 @@ class NiconicoIE(InfoExtractor): flv_info_request, video_id, note='Downloading flv info', errnote='Unable to download flv info') - if 'deleted=' in flv_info_webpage: - raise ExtractorError('The video has been deleted.', - expected=True) - video_real_url = compat_urlparse.parse_qs(flv_info_webpage)['url'][0] + flv_info = compat_urlparse.parse_qs(flv_info_webpage) + if 'url' not in flv_info: + if 'deleted' in flv_info: + raise ExtractorError('The video has been deleted.', + expected=True) + else: + raise ExtractorError('Unable to find video URL') + + video_real_url = flv_info['url'][0] # Start extracting information - title = video_info.find('.//title').text - extension = video_info.find('.//movie_type').text + title = xpath_text(video_info, './/title') + if not title: + title = self._og_search_title(webpage, default=None) + if not title: + title = self._html_search_regex( + r']+class="videoHeaderTitle"[^>]*>([^<]+)', + webpage, 'video title') + + watch_api_data_string = self._html_search_regex( + r'