Added Thumbnails and saving those to db,

also added Log for Locking and unlocking Rw, because there was a Problem with that, and now it stays
This commit is contained in:
Pablu23
2024-02-23 14:59:08 +01:00
parent cd26d937aa
commit 23f96e0ab5
9 changed files with 236 additions and 29 deletions

View File

@@ -108,3 +108,40 @@ func (b *Bato) GetTitleIdAndChapterId(url string) (titleId int, chapterId int, e
return t, c, err
}
//func (b *Bato) GetChapterList(url string) (chapterIds []int, err error) {
//
//}
func (b *Bato) GetThumbnail(subUrl string) (thumbnailUrl string, err error) {
url := fmt.Sprintf("https://bato.to/title/%s", subUrl)
resp, err := http.Get(url)
// TODO: Testing for above 300 is dirty
if err != nil && resp.StatusCode > 300 {
return "", errors.New("could not get html")
}
defer func(Body io.ReadCloser) {
err := Body.Close()
if err != nil {
fmt.Printf("Could not close body because: %v\n", err)
}
}(resp.Body)
all, err := io.ReadAll(resp.Body)
if err != nil {
return "", err
}
h := string(all)
reg, err := regexp.Compile(`<img data-hk="0-1-0" .*? src="(.*?)["']`)
if err != nil {
return "", err
}
match := reg.FindStringSubmatch(h)
if len(match) <= 1 {
return "", errors.New("could not find Thumbnail url")
}
return match[1], nil
}

View File

@@ -7,4 +7,5 @@ type Provider interface {
GetPrev(html string) (url string, err error)
GetTitleAndChapter(url string) (title string, chapter string, err error)
GetTitleIdAndChapterId(url string) (titleId int, chapterId int, err error)
GetThumbnail(mangaId string) (thumbnailUrl string, err error)
}