Skip to content

Commit

Permalink
ニコニコ動画の検索APIを最新のものに変更
Browse files Browse the repository at this point in the history
  • Loading branch information
kosugikun committed Apr 14, 2024
1 parent fb2c681 commit 3dcb40d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/main/java/dev/cosgy/niconicoSearchAPI/nicoSearchAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,19 @@ public LinkedList<nicoVideoSearchResult> searchVideo(String query, int resultLim
if (resultLimit <= 0) resultLimit = 10;
if (cacheEnabled && videoResultCache == null) videoResultCache = new LinkedHashMap<>();

// https://snapshot.search.nicovideo.jp/api/v2/snapshot/video/contents/search?q=初音ミク&targets=title&fields=contentId,title,viewCounter&filters[viewCounter][gte]=10000&_sort=-viewCounter&_offset=0&_limit=3&_context=apiguide
// https://snapshot.search.nicovideo.jp/api/v2/snapshot/video/contents/search?q=初音ミク&_limit=5&_context=discord_bot&fields=contentId,title,description,tags,categoryTags,viewCounter,mylistCounter,commentCounter,startTime,lastCommentTime,lengthSeconds,thumbnailUrl&_sort=-viewCounter&targets=title

HTTPUtil hu = new HTTPUtil();
hu.setTargetAddress("https://api.search.nicovideo.jp/api/v2/video/contents/search");
hu.setTargetAddress("https://snapshot.search.nicovideo.jp/api/v2/snapshot/video/contents/search");
hu.setMethod("GET");
Map<String, String> queryMap = new HashMap<>();
queryMap.put("q", URLEncoder.encode(query, StandardCharsets.UTF_8));
queryMap.put("_sort", "-viewCounter");
queryMap.put("targets", "title");
queryMap.put("fields", "contentId,title,description,tags,categoryTags,viewCounter,mylistCounter,commentCounter,startTime,lastCommentTime,lengthSeconds,thumbnailUrl");
queryMap.put("fields", "contentId,title,description,userId,channelId,viewCounter,thumbnailUrl,categoryTags,tags,mylistCounter,commentCounter,startTime");
queryMap.put("_limit", String.valueOf(resultLimit));
queryMap.put("_context", "discord_bot");
hu.setQueryMap(queryMap);

LinkedList<nicoVideoSearchResult> results = new LinkedList<>();
Expand Down

0 comments on commit 3dcb40d

Please sign in to comment.