Skip to content

Commit

Permalink
[extractor:hentaihavenred] moved to separate extractor
Browse files Browse the repository at this point in the history
  • Loading branch information
gan-of-culture committed Sep 19, 2023
1 parent 91c833f commit 6f701a2
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 35 deletions.
3 changes: 2 additions & 1 deletion extractors/extractors.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/gan-of-culture/get-sauce/extractors/hentaidude"
"github.com/gan-of-culture/get-sauce/extractors/hentaifoundry"
"github.com/gan-of-culture/get-sauce/extractors/hentaihaven"
"github.com/gan-of-culture/get-sauce/extractors/hentaihavenred"
"github.com/gan-of-culture/get-sauce/extractors/hentaimama"
"github.com/gan-of-culture/get-sauce/extractors/hentaimoon"
"github.com/gan-of-culture/get-sauce/extractors/hentaipulse"
Expand Down Expand Up @@ -78,7 +79,7 @@ func init() {
"hentaifox.com": htdoujinExtractor,
"hentaihaven.co": nhgroupExtractor,
"hentaihaven.com": hentaihaven.New(),
"hentaihaven.red": nhgroupExtractor,
"hentaihaven.red": hentaihavenred.New(),
"hentaihaven.xxx": vravenExtractor,
"hentaimama.io": hentaimama.New(),
"hentaipulse.com": hentaipulse.New(),
Expand Down
60 changes: 60 additions & 0 deletions extractors/hentaihavenred/hentaihavenred.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package hentaihavenred

import (
"github.com/gan-of-culture/get-sauce/extractors/jwplayer"
"github.com/gan-of-culture/get-sauce/extractors/nhgroup"
"github.com/gan-of-culture/get-sauce/request"
"github.com/gan-of-culture/get-sauce/static"
"github.com/gan-of-culture/get-sauce/utils"
)

const site = "https://hentaihaven.red/"

type extractor struct{}

// New returns a hentaihaven.red extractor
func New() static.Extractor {
return &extractor{}
}

func (e *extractor) Extract(URL string) ([]*static.Data, error) {
URLs := parseURL(URL)
if len(URLs) == 0 {
return nil, static.ErrURLParseFailed
}

data := []*static.Data{}
for _, u := range URLs {
d, err := extractData(u)
if err != nil {
return nil, utils.Wrap(err, u)
}
data = append(data, d)
}

return data, nil
}

func parseURL(URL string) []string {
return nhgroup.ParseURL(URL)
}

func extractData(URL string) (*static.Data, error) {

htmlString, err := request.Get(URL)
if err != nil {
return nil, err
}

data, err := jwplayer.New().Extract(jwplayer.FindJWPlayerURL(&htmlString))
if err != nil {
return nil, err
}

data[0].Site = site
data[0].Title = utils.GetSectionHeadingElement(&htmlString, 1, -1)
data[0].URL = URL

return data[0], nil

}
59 changes: 59 additions & 0 deletions extractors/hentaihavenred/hentaihavenred_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package hentaihavenred

import (
"testing"

"github.com/gan-of-culture/get-sauce/test"
)

func TestParseURL(t *testing.T) {
tests := []struct {
Name string
URL string
Want int
}{
{
Name: "Single Episode",
URL: "https://hentaihaven.red/hentai/ikusa-otome-suvia-episode-4/",
Want: 1,
},
}
for _, tt := range tests {
t.Run(tt.Name, func(t *testing.T) {
URLs := parseURL(tt.URL)
if len(URLs) > tt.Want || len(URLs) == 0 {
t.Errorf("Got: %v - Want: %v", len(URLs), tt.Want)
}
})
}
}

func TestExtract(t *testing.T) {
tests := []struct {
Name string
Args test.Args
}{
{
Name: "Single Episode",
Args: test.Args{
URL: "https://hentaihaven.red/hentai/ikusa-otome-suvia-episode-4/",
Title: "Ikusa Otome Suvia Episode 4",
Quality: "1280x720",
},
}, {
Name: "Single Episode 2",
Args: test.Args{
URL: "https://hentaihaven.red/hentai/class-de-otoko-wa-boku-hitori-episode-1/",
Title: "Class de Otoko wa Boku Hitori!? Episode 1",
Quality: "1920x1080",
},
},
}
for _, tt := range tests {
t.Run(tt.Name, func(t *testing.T) {
data, err := New().Extract(tt.Args.URL)
test.CheckError(t, err)
test.Check(t, tt.Args, data[0])
})
}
}
46 changes: 12 additions & 34 deletions extractors/nhgroup/nhgroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,46 +94,25 @@ func TestExtract(t *testing.T) {
{
Name: "Single Episode animeidhentai.com",
Args: test.Args{
URL: "https://animeidhentai.com/36364/usamimi-bouken-tan-sekuhara-shinagara-sekai-o-sukue-episode-3/",
Title: "Usamimi Bouken-tan: Sekuhara Shinagara Sekai o Sukue Episode 3",
Quality: "",
Size: 288687974,
URL: "https://animeidhentai.com/36364/usamimi-bouken-tan-sekuhara-shinagara-sekai-o-sukue-episode-3/",
Title: "Usamimi Bouken-tan: Sekuhara Shinagara Sekai o Sukue Episode 3",
Size: 288687974,
},
},
{
Name: "Single Episode hentaihaven.co",
Args: test.Args{
URL: "https://hentaihaven.co/watch/seika-jogakuin-koutoubu-kounin-sao-oji-san-episode-3/",
Title: "Seika Jogakuin Koutoubu Kounin Sao Oji-San Episode 3",
Quality: "",
Size: 391364277,
},
},
{
Name: "Single Episode",
Args: test.Args{
URL: "https://hentaihaven.red/hentai/bitch-na-inane-sama-episode-4/",
Title: "Bitch na Inane-sama Episode 4",
Quality: "1920x1080",
Size: 358198092,
},
},
{
Name: "[OLD] Single Episode",
Args: test.Args{
URL: "https://hentaihaven.red/hentai/mako-chan-kaihatsu-nikki-episode-2/",
Title: "Mako chan Kaihatsu Nikki Episode 2",
Quality: "1920x1080",
Size: 306057984,
URL: "https://hentaihaven.co/watch/seika-jogakuin-koutoubu-kounin-sao-oji-san-episode-3/",
Title: "Seika Jogakuin Koutoubu Kounin Sao Oji-San Episode 3",
Size: 391364277,
},
},
{
Name: "Single Episode hentai.tv",
Args: test.Args{
URL: "https://hentai.tv/hentai/usamimi-bouken-tan-sekuhara-shinagara-sekai-o-sukue-episode-3/",
Title: "Usamimi Bouken-tan: Sekuhara Shinagara Sekai o Sukue Episode 3",
Quality: "",
Size: 288687974,
URL: "https://hentai.tv/hentai/usamimi-bouken-tan-sekuhara-shinagara-sekai-o-sukue-episode-3/",
Title: "Usamimi Bouken-tan: Sekuhara Shinagara Sekai o Sukue Episode 3",
Size: 288687974,
},
},
{
Expand Down Expand Up @@ -163,10 +142,9 @@ func TestExtract(t *testing.T) {
{
Name: "[New] Single Episode uncensoredhentai.xxx",
Args: test.Args{
URL: "https://uncensoredhentai.xxx/watch/joshi-luck-episode-5/",
Title: "Joshi Luck! Episode 5",
Quality: "",
Size: 423727631,
URL: "https://uncensoredhentai.xxx/watch/joshi-luck-episode-5/",
Title: "Joshi Luck! Episode 5",
Size: 423727631,
},
},
}
Expand Down

0 comments on commit 6f701a2

Please sign in to comment.