From 2646a37243e5d732ed26764364ef83b6e72c4bb0 Mon Sep 17 00:00:00 2001 From: xjasonlyu Date: Mon, 27 Jan 2025 22:16:33 -0500 Subject: [PATCH] Fix(provider): add more fields --- provider/javfree/javfree.go | 20 ++++++++++++++++---- provider/javfree/javfree_test.go | 1 + 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/provider/javfree/javfree.go b/provider/javfree/javfree.go index f7b3dc5b..f8538e75 100644 --- a/provider/javfree/javfree.go +++ b/provider/javfree/javfree.go @@ -7,8 +7,10 @@ import ( "strings" "github.com/gocolly/colly/v2" + "golang.org/x/net/html" "github.com/metatube-community/metatube-sdk-go/common/fetch" + "github.com/metatube-community/metatube-sdk-go/common/parser" "github.com/metatube-community/metatube-sdk-go/model" "github.com/metatube-community/metatube-sdk-go/provider" "github.com/metatube-community/metatube-sdk-go/provider/fc2/fc2util" @@ -81,14 +83,23 @@ func (javfree *JAVFREE) GetMovieInfoByURL(rawURL string) (info *model.MovieInfo, // Title c.OnXML(`//header[@class="entry-header"]/h1`, func(e *colly.XMLElement) { - regex := `(?i)(?:FC2(?:[-_]?PPV)?[-_]?)(\d+)` - re, _ := regexp.Compile(regex) - info.Title = strings.TrimSpace(re.ReplaceAllString(e.Text, "")) - if num := fc2util.ParseNumber(strings.TrimSpace(rawURL[strings.LastIndex(rawURL, "/")+1:])); num != "" { + info.Title = strings.TrimSpace(regexp. + MustCompile(`(?i)(?:FC2(?:[-_]?PPV)?[-_]?)(\d+)`). + ReplaceAllString(e.Text, "")) + if num := fc2util.ParseNumber(strings. + TrimSpace(rawURL[strings.LastIndex(rawURL, "/")+1:])); num != "" { info.Number = fmt.Sprintf("FC2-%s", num) } }) + // Director & Release Date + c.OnXML(`//span[@class="post-author"]/strong`, func(e *colly.XMLElement) { + info.Director = strings.TrimSpace(e.Text) + if next := e.DOM.(*html.Node).NextSibling; next != nil { + info.ReleaseDate = parser.ParseDate(next.Data) + } + }) + // Preview Images c.OnXML(`//div[@class="entry-content"]/p/img`, func(e *colly.XMLElement) { if href := e.Attr("src"); href != "" { @@ -100,6 +111,7 @@ func (javfree *JAVFREE) GetMovieInfoByURL(rawURL string) (info *model.MovieInfo, c.OnScraped(func(_ *colly.Response) { if info.CoverURL == "" && len(info.PreviewImages) > 0 { info.CoverURL = info.PreviewImages[0] + info.PreviewImages = info.PreviewImages[1:] } // cover as thumb image. info.ThumbURL = info.CoverURL diff --git a/provider/javfree/javfree_test.go b/provider/javfree/javfree_test.go index 79fe8cfd..b23898ba 100644 --- a/provider/javfree/javfree_test.go +++ b/provider/javfree/javfree_test.go @@ -9,6 +9,7 @@ import ( func TestJAVFREE_GetMovieInfoByID(t *testing.T) { testkit.Test(t, New, []string{ "243452-1151912", + "402171-4608186", }) }