Skip to content

Commit

Permalink
feat: support for parsing bilibili mobile share links (#19)
Browse files Browse the repository at this point in the history
支持解析 bilibili 手机端的分享链接

```release-note
支持解析 bilibili 手机端的分享链接
```
  • Loading branch information
Aziteee authored Nov 11, 2024
1 parent d064788 commit c59bb0c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferUtils;
import org.springframework.http.HttpHeaders;
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;
import run.halo.editor.hyperlink.HttpClientFactory;
import run.halo.editor.hyperlink.dto.HyperLinkBaseDTO;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -51,7 +54,15 @@ public Mono<String> getHyperLinkDetail(URI linkURI) {
httpHeaders.set(HttpHeaders.CONTENT_TYPE, "application/json");
})
.retrieve()
.bodyToMono(String.class));
.bodyToFlux(DataBuffer.class)
.flatMap(dataBuffer -> {
String content = dataBuffer.toString(StandardCharsets.UTF_8);
DataBufferUtils.release(dataBuffer);
return Mono.just(content);
})
.reduce(new StringBuilder(), StringBuilder::append)
.filter(stringBuilder -> !stringBuilder.isEmpty())
.map(StringBuilder::toString));
}

public String getQueryParam(URI linkURI) {
Expand All @@ -61,7 +72,6 @@ public String getQueryParam(URI linkURI) {
throw new RuntimeException("id not found");
}
String id = matcher.group(1);
System.out.println(id);
if (id.chars().allMatch(Character::isDigit)) {
return "aid=" + id;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ public String getQueryParam(URI linkURI) {
throw new RuntimeException("id not found");
}
String id = matcher.group(1);
System.out.println(id);
if (id.chars().allMatch(Character::isDigit)) {
return "songid=" + id;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public enum ParserType {

DEFAULT("default", HyperLinkDefaultParser.class),
QQMUSIC("(i.)?y.qq.com", HyperLinkQQMusicParser.class),
BILIBILI("www.bilibili.com", HyperLinkBilibiliParser.class);
BILIBILI("(www|m).bilibili.com", HyperLinkBilibiliParser.class);

private final String host;
private final Class<? extends HyperLinkParser<? extends HyperLinkBaseDTO>> type;
Expand Down

0 comments on commit c59bb0c

Please sign in to comment.