From 14f56e860ef603a830b403db7444806136731247 Mon Sep 17 00:00:00 2001 From: gan-of-culture Date: Sun, 12 Dec 2021 16:16:20 +0100 Subject: [PATCH] added haho.moe --- README.md | 1 + extractors/extractors.go | 2 + extractors/haho/haho.go | 118 +++++++++++++++++++++++++++++++++++ extractors/haho/haho_test.go | 60 ++++++++++++++++++ 4 files changed, 181 insertions(+) create mode 100644 extractors/haho/haho.go create mode 100644 extractors/haho/haho_test.go diff --git a/README.md b/README.md index bdbf9e9..985bcf5 100755 --- a/README.md +++ b/README.md @@ -252,6 +252,7 @@ The following links will direct you to adult content. Please keep that in mind! | [e-hentai.org](http://e-hentai.org/) | :heavy_check_mark: | ? | | [ecchi.iwara.tv](https://ecchi.iwara.tv/) | :heavy_check_mark: |:heavy_check_mark:| | [exhentai.org*](http://exhentai.org/) | :heavy_check_mark: | ? | +| [haho.moe (1080p, 720p, 480p, 360p)](https://haho.moe) | ? |:heavy_check_mark:| | [hanime.io (1080p, 720p, 480p, 360p)](https://hanime.io) | ? |:heavy_check_mark:| | [hentai.guru (1080p, 720p, 480p)](https://hentai.guru/) | ? |:heavy_check_mark:| | [hentai.tv (1080p, 720p, 480p, 360p)](https://hentai.tv/) | ? |:heavy_check_mark:| diff --git a/extractors/extractors.go b/extractors/extractors.go index 58d886e..90e09b4 100755 --- a/extractors/extractors.go +++ b/extractors/extractors.go @@ -9,6 +9,7 @@ import ( "github.com/gan-of-culture/get-sauce/extractors/danbooru" "github.com/gan-of-culture/get-sauce/extractors/ehentai" "github.com/gan-of-culture/get-sauce/extractors/exhentai" + "github.com/gan-of-culture/get-sauce/extractors/haho" "github.com/gan-of-culture/get-sauce/extractors/hanime" "github.com/gan-of-culture/get-sauce/extractors/hentai2read" "github.com/gan-of-culture/get-sauce/extractors/hentai2w" @@ -70,6 +71,7 @@ func init() { "e-hentai.org": ehentai.New(), "ecchi.iwara.tv": iwara.New(), "exhentai.org": exhentai.New(), + "haho.moe": haho.New(), "hanime.io": hanime.New(), "hentai.guru": hentaiguru.New(), "hentai.pro": htstreamingExtactor, diff --git a/extractors/haho/haho.go b/extractors/haho/haho.go new file mode 100644 index 0000000..b5caf43 --- /dev/null +++ b/extractors/haho/haho.go @@ -0,0 +1,118 @@ +package haho + +import ( + "fmt" + "regexp" + "strings" + + "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://haho.moe" + +var reEpisodeURL = regexp.MustCompile(site + `/anime/\w+/\d+`) +var reSeriesURL = regexp.MustCompile(site + `/anime/\w{8}"`) +var reEmbedURL = regexp.MustCompile(site + `/embed\?v=[^"]+`) +var reSource = regexp.MustCompile(``)[0] + + // cut of hidden items + htmlString = strings.Split(htmlString, ``)[0] + + if matchedEpisodes := reEpisodeURL.FindAllString(htmlString, -1); len(matchedEpisodes) > 0 { + return matchedEpisodes + } + + out := []string{} + for _, series := range reSeriesURL.FindAllString(htmlString, -1) { + out = append(out, parseURL(strings.TrimSuffix(series, `"`))...) + } + + return out +} +func extractData(URL string) (*static.Data, error) { + htmlString, err := request.Get(URL) + if err != nil { + return nil, err + } + + title := utils.GetH1(&htmlString, -1) + + matchedEmbedURL := reEmbedURL.FindString(htmlString) + if matchedEmbedURL == "" { + return nil, static.ErrDataSourceParseFailed + } + + embedHtml, err := request.GetWithHeaders(matchedEmbedURL, map[string]string{"Referer": URL}) + if err != nil { + return nil, err + } + + sources := reSource.FindAllStringSubmatch(embedHtml, -1) + streams := map[string]*static.Stream{} + for i, source := range sources { + if len(source) < 4 { + return nil, static.ErrDataSourceParseFailed + } + size, _ := request.Size(source[1], site) + streams[fmt.Sprint(i)] = &static.Stream{ + Type: static.DataTypeVideo, + URLs: []*static.URL{ + { + URL: source[1], + Ext: strings.Split(source[3], "/")[1], + }, + }, + Quality: source[2], + Size: size, + } + } + + return &static.Data{ + Site: site, + Title: title, + Type: static.DataTypeVideo, + Streams: streams, + URL: URL, + }, nil +} diff --git a/extractors/haho/haho_test.go b/extractors/haho/haho_test.go new file mode 100644 index 0000000..e3c9246 --- /dev/null +++ b/extractors/haho/haho_test.go @@ -0,0 +1,60 @@ +package haho + +import "testing" + +func TestParseURL(t *testing.T) { + tests := []struct { + Name string + URL string + Want int + }{ + { + Name: "Single Episode Eng Sub", + URL: "https://haho.moe/anime/z7tg8ooz/1", + Want: 1, + }, { + Name: "Series", + URL: "https://haho.moe/anime/z7tg8ooz", + Want: 2, + }, { + // this is the same logic for all extensions that group shows e.g. /genres/ + // its hard to make a test for the other groups since the number of episodes always changes + Name: "Studio", + URL: "https://haho.moe/genre/i9sfflho", + 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 + URL string + Want int + }{ + { + Name: "Single Episode", + URL: "https://haho.moe/anime/59znzcjt/1", + Want: 1, + }, + } + for _, tt := range tests { + t.Run(tt.Name, func(t *testing.T) { + data, err := New().Extract(tt.URL) + if err != nil { + t.Error(err) + } + if len(data) > tt.Want || len(data) == 0 { + t.Errorf("Got: %v - Want: %v", len(data), tt.Want) + } + }) + } +}