Skip to content

Commit

Permalink
Fix(provider): add more fields
Browse files Browse the repository at this point in the history
  • Loading branch information
xjasonlyu committed Jan 28, 2025
1 parent 4e79ece commit 2646a37
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
20 changes: 16 additions & 4 deletions provider/javfree/javfree.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 != "" {
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions provider/javfree/javfree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
func TestJAVFREE_GetMovieInfoByID(t *testing.T) {
testkit.Test(t, New, []string{
"243452-1151912",
"402171-4608186",
})
}

Expand Down

0 comments on commit 2646a37

Please sign in to comment.