-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[extractor:hentaihavenred] moved to separate extractor
- Loading branch information
1 parent
91c833f
commit 6f701a2
Showing
4 changed files
with
133 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters