2 from __future__
import unicode_literals
9 from .common
import InfoExtractor
, SearchInfoExtractor
10 from ..postprocessor
.ffmpeg
import FFmpegPostProcessor
11 from ..compat
import (
14 compat_urllib_parse_urlparse
,
34 class NiconicoIE(InfoExtractor
):
39 'url': 'http://www.nicovideo.jp/watch/sm22312215',
40 'md5': 'a5bad06f1347452102953f323c69da34s',
44 'title': 'Big Buck Bunny',
45 'thumbnail': r
're:https?://.*',
46 'uploader': 'takuya0301',
47 'uploader_id': '2698420',
48 'upload_date': '20131123',
49 'timestamp': int, # timestamp is unstable
50 'description': '(c) copyright 2008, Blender Foundation / www.bigbuckbunny.org',
55 'skip': 'Requires an account',
57 # File downloaded with and without credentials are different, so omit
59 'url': 'http://www.nicovideo.jp/watch/nm14296458',
63 'title': '【鏡音リン】Dance on media【オリジナル】take2!',
64 'description': 'md5:689f066d74610b3b22e0f1739add0f58',
65 'thumbnail': r
're:https?://.*',
67 'uploader_id': '18822557',
68 'upload_date': '20110429',
69 'timestamp': 1304065916,
72 'skip': 'Requires an account',
74 # 'video exists but is marked as "deleted"
76 'url': 'http://www.nicovideo.jp/watch/sm10000',
79 'ext': 'unknown_video',
80 'description': 'deleted',
81 'title': 'ドラえもんエターナル第3話「決戦第3新東京市」<前編>',
82 'thumbnail': r
're:https?://.*',
83 'upload_date': '20071224',
84 'timestamp': int, # timestamp field has different value if logged in
88 'skip': 'Requires an account',
90 'url': 'http://www.nicovideo.jp/watch/so22543406',
94 'title': '【第1回】RADIOアニメロミックス ラブライブ!~のぞえりRadio Garden~',
95 'description': 'md5:b27d224bb0ff53d3c8269e9f8b561cf1',
96 'thumbnail': r
're:https?://.*',
97 'timestamp': 1388851200,
98 'upload_date': '20140104',
99 'uploader': 'アニメロチャンネル',
100 'uploader_id': '312',
102 'skip': 'The viewing period of the video you were searching for has expired.',
104 # video not available via `getflv`; "old" HTML5 video
105 'url': 'http://www.nicovideo.jp/watch/sm1151009',
106 'md5': '8fa81c364eb619d4085354eab075598a',
110 'title': 'マスターシステム本体内蔵のスペハリのメインテーマ(PSG版)',
111 'description': 'md5:6ee077e0581ff5019773e2e714cdd0b7',
112 'thumbnail': r
're:https?://.*',
114 'timestamp': 1190868283,
115 'upload_date': '20070927',
116 'uploader': 'denden2',
117 'uploader_id': '1392194',
119 'comment_count': int,
121 'skip': 'Requires an account',
125 'url': 'http://www.nicovideo.jp/watch/sm31464864',
129 'title': '新作TVアニメ「戦姫絶唱シンフォギアAXZ」PV 最高画質',
130 'description': 'md5:e52974af9a96e739196b2c1ca72b5feb',
131 'timestamp': 1498514060,
132 'upload_date': '20170626',
134 'uploader_id': '40826363',
135 'thumbnail': r
're:https?://.*',
138 'comment_count': int,
140 'skip': 'Requires an account',
142 # Video without owner
143 'url': 'http://www.nicovideo.jp/watch/sm18238488',
144 'md5': 'd265680a1f92bdcbbd2a507fc9e78a9e',
148 'title': '【実写版】ミュータントタートルズ',
149 'description': 'md5:15df8988e47a86f9e978af2064bf6d8e',
150 'timestamp': 1341160408,
151 'upload_date': '20120701',
154 'thumbnail': r
're:https?://.*',
157 'comment_count': int,
159 'skip': 'Requires an account',
161 'url': 'http://sp.nicovideo.jp/watch/sm28964488?ss_pos=1&cp_in=wt_tg',
162 'only_matching': True,
165 _VALID_URL
= r
'https?://(?:www\.|secure\.|sp\.)?nicovideo\.jp/watch/(?P<id>(?:[a-z]{2})?[0-9]+)'
166 _NETRC_MACHINE
= 'niconico'
169 'X-Frontend-ID': '6',
170 'X-Frontend-Version': '0'
173 def _real_initialize(self
):
177 username
, password
= self
._get
_login
_info
()
178 # No authentication to be performed
185 'mail_tel': username
,
186 'password': password
,
188 urlh
= self
._request
_webpage
(
189 'https://account.nicovideo.jp/api/v1/login', None,
190 note
='Logging in', errnote
='Unable to log in',
191 data
=urlencode_postdata(login_form_strs
))
195 parts
= compat_urllib_parse_urlparse(urlh
.geturl())
196 if compat_parse_qs(parts
.query
).get('message', [None])[0] == 'cant_login':
199 self
.report_warning('unable to log in: bad username or password')
202 def _get_heartbeat_info(self
, info_dict
):
204 video_id
, video_src_id
, audio_src_id
= info_dict
['url'].split(':')[1].split('/')
207 info_dict
.get('_api_data')
209 self
._html
_search
_regex
(
210 'data-api-data="([^"]+)"',
211 self
._download
_webpage
('http://www.nicovideo.jp/watch/' + video_id
, video_id
),
212 'API data', default
='{}'),
215 session_api_data
= try_get(api_data
, lambda x
: x
['media']['delivery']['movie']['session'])
216 session_api_endpoint
= try_get(session_api_data
, lambda x
: x
['urls'][0])
221 'https://nvapi.nicovideo.jp/v1/2ab0cbaa/watch', video_id
,
222 query
={'t': try_get(api_data, lambda x: x['media']['delivery']['trackingId'])}
,
223 note
='Acquiring permission for downloading video',
224 headers
=self
._API
_HEADERS
),
225 lambda x
: x
['meta']['status'])
227 self
.report_warning('Failed to acquire permission for playing video. The video may not download.')
229 yesno
= lambda x
: 'yes' if x
else 'no'
232 if try_get(api_data
, lambda x
: x
['media']['delivery']['encryption']) is not None:
234 encryption
= self
._parse
_json
(session_api_data
['token'], video_id
)['hls_encryption']
235 session_api_http_parameters
= {
240 'encrypted_key': try_get(api_data
, lambda x
: x
['media']['delivery']['encryption']['encryptedKey']),
241 'key_uri': try_get(api_data
, lambda x
: x
['media']['delivery']['encryption']['keyUri'])
244 'transfer_preset': '',
245 'use_ssl': yesno(session_api_endpoint
['isSsl']),
246 'use_well_known_port': yesno(session_api_endpoint
['isWellKnownPort']),
247 'segment_duration': 6000,
254 session_api_http_parameters
= {
256 'http_output_download_parameters': {
257 'use_ssl': yesno(session_api_endpoint
['isSsl']),
258 'use_well_known_port': yesno(session_api_endpoint
['isWellKnownPort']),
263 session_response
= self
._download
_json
(
264 session_api_endpoint
['url'], video_id
,
265 query
={'_format': 'json'}
,
266 headers
={'Content-Type': 'application/json'}
,
267 note
='Downloading JSON metadata for %s' % info_dict
['format_id'],
271 'player_id': session_api_data
.get('playerId'),
274 'auth_type': try_get(session_api_data
, lambda x
: x
['authTypes'][session_api_data
['protocols'][0]]),
275 'content_key_timeout': session_api_data
.get('contentKeyTimeout'),
276 'service_id': 'nicovideo',
277 'service_user_id': session_api_data
.get('serviceUserId')
279 'content_id': session_api_data
.get('contentId'),
280 'content_src_id_sets': [{
281 'content_src_ids': [{
283 'audio_src_ids': [audio_src_id
],
284 'video_src_ids': [video_src_id
],
288 'content_type': 'movie',
292 'lifetime': session_api_data
.get('heartbeatLifetime')
295 'priority': session_api_data
.get('priority'),
299 'http_parameters': session_api_http_parameters
302 'recipe_id': session_api_data
.get('recipeId'),
303 'session_operation_auth': {
304 'session_operation_auth_by_signature': {
305 'signature': session_api_data
.get('signature'),
306 'token': session_api_data
.get('token'),
309 'timing_constraint': 'unlimited'
313 info_dict
['url'] = session_response
['data']['session']['content_uri']
314 info_dict
['protocol'] = protocol
317 heartbeat_info_dict
= {
318 'url': session_api_endpoint
['url'] + '/' + session_response
['data']['session']['id'] + '?_format=json&_method=PUT',
319 'data': json
.dumps(session_response
['data']),
320 # interval, convert milliseconds to seconds, then halve to make a buffer.
321 'interval': float_or_none(session_api_data
.get('heartbeatLifetime'), scale
=3000),
325 return info_dict
, heartbeat_info_dict
327 def _extract_format_for_quality(self
, api_data
, video_id
, audio_quality
, video_quality
):
328 def parse_format_id(id_code
):
329 mobj
= re
.match(r
'''(?x)
331 (?:(?P<codec>[^_]+)_)?
332 (?:(?P<br>[\d]+)kbps_)?
333 (?:(?P<res>[\d+]+)p_)?
334 ''', '%s_' % id_code
)
335 return mobj
.groupdict() if mobj
else {}
337 protocol
= 'niconico_dmc'
338 format_id
= '-'.join(map(lambda s
: remove_start(s
['id'], 'archive_'), [video_quality
, audio_quality
]))
339 vdict
= parse_format_id(video_quality
['id'])
340 adict
= parse_format_id(audio_quality
['id'])
341 resolution
= try_get(video_quality
, lambda x
: x
['metadata']['resolution'], dict) or {'height': vdict.get('res')}
342 vbr
= try_get(video_quality
, lambda x
: x
['metadata']['bitrate'], float)
345 'url': '%s:%s/%s/%s' % (protocol
, video_id
, video_quality
['id'], audio_quality
['id']),
346 'format_id': format_id
,
347 'format_note': 'DMC %s' % try_get(video_quality
, lambda x
: x
['metadata']['label'], compat_str
),
348 'ext': 'mp4', # Session API are used in HTML5, which always serves mp4
349 'vcodec': vdict
.get('codec'),
350 'acodec': adict
.get('codec'),
351 'vbr': float_or_none(vbr
, 1000) or float_or_none(vdict
.get('br')),
352 'abr': float_or_none(audio_quality
.get('bitrate'), 1000) or float_or_none(adict
.get('br')),
353 'height': int_or_none(resolution
.get('height', vdict
.get('res'))),
354 'width': int_or_none(resolution
.get('width')),
355 'quality': -2 if 'low' in format_id
else -1, # Default quality value is -1
356 'protocol': protocol
,
358 'Origin': 'https://www.nicovideo.jp',
359 'Referer': 'https://www.nicovideo.jp/watch/' + video_id
,
363 def _real_extract(self
, url
):
364 video_id
= self
._match
_id
(url
)
366 # Get video webpage for API data.
367 webpage
, handle
= self
._download
_webpage
_handle
(
368 'http://www.nicovideo.jp/watch/' + video_id
, video_id
)
369 if video_id
.startswith('so'):
370 video_id
= self
._match
_id
(handle
.geturl())
372 api_data
= self
._parse
_json
(self
._html
_search
_regex
(
373 'data-api-data="([^"]+)"', webpage
,
374 'API data', default
='{}'), video_id
)
376 def get_video_info_web(items
):
377 return dict_get(api_data
['video'], items
)
380 video_info_xml
= self
._download
_xml
(
381 'http://ext.nicovideo.jp/api/getthumbinfo/' + video_id
,
382 video_id
, note
='Downloading video info page')
384 def get_video_info_xml(items
):
385 if not isinstance(items
, list):
388 ret
= xpath_text(video_info_xml
, './/' + item
)
392 if get_video_info_xml('error'):
393 error_code
= get_video_info_xml('code')
395 if error_code
== 'DELETED':
396 raise ExtractorError('The video has been deleted.',
398 elif error_code
== 'NOT_FOUND':
399 raise ExtractorError('The video is not found.',
401 elif error_code
== 'COMMUNITY':
402 self
.to_screen('%s: The video is community members only.' % video_id
)
404 raise ExtractorError('%s reports error: %s' % (self
.IE_NAME
, error_code
))
406 # Start extracting video formats
409 # Get HTML5 videos info
410 quality_info
= try_get(api_data
, lambda x
: x
['media']['delivery']['movie'])
412 raise ExtractorError('The video can\'t be downloaded', expected
=True)
414 for audio_quality
in quality_info
.get('audios') or {}:
415 for video_quality
in quality_info
.get('videos') or {}:
416 if not audio_quality
.get('isAvailable') or not video_quality
.get('isAvailable'):
418 formats
.append(self
._extract
_format
_for
_quality
(
419 api_data
, video_id
, audio_quality
, video_quality
))
423 video_real_url
= try_get(api_data
, lambda x
: x
['video']['smileInfo']['url'])
425 is_economy
= video_real_url
.endswith('low')
428 self
.report_warning('Site is currently in economy mode! You will only have access to lower quality streams')
430 # Invoking ffprobe to determine resolution
431 pp
= FFmpegPostProcessor(self
._downloader
)
432 cookies
= self
._get
_cookies
('https://nicovideo.jp').output(header
='', sep
='; path=/; domain=nicovideo.jp;\n')
434 self
.to_screen('%s: %s' % (video_id
, 'Checking smile format with ffprobe'))
437 metadata
= pp
.get_metadata_object(video_real_url
, ['-cookies', cookies
])
438 except PostProcessingError
as err
:
439 raise ExtractorError(err
.msg
, expected
=True)
441 v_stream
= a_stream
= {}
443 # Some complex swf files doesn't have video stream (e.g. nm4809023)
444 for stream
in metadata
['streams']:
445 if stream
['codec_type'] == 'video':
447 elif stream
['codec_type'] == 'audio':
450 # Community restricted videos seem to have issues with the thumb API not returning anything at all
452 (get_video_info_xml('size_high') if not is_economy
else get_video_info_xml('size_low'))
453 or metadata
['format']['size']
456 get_video_info_xml('movie_type')
457 or 'mp4' if 'mp4' in metadata
['format']['format_name'] else metadata
['format']['format_name']
460 # 'creation_time' tag on video stream of re-encoded SMILEVIDEO mp4 files are '1970-01-01T00:00:00.000000Z'.
462 parse_iso8601(get_video_info_web('first_retrieve'))
463 or unified_timestamp(get_video_info_web('postedDateTime'))
465 metadata_timestamp
= (
466 parse_iso8601(try_get(v_stream
, lambda x
: x
['tags']['creation_time']))
467 or timestamp
if extension
!= 'mp4' else 0
470 # According to compconf, smile videos from pre-2017 are always better quality than their DMC counterparts
471 smile_threshold_timestamp
= parse_iso8601('2016-12-08T00:00:00+09:00')
473 is_source
= timestamp
< smile_threshold_timestamp
or metadata_timestamp
> 0
475 # If movie file size is unstable, old server movie is not source movie.
478 'url': video_real_url
,
479 'format_id': 'smile' if not is_economy
else 'smile_low',
480 'format_note': 'SMILEVIDEO source' if not is_economy
else 'SMILEVIDEO low quality',
482 'container': extension
,
483 'vcodec': v_stream
.get('codec_name'),
484 'acodec': a_stream
.get('codec_name'),
485 # Some complex swf files doesn't have total bit rate metadata (e.g. nm6049209)
486 'tbr': int_or_none(metadata
['format'].get('bit_rate'), scale
=1000),
487 'vbr': int_or_none(v_stream
.get('bit_rate'), scale
=1000),
488 'abr': int_or_none(a_stream
.get('bit_rate'), scale
=1000),
489 'height': int_or_none(v_stream
.get('height')),
490 'width': int_or_none(v_stream
.get('width')),
491 'source_preference': 5 if not is_economy
else -2,
492 'quality': 5 if is_source
and not is_economy
else None,
496 self
._sort
_formats
(formats
)
498 # Start extracting information
500 get_video_info_xml('title') # prefer to get the untranslated original title
501 or get_video_info_web(['originalTitle', 'title'])
502 or self
._og
_search
_title
(webpage
, default
=None)
503 or self
._html
_search
_regex
(
504 r
'<span[^>]+class="videoHeaderTitle"[^>]*>([^<]+)</span>',
505 webpage
, 'video title'))
507 watch_api_data_string
= self
._html
_search
_regex
(
508 r
'<div[^>]+id="watchAPIDataContainer"[^>]+>([^<]+)</div>',
509 webpage
, 'watch api data', default
=None)
510 watch_api_data
= self
._parse
_json
(watch_api_data_string
, video_id
) if watch_api_data_string
else {}
511 video_detail
= watch_api_data
.get('videoDetail', {})
514 self
._html
_search
_regex
(r
'<meta property="og:image" content="([^"]+)">', webpage
, 'thumbnail data', default
=None)
515 or dict_get( # choose highest from 720p to 240p
516 get_video_info_web('thumbnail'),
517 ['ogp', 'player', 'largeUrl', 'middleUrl', 'url'])
518 or self
._html
_search
_meta
('image', webpage
, 'thumbnail', default
=None)
519 or video_detail
.get('thumbnail'))
521 description
= get_video_info_web('description')
524 match
= self
._html
_search
_meta
('datePublished', webpage
, 'date published', default
=None)
526 timestamp
= parse_iso8601(match
.replace('+', ':00+'))
527 if not timestamp
and video_detail
.get('postedAt'):
528 timestamp
= parse_iso8601(
529 video_detail
['postedAt'].replace('/', '-'),
530 delimiter
=' ', timezone
=datetime
.timedelta(hours
=9))
531 timestamp
= timestamp
or try_get(api_data
, lambda x
: parse_iso8601(x
['video']['registeredAt']))
533 view_count
= int_or_none(get_video_info_web(['view_counter', 'viewCount']))
535 match
= self
._html
_search
_regex
(
536 r
'>Views: <strong[^>]*>([^<]+)</strong>',
537 webpage
, 'view count', default
=None)
539 view_count
= int_or_none(match
.replace(',', ''))
542 or video_detail
.get('viewCount')
543 or try_get(api_data
, lambda x
: x
['video']['count']['view']))
546 int_or_none(get_video_info_web('comment_num'))
547 or video_detail
.get('commentCount')
548 or try_get(api_data
, lambda x
: x
['video']['count']['comment']))
550 if not comment_count
:
551 match
= self
._html
_search
_regex
(
552 r
'>Comments: <strong[^>]*>([^<]+)</strong>',
553 webpage
, 'comment count', default
=None)
555 comment_count
= int_or_none(match
.replace(',', ''))
557 duration
= (parse_duration(
558 get_video_info_web('length')
559 or self
._html
_search
_meta
(
560 'video:duration', webpage
, 'video duration', default
=None))
561 or video_detail
.get('length')
562 or get_video_info_web('duration'))
564 webpage_url
= get_video_info_web('watch_url') or url
566 # for channel movie and community movie
567 channel_id
= try_get(
569 (lambda x
: x
['channel']['globalId'],
570 lambda x
: x
['community']['globalId']))
573 (lambda x
: x
['channel']['name'],
574 lambda x
: x
['community']['name']))
576 # Note: cannot use api_data.get('owner', {}) because owner may be set to "null"
577 # in the JSON, which will cause None to be returned instead of {}.
578 owner
= try_get(api_data
, lambda x
: x
.get('owner'), dict) or {}
579 uploader_id
= str_or_none(
580 get_video_info_web(['ch_id', 'user_id'])
585 get_video_info_web(['ch_name', 'user_nickname'])
586 or owner
.get('nickname')
592 '_api_data': api_data
,
595 'thumbnail': thumbnail
,
596 'description': description
,
597 'uploader': uploader
,
598 'timestamp': timestamp
,
599 'uploader_id': uploader_id
,
601 'channel_id': channel_id
,
602 'view_count': view_count
,
603 'comment_count': comment_count
,
604 'duration': duration
,
605 'webpage_url': webpage_url
,
609 class NiconicoPlaylistIE(InfoExtractor
):
610 _VALID_URL
= r
'https?://(?:www\.)?nicovideo\.jp/(?:user/\d+/|my/)?mylist/(?P<id>\d+)'
613 'url': 'http://www.nicovideo.jp/mylist/27411728',
616 'title': 'AKB48のオールナイトニッポン',
617 'description': 'md5:d89694c5ded4b6c693dea2db6e41aa08',
619 'uploader_id': '805442',
621 'playlist_mincount': 225,
623 'url': 'https://www.nicovideo.jp/user/805442/mylist/27411728',
624 'only_matching': True,
628 'X-Frontend-ID': '6',
629 'X-Frontend-Version': '0'
632 def _real_extract(self
, url
):
633 list_id
= self
._match
_id
(url
)
635 def get_page_data(pagenum
, pagesize
):
636 return self
._download
_json
(
637 'http://nvapi.nicovideo.jp/v2/mylists/' + list_id
, list_id
,
638 query
={'page': 1 + pagenum, 'pageSize': pagesize}
,
639 headers
=self
._API
_HEADERS
).get('data').get('mylist')
641 data
= get_page_data(0, 1)
642 title
= data
.get('name')
643 description
= data
.get('description')
644 uploader
= data
.get('owner').get('name')
645 uploader_id
= data
.get('owner').get('id')
647 def pagefunc(pagenum
):
648 data
= get_page_data(pagenum
, 25)
651 'url': 'http://www.nicovideo.jp/watch/' + item
.get('watchId'),
652 } for item
in data
.get('items'))
658 'description': description
,
659 'uploader': uploader
,
660 'uploader_id': uploader_id
,
661 'entries': OnDemandPagedList(pagefunc
, 25),
665 NicovideoSearchIE_NAME
= 'nicovideo:search'
668 class NicovideoSearchURLIE(InfoExtractor
):
669 IE_NAME
= f
'{NicovideoSearchIE_NAME}_url'
670 IE_DESC
= 'Nico video search URLs'
671 _VALID_URL
= r
'https?://(?:www\.)?nicovideo\.jp/search/(?P<id>[^?#&]+)?'
673 'url': 'http://www.nicovideo.jp/search/sm9',
678 'playlist_mincount': 40,
680 'url': 'https://www.nicovideo.jp/search/sm9?sort=h&order=d&end=2020-12-31&start=2020-01-01',
685 'playlist_count': 31,
688 def _entries(self
, url
, item_id
, query
=None, note
='Downloading page %(page)s'):
690 pages
= [query
['page']] if 'page' in query
else itertools
.count(1)
691 for page_num
in pages
:
692 query
['page'] = str(page_num
)
693 webpage
= self
._download
_webpage
(url
, item_id
, query
=query
, note
=note
% {'page': page_num}
)
694 results
= re
.findall(r
'(?<=data-video-id=)["\']?
(?P
<videoid
>.*?
)(?
=["\'])', webpage)
696 yield self.url_result(f'http://www.nicovideo.jp/watch/{item}', 'Niconico', item)
700 def _real_extract(self, url):
701 query = self._match_id(url)
702 return self.playlist_result(self._entries(url, query), query, query)
705 class NicovideoSearchIE(SearchInfoExtractor, NicovideoSearchURLIE):
706 IE_DESC = 'Nico video searches'
707 _MAX_RESULTS = float('inf')
708 IE_NAME = NicovideoSearchIE_NAME
709 _SEARCH_KEY = 'nicosearch'
712 def _get_n_results(self, query, n):
713 entries = self._entries(self._proto_relative_url(f'//www.nicovideo.jp/search/{query}'), query)
715 entries = itertools.islice(entries, 0, n)
716 return self.playlist_result(entries, query, query)
719 class NicovideoSearchDateIE(NicovideoSearchIE):
720 IE_DESC = 'Nico video searches, newest first'
721 IE_NAME = f'{NicovideoSearchIE_NAME}:date'
722 _SEARCH_KEY = 'nicosearchdate'
724 'url': 'nicosearchdateall:a',
729 'playlist_mincount': 1610,
732 _START_DATE = datetime.date(2007, 1, 1)
733 _RESULTS_PER_PAGE = 32
736 def _entries(self, url, item_id, start_date=None, end_date=None):
737 start_date, end_date = start_date or self._START_DATE, end_date or datetime.datetime.now().date()
739 # If the last page has a full page of videos, we need to break down the query interval further
740 last_page_len = len(list(self._get_entries_for_date(
741 url, item_id, start_date, end_date, self._MAX_PAGES,
742 note=f'Checking number of videos from {start_date} to {end_date}')))
743 if (last_page_len == self._RESULTS_PER_PAGE and start_date != end_date):
744 midpoint = start_date + ((end_date - start_date) // 2)
745 yield from self._entries(url, item_id, midpoint, end_date)
746 yield from self._entries(url, item_id, start_date, midpoint)
748 self.to_screen(f'{item_id}: Downloading results from {start_date} to {end_date}')
749 yield from self._get_entries_for_date(
750 url, item_id, start_date, end_date, note=' Downloading page %(page)s')
752 def _get_entries_for_date(self, url, item_id, start_date, end_date=None, page_num=None, note=None):
754 'start': str(start_date),
755 'end': str(end_date or start_date),
760 query['page'] = str(page_num)
762 yield from NicovideoSearchURLIE._entries(self, url, item_id, query=query, note=note)
765 class NiconicoUserIE(InfoExtractor):
766 _VALID_URL = r'https?://(?:www\.)?nicovideo\.jp/user/(?P<id>\d+)/?(?:$|[#?])'
768 'url': 'https://www.nicovideo.jp/user/419948',
772 'playlist_mincount': 101,
774 _API_URL = "https
://nvapi
.nicovideo
.jp
/v1
/users
/%s/videos?sortKey
=registeredAt
&sortOrder
=desc
&pageSize
=%s&page
=%s"
778 'X-Frontend-ID': '6',
779 'X-Frontend-Version': '0'
782 def _entries(self, list_id):
785 while count < total_count:
786 json_parsed = self._download_json(
787 self._API_URL % (list_id, self._PAGE_SIZE, page_num + 1), list_id,
788 headers=self._API_HEADERS,
789 note='Downloading JSON metadata%s' % (' page %d' % page_num if page_num else ''))
791 total_count = int_or_none(json_parsed['data'].get('totalCount'))
792 for entry in json_parsed["data
"]["items
"]:
794 yield self.url_result('https://www.nicovideo.jp/watch/%s' % entry['id'])
797 def _real_extract(self, url):
798 list_id = self._match_id(url)
799 return self.playlist_result(self._entries(list_id), list_id, ie=NiconicoIE.ie_key())