fix: log watch-order parse fallback

This commit is contained in:
2026-04-11 22:16:32 +02:00
parent 197c9c7485
commit f38ab058e0
3 changed files with 35 additions and 0 deletions

View File

@@ -17,6 +17,7 @@ const defaultUserAgent = "anime-relations-scraper/1.0 (+https://github.com/mkelv
var idPattern = regexp.MustCompile(`/id/(\d+)`)
var ErrInvalidWatchOrderURL = errors.New("invalid watch order url")
var ErrWatchOrderMarkupNotFound = errors.New("watch order markup not found")
type WatchOrderEntry struct {
ID int `json:"id"`
@@ -150,6 +151,10 @@ func extractRows(doc *goquery.Document) []watchOrderRow {
return rows
}
func hasWatchOrderTable(doc *goquery.Document) bool {
return doc.Find("#wo_list").Length() > 0
}
func FetchWatchOrder(ctx context.Context, httpClient *http.Client, url string) (WatchOrderResult, error) {
rootID, err := parseRootID(url)
if err != nil {
@@ -161,6 +166,10 @@ func FetchWatchOrder(ctx context.Context, httpClient *http.Client, url string) (
return WatchOrderResult{}, err
}
if !hasWatchOrderTable(doc) {
return WatchOrderResult{}, ErrWatchOrderMarkupNotFound
}
rows := extractRows(doc)
if len(rows) == 0 {
return WatchOrderResult{ID: rootID, WatchOrder: []WatchOrderEntry{}}, nil