package service import ( "regexp" "strconv" "strings" ) // parseNexusPHPDetailHTML 解析种子详情页。 func parseNexusPHPDetailHTML(html, id, baseURL string) (*TorrentDetail, error) { detail := &TorrentDetail{ ID: id, DetailURL: baseURL + "/details.php?id=" + id, } if m := regexp.MustCompile(`]*>([^<]+)`).FindStringSubmatch(html); len(m) >= 2 { detail.Title = strings.TrimSpace(m[1]) } if m := regexp.MustCompile(`]*class="[^"]*sub[^"]*"[^>]*>([^<]+)`).FindStringSubmatch(html); len(m) >= 2 { detail.Subtitle = strings.TrimSpace(m[1]) } if m := regexp.MustCompile(`(?i)info_hash[^<]*\s*]*>([^<]+)`).FindStringSubmatch(html); len(m) >= 2 { detail.InfoHash = strings.TrimSpace(m[1]) } if m := regexp.MustCompile(`(?i)imdb[^<]*\s*]*>[^<]*(tt\d+)`).FindStringSubmatch(html); len(m) >= 2 { detail.ImdbID = m[1] } if m := regexp.MustCompile(`(?i)size[^<]*\s*]*>(\d+\.?\d*)\s*(GB|MB|TB|KB)`).FindStringSubmatch(html); len(m) >= 3 { detail.Size = parseSizeString(m[1], m[2]) } if m := regexp.MustCompile(`seeders[^<]*\s*]*>(\d+)\s*]*>\s*\s*]*>\s*\s*]*>leechers[^<]*\s*]*>(\d+)`).FindStringSubmatch(html); len(m) >= 3 { detail.Seeders, _ = strconv.Atoi(m[1]) detail.Leechers, _ = strconv.Atoi(m[2]) } if m := regexp.MustCompile(`(?i)times completed[^<]*\s*]*>(\d+)`).FindStringSubmatch(html); len(m) >= 2 { detail.Snatched, _ = strconv.Atoi(m[1]) } if m := regexp.MustCompile(`(?i)]*id="kdescr"[^>]*>(.*?)`).FindStringSubmatch(html); len(m) >= 2 { detail.Description = stripHTML(m[1]) } detail.DownloadURL = baseURL + "/download.php?id=" + id detail.Free = strings.Contains(html, "free") || strings.Contains(html, "免费") return detail, nil }