Skip to content

Commit

Permalink
Added Niconico channel extractor
Browse files Browse the repository at this point in the history
  • Loading branch information
horahoradev committed Mar 13, 2021
1 parent cc31c16 commit 6626c0d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion youtube_dl/extractor/extractors.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@
NickNightIE,
NickRuIE,
)
from .niconico import NiconicoIE, NiconicoPlaylistIE, NicovideoIE, NiconicoLiveIE
from .niconico import NiconicoIE, NiconicoPlaylistIE, NicovideoIE, NiconicoLiveIE, NiconicoChannelIE
from .ninecninemedia import NineCNineMediaIE
from .ninegag import NineGagIE
from .ninenow import NineNowIE
Expand Down
34 changes: 34 additions & 0 deletions youtube_dl/extractor/niconico.py
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,40 @@ def _real_extract(self, url):
'entries': entries,
}

class NiconicoChannelIE(InfoExtractor):
_VALID_URL = r'https?://(?:www\.)?nicovideo\.jp/user/(?P<id>\d+)'
# May need to add support for pagination? Need to find a user with many video uploads to test
_API_URL = "https://nvapi.nicovideo.jp/v1/users/%s/videos?sortKey=registeredAt&sortOrder=desc&pageSize=%s&page=%s"
_TEST = {}
_api_headers = {
'X-Frontend-ID': '6',
'X-Frontend-Version': '0',
'X-Niconico-Language': 'en-us'
}
_PAGE_SIZE = 100

def _real_extract(self, url):
list_id = self._match_id(url)
json_parsed = self._download_json(self._API_URL % (list_id, self._PAGE_SIZE, 1), "None", headers=self._api_headers)
total_count = json_parsed['data']['totalCount']

for page in range(1, math.ceil(total_count / 100.0) + 1):
json_parsed = self._download_json(self._API_URL % (list_id, self._PAGE_SIZE, page), "None", headers=self._api_headers)

entries = [{
'_type': 'url',
'ie_key': NiconicoIE.ie_key(),
'url': ('https://www.nicovideo.jp/watch/%s' %
entry['id']),
'id': entry['id'],
} for entry in json_parsed["data"]["items"]]

return {
'_type': 'playlist',
'id': list_id,
'entries': entries
}

# USAGE: youtube-dl "nicosearch<NUMBER OF ENTRIES>:<SEARCH STRING>"
class NicovideoIE(SearchInfoExtractor):
IE_DESC = 'Nico video search'
Expand Down

0 comments on commit 6626c0d

Please sign in to comment.