|
|
@@ -8,6 +8,7 @@ import (
|
|
|
"fmt"
|
|
|
"log/slog"
|
|
|
"regexp"
|
|
|
+ "strings"
|
|
|
|
|
|
"miniflux.app/v2/internal/config"
|
|
|
"miniflux.app/v2/internal/model"
|
|
|
@@ -16,7 +17,6 @@ import (
|
|
|
)
|
|
|
|
|
|
var (
|
|
|
- bilibiliURLRegex = regexp.MustCompile(`bilibili\.com/video/(.*)$`)
|
|
|
bilibiliVideoIdRegex = regexp.MustCompile(`/video/(?:av(\d+)|BV([a-zA-Z0-9]+))`)
|
|
|
)
|
|
|
|
|
|
@@ -24,9 +24,7 @@ func shouldFetchBilibiliWatchTime(entry *model.Entry) bool {
|
|
|
if !config.Opts.FetchBilibiliWatchTime() {
|
|
|
return false
|
|
|
}
|
|
|
- matches := bilibiliURLRegex.FindStringSubmatch(entry.URL)
|
|
|
- urlMatchesBilibiliPattern := len(matches) == 2
|
|
|
- return urlMatchesBilibiliPattern
|
|
|
+ return strings.Contains(entry.URL, "bilibili.com/video/")
|
|
|
}
|
|
|
|
|
|
func extractBilibiliVideoID(websiteURL string) (string, string, error) {
|
|
|
@@ -52,7 +50,7 @@ func fetchBilibiliWatchTime(websiteURL string) (int, error) {
|
|
|
if extractErr != nil {
|
|
|
return 0, extractErr
|
|
|
}
|
|
|
- bilibiliApiURL := fmt.Sprintf("https://api.bilibili.com/x/web-interface/view?%s=%s", idType, videoID)
|
|
|
+ bilibiliApiURL := "https://api.bilibili.com/x/web-interface/view?" + idType + "=" + videoID
|
|
|
|
|
|
responseHandler := fetcher.NewResponseHandler(requestBuilder.ExecuteRequest(bilibiliApiURL))
|
|
|
defer responseHandler.Close()
|
|
|
@@ -65,7 +63,7 @@ func fetchBilibiliWatchTime(websiteURL string) (int, error) {
|
|
|
return 0, localizedError.Error()
|
|
|
}
|
|
|
|
|
|
- var result map[string]interface{}
|
|
|
+ var result map[string]any
|
|
|
doc := json.NewDecoder(responseHandler.Body(config.Opts.HTTPClientMaxBodySize()))
|
|
|
if docErr := doc.Decode(&result); docErr != nil {
|
|
|
return 0, fmt.Errorf("failed to decode API response: %v", docErr)
|
|
|
@@ -75,7 +73,7 @@ func fetchBilibiliWatchTime(websiteURL string) (int, error) {
|
|
|
return 0, fmt.Errorf("API returned error code: %v", result["code"])
|
|
|
}
|
|
|
|
|
|
- data, ok := result["data"].(map[string]interface{})
|
|
|
+ data, ok := result["data"].(map[string]any)
|
|
|
if !ok {
|
|
|
return 0, fmt.Errorf("data field not found or not an object")
|
|
|
}
|