Skip to content

Commit

Permalink
niconico: add support for tag search
Browse files Browse the repository at this point in the history
  • Loading branch information
Lesmiscore committed Feb 15, 2022
1 parent 2b8372f commit e669cc8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions yt_dlp/extractor/extractors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,7 @@
NicovideoSearchDateIE,
NicovideoSearchIE,
NicovideoSearchURLIE,
NicovideoTagURLIE,
NiconicoLiveIE,
)
from .niconico_smile import NiconicoSmileIE
Expand Down
23 changes: 22 additions & 1 deletion yt_dlp/extractor/niconico.py
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,8 @@ def _real_extract(self, url):


class NicovideoSearchBaseIE(InfoExtractor):
_SEARCH_TYPE = 'search'

def _entries(self, url, item_id, query=None, note='Downloading page %(page)s'):
query = query or {}
pages = [query['page']] if 'page' in query else itertools.count(1)
Expand All @@ -905,7 +907,7 @@ def _entries(self, url, item_id, query=None, note='Downloading page %(page)s'):

def _search_results(self, query):
return self._entries(
self._proto_relative_url(f'//www.nicovideo.jp/search/{query}'), query)
self._proto_relative_url(f'//www.nicovideo.jp/{self._SEARCH_TYPE}/{query}'), query)


class NicovideoSearchIE(NicovideoSearchBaseIE, SearchInfoExtractor):
Expand Down Expand Up @@ -985,6 +987,25 @@ def _get_entries_for_date(self, url, item_id, start_date, end_date=None, page_nu
yield from super()._entries(url, item_id, query=query, note=note)


class NicovideoTagURLIE(NicovideoSearchBaseIE):
IE_NAME = 'niconico:tag'
IE_DESC = 'NicoNico video tag URLs'
_SEARCH_TYPE = 'tag'
_VALID_URL = r'https?://(?:www\.)?nicovideo\.jp/tag/(?P<id>[^?#&]+)?'
_TESTS = [{
'url': 'https://www.nicovideo.jp/tag/%E3%83%89%E3%82%AD%E3%83%A5%E3%83%A1%E3%83%B3%E3%82%BF%E3%83%AA%E3%83%BC%E6%B7%AB%E5%A4%A2',
'info_dict': {
'id': 'ドキュメンタリー淫夢',
'title': 'ドキュメンタリー淫夢'
},
'playlist_mincount': 400,
}]

def _real_extract(self, url):
query = self._match_id(url)
return self.playlist_result(self._entries(url, query), query, query)


class NiconicoLiveIE(NiconicoBaseIE):
IE_NAME = 'niconico:live'
IE_DESC = 'ニコニコ生放送'
Expand Down

0 comments on commit e669cc8

Please sign in to comment.