mirror of
https://github.com/truewhile/MeBox.git
synced 2026-10-04 04:26:38 +08:00
fix nexusphp search and library labels
This commit is contained in:
@@ -217,14 +217,14 @@ func nexusPHPTorrentRows(pageHTML string) []string {
|
||||
}
|
||||
|
||||
func firstNexusPHPLink(row, path string) *nexusPHPLink {
|
||||
pattern := regexp.MustCompile(`(?is)<a\b([^>]*href\s*=\s*["']([^"']*` + regexp.QuoteMeta(path) + `[^"']*)["'][^>]*)>(.*?)</a>`)
|
||||
pattern := regexp.MustCompile(`(?is)<a\b([^>]*href\s*=\s*["']([^"']*)["'][^>]*)>(.*?)</a>`)
|
||||
for _, match := range pattern.FindAllStringSubmatch(row, -1) {
|
||||
if len(match) < 4 {
|
||||
continue
|
||||
}
|
||||
href := html.UnescapeString(strings.TrimSpace(match[2]))
|
||||
parsed, err := url.Parse(href)
|
||||
if err != nil {
|
||||
if err != nil || !nexusPHPLinkPathMatches(parsed, path) {
|
||||
continue
|
||||
}
|
||||
return &nexusPHPLink{
|
||||
@@ -237,6 +237,22 @@ func firstNexusPHPLink(row, path string) *nexusPHPLink {
|
||||
return nil
|
||||
}
|
||||
|
||||
func nexusPHPLinkPathMatches(parsed *url.URL, want string) bool {
|
||||
if parsed == nil {
|
||||
return false
|
||||
}
|
||||
path := strings.TrimSpace(parsed.Path)
|
||||
if path == "" {
|
||||
path = strings.TrimSpace(parsed.Opaque)
|
||||
}
|
||||
path = strings.Trim(strings.ToLower(path), "/")
|
||||
want = strings.Trim(strings.ToLower(strings.TrimSpace(want)), "/")
|
||||
if path == "" || want == "" {
|
||||
return false
|
||||
}
|
||||
return path == want || strings.HasSuffix(path, "/"+want)
|
||||
}
|
||||
|
||||
func nexusPHPTitleFromLink(link nexusPHPLink) string {
|
||||
for _, attr := range []string{"title", "data-title"} {
|
||||
if value := htmlAttr(link.attrs, attr); value != "" {
|
||||
|
||||
@@ -247,6 +247,24 @@ func TestParseNexusPHPHTMLModernRows(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseNexusPHPHTMLIgnoresUserDetailsLinks(t *testing.T) {
|
||||
page := `
|
||||
<table>
|
||||
<tr><td><a href="userdetails.php?id=31044">shukBeta</a></td><td>15.5 GiB</td></tr>
|
||||
<tr><td><a href="/details.php?id=789" title="问心 S01 1080p">问心</a><a href="/download.php?id=789">下载</a></td><td>1.5 GiB</td></tr>
|
||||
</table>`
|
||||
result, err := parseNexusPHPHTML(page, "Nexus", "https://pt.example")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(result.Items) != 1 {
|
||||
t.Fatalf("items = %#v, want only real torrent details row", result.Items)
|
||||
}
|
||||
if result.Items[0].ID != "789" || result.Items[0].Title != "问心 S01 1080p" {
|
||||
t.Fatalf("parsed item = %#v", result.Items[0])
|
||||
}
|
||||
}
|
||||
|
||||
func TestMTeamAPIRateLimits(t *testing.T) {
|
||||
search := mteamAPIRateLimits(mteamAPIEndpointSearch)
|
||||
if len(search) != 1 || search[0].Limit != 1500 || search[0].Window != 24*time.Hour {
|
||||
|
||||
Reference in New Issue
Block a user