yoink-go initial commit
This commit is contained in:
22
.gitignore
vendored
Normal file
22
.gitignore
vendored
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
# Binaries for programs and plugins
|
||||||
|
*.exe
|
||||||
|
*.exe~
|
||||||
|
*.dll
|
||||||
|
*.so
|
||||||
|
*.dylib
|
||||||
|
|
||||||
|
# Test binary, built with `go test -c`
|
||||||
|
*.test
|
||||||
|
|
||||||
|
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||||
|
*.out
|
||||||
|
|
||||||
|
# Dependency directories (remove the comment below to include it)
|
||||||
|
# vendor/
|
||||||
|
|
||||||
|
# Go workspace file
|
||||||
|
go.work
|
||||||
|
go.work.sum
|
||||||
|
|
||||||
|
# env file
|
||||||
|
.env
|
||||||
59
cli/root.go
Normal file
59
cli/root.go
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
package cli
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"yoink/comic"
|
||||||
|
|
||||||
|
"github.com/PuerkitoBio/goquery"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Options struct {
|
||||||
|
Verbose bool
|
||||||
|
LibraryPath string
|
||||||
|
}
|
||||||
|
|
||||||
|
var cli = &cobra.Command{
|
||||||
|
Use: "yoink",
|
||||||
|
Short: "yoink",
|
||||||
|
Args: cobra.ExactArgs(1),
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
library, ok := os.LookupEnv("YOINK_LIBRARY")
|
||||||
|
if !ok {
|
||||||
|
userHome, _ := os.UserHomeDir()
|
||||||
|
library = filepath.Join(userHome, ".yoink")
|
||||||
|
}
|
||||||
|
|
||||||
|
options := Options{
|
||||||
|
Verbose: false,
|
||||||
|
LibraryPath: library,
|
||||||
|
}
|
||||||
|
|
||||||
|
var markupChannel = make(chan *goquery.Document)
|
||||||
|
var imageChannel = make(chan []string)
|
||||||
|
|
||||||
|
comic := comic.NewComic(args[0], options.LibraryPath, imageChannel, markupChannel)
|
||||||
|
|
||||||
|
fmt.Println(comic.Title)
|
||||||
|
|
||||||
|
err := comic.Download(len(comic.Filelist))
|
||||||
|
for e := range err {
|
||||||
|
fmt.Println(e)
|
||||||
|
}
|
||||||
|
|
||||||
|
comic.Archive()
|
||||||
|
comic.Cleanup()
|
||||||
|
},
|
||||||
|
Version: "1.1.0",
|
||||||
|
}
|
||||||
|
|
||||||
|
func Execute() error {
|
||||||
|
if err := cli.Execute(); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
108
comic/archive.go
Normal file
108
comic/archive.go
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
package comic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"archive/zip"
|
||||||
|
"io"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ArchiveError struct {
|
||||||
|
Message string
|
||||||
|
Code int
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a ArchiveError) Error() string {
|
||||||
|
return a.Message
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Comic) Archive() error {
|
||||||
|
|
||||||
|
outputPath := filepath.Join(c.LibraryPath, c.Title, c.Title+".cbz")
|
||||||
|
err := os.MkdirAll(filepath.Dir(outputPath), os.ModePerm)
|
||||||
|
if err != nil {
|
||||||
|
return ArchiveError{
|
||||||
|
Message: "error creating directory",
|
||||||
|
Code: 1,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
zipFile, err := os.Create(outputPath)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer zipFile.Close()
|
||||||
|
|
||||||
|
zwriter := zip.NewWriter(zipFile)
|
||||||
|
defer zwriter.Close()
|
||||||
|
|
||||||
|
sourcePath := filepath.Join(c.LibraryPath, c.Title)
|
||||||
|
|
||||||
|
err = filepath.Walk(
|
||||||
|
filepath.Dir(sourcePath),
|
||||||
|
func(path string, info os.FileInfo, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return ArchiveError{
|
||||||
|
Message: "error walking archive",
|
||||||
|
Code: 1,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if info.IsDir() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
ext := strings.ToLower(filepath.Ext(path))
|
||||||
|
if ext != ".jpg" && ext != ".jpeg" && ext != ".png" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
relPath, err := filepath.Rel(sourcePath, path)
|
||||||
|
if err != nil {
|
||||||
|
return ArchiveError{
|
||||||
|
Message: "error walking archive",
|
||||||
|
Code: 1,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
file, err := os.Open(path)
|
||||||
|
if err != nil {
|
||||||
|
return ArchiveError{
|
||||||
|
Message: "error walking archive",
|
||||||
|
Code: 1,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
zipEntry, err := zwriter.Create(relPath)
|
||||||
|
if err != nil {
|
||||||
|
return ArchiveError{
|
||||||
|
Message: "error walking archive",
|
||||||
|
Code: 1,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = io.Copy(zipEntry, file)
|
||||||
|
if err != nil {
|
||||||
|
return ArchiveError{
|
||||||
|
Message: "error walking archive",
|
||||||
|
Code: 1,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return ArchiveError{
|
||||||
|
Message: "error writing files to archive",
|
||||||
|
Code: 1,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("Created archive\n: %s", outputPath)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
31
comic/cleanup.go
Normal file
31
comic/cleanup.go
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package comic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (c *Comic) Cleanup() error {
|
||||||
|
filepath.Walk(
|
||||||
|
filepath.Join(c.LibraryPath, c.Title),
|
||||||
|
func(path string, info os.FileInfo, err error) error {
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if info.IsDir() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, ext := range []string{".jpg", ".jpeg", ".png"} {
|
||||||
|
edited := strings.Replace(info.Name(), c.Title, "", 1)
|
||||||
|
edited = strings.Trim(edited, " ")
|
||||||
|
|
||||||
|
if !strings.HasPrefix(strings.ToLower(edited), "001") && strings.HasSuffix(info.Name(), ext) {
|
||||||
|
return os.Remove(path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
return nil
|
||||||
|
}
|
||||||
77
comic/comic.go
Normal file
77
comic/comic.go
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
package comic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/PuerkitoBio/goquery"
|
||||||
|
)
|
||||||
|
|
||||||
|
// var debugUrl = "https://readallcomics.com/ultraman-x-avengers-001-2024/"
|
||||||
|
|
||||||
|
type Comic struct {
|
||||||
|
URL string
|
||||||
|
Title string
|
||||||
|
Markup *goquery.Document
|
||||||
|
Filelist []string
|
||||||
|
Next *Comic
|
||||||
|
Prev *Comic
|
||||||
|
LibraryPath string
|
||||||
|
}
|
||||||
|
|
||||||
|
func extractTitleFromMarkup(c Comic) string {
|
||||||
|
yearFormat := `^(.*?)\s+\(\d{4}(?:\s+.+)?\)`
|
||||||
|
selection := c.Markup.Find("title")
|
||||||
|
|
||||||
|
if selection.Length() == 0 {
|
||||||
|
return "Untitled"
|
||||||
|
}
|
||||||
|
|
||||||
|
content := selection.First().Text()
|
||||||
|
regex := regexp.MustCompile(yearFormat)
|
||||||
|
matches := regex.FindStringSubmatch(content)
|
||||||
|
|
||||||
|
if len(matches) != 2 {
|
||||||
|
return "Untitled"
|
||||||
|
}
|
||||||
|
|
||||||
|
return strings.ReplaceAll(matches[1], ":", "")
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewComic(
|
||||||
|
url string, libraryPath string,
|
||||||
|
imageChannel chan []string,
|
||||||
|
markupChannel chan *goquery.Document,
|
||||||
|
) *Comic {
|
||||||
|
c := &Comic{
|
||||||
|
URL: url,
|
||||||
|
LibraryPath: libraryPath,
|
||||||
|
}
|
||||||
|
|
||||||
|
go Markup(c.URL, markupChannel)
|
||||||
|
|
||||||
|
markup := <-markupChannel
|
||||||
|
c.Markup = markup
|
||||||
|
c.Title = extractTitleFromMarkup(*c)
|
||||||
|
|
||||||
|
go ParseImageLinks(markup, imageChannel)
|
||||||
|
links := <-imageChannel
|
||||||
|
|
||||||
|
c.Filelist = links
|
||||||
|
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Comic) Cover() (imageFilepath string, err error) {
|
||||||
|
for _, image := range c.Filelist {
|
||||||
|
if strings.HasSuffix(image, "000.jpg") || strings.HasSuffix(image, "001.jpg") {
|
||||||
|
image, err := filepath.Abs(image)
|
||||||
|
if err != nil {
|
||||||
|
return image, ImageParseError{Message: err.Error(), Code: 1}
|
||||||
|
}
|
||||||
|
return image, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "", ImageParseError{Message: "No cover found", Code: 1}
|
||||||
|
}
|
||||||
254
comic/download.go
Normal file
254
comic/download.go
Normal file
@@ -0,0 +1,254 @@
|
|||||||
|
package comic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
cloudflarebp "github.com/DaRealFreak/cloudflare-bp-go"
|
||||||
|
)
|
||||||
|
|
||||||
|
// func _downloadFile(wg *sync.WaitGroup, url string, page int, c *Comic) error {
|
||||||
|
// defer wg.Done()
|
||||||
|
|
||||||
|
// pageNumber := fmt.Sprintf("%03d", page)
|
||||||
|
// formattedImagePath := fmt.Sprintf("%s %s.jpg", c.Title, pageNumber)
|
||||||
|
// imageFilepath, _ := filepath.Abs(filepath.Join(c.LibraryPath, c.Title, formattedImagePath))
|
||||||
|
|
||||||
|
// if err := os.MkdirAll(
|
||||||
|
// filepath.Dir(imageFilepath),
|
||||||
|
// os.ModePerm,
|
||||||
|
// ); err != nil {
|
||||||
|
// return ComicDownloadError{
|
||||||
|
// Message: "error creating directory",
|
||||||
|
// Code: 1,
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // get image data
|
||||||
|
// res, err := handleRequest(url)
|
||||||
|
// if err != nil {
|
||||||
|
// return ComicDownloadError{
|
||||||
|
// Message: "invalid request",
|
||||||
|
// Code: 1,
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// defer res.Body.Close()
|
||||||
|
|
||||||
|
// var fileChannel = make(chan *os.File)
|
||||||
|
|
||||||
|
// go func() error {
|
||||||
|
// imageFile, err := os.Create(imageFilepath)
|
||||||
|
// if err != nil {
|
||||||
|
// return ComicDownloadError{
|
||||||
|
// Message: "error creating image file",
|
||||||
|
// Code: 1,
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// defer imageFile.Close()
|
||||||
|
|
||||||
|
// fileChannel <- imageFile
|
||||||
|
|
||||||
|
// return nil
|
||||||
|
// }()
|
||||||
|
|
||||||
|
// println("Downloading", imageFilepath)
|
||||||
|
|
||||||
|
// go func(
|
||||||
|
// fc chan *os.File,
|
||||||
|
// res *http.Response,
|
||||||
|
// ) error {
|
||||||
|
// buffer := make([]byte, 64*1024)
|
||||||
|
|
||||||
|
// defer close(fileChannel)
|
||||||
|
|
||||||
|
// // write image data
|
||||||
|
// _, err := io.CopyBuffer(<-fc, res.Body, buffer)
|
||||||
|
// if err != nil {
|
||||||
|
// return ComicDownloadError{
|
||||||
|
// Message: "Unable to save file contents",
|
||||||
|
// Code: 1,
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return nil
|
||||||
|
// }(fileChannel, res)
|
||||||
|
|
||||||
|
// return nil
|
||||||
|
// }
|
||||||
|
|
||||||
|
func downloadFile(url string, page int, c *Comic) error {
|
||||||
|
pageNumber := fmt.Sprintf("%03d", page)
|
||||||
|
formattedImagePath := fmt.Sprintf("%s %s.jpg", c.Title, pageNumber)
|
||||||
|
imageFilepath, _ := filepath.Abs(filepath.Join(c.LibraryPath, c.Title, formattedImagePath))
|
||||||
|
|
||||||
|
if err := os.MkdirAll(
|
||||||
|
filepath.Dir(imageFilepath),
|
||||||
|
os.ModePerm,
|
||||||
|
); err != nil {
|
||||||
|
return ComicDownloadError{
|
||||||
|
Message: "error creating directory",
|
||||||
|
Code: 1,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := handleRequest(url)
|
||||||
|
if err != nil {
|
||||||
|
return ComicDownloadError{
|
||||||
|
Message: "invalid request",
|
||||||
|
Code: 1,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
defer res.Body.Close()
|
||||||
|
|
||||||
|
imageFile, err := os.Create(imageFilepath)
|
||||||
|
if err != nil {
|
||||||
|
return ComicDownloadError{
|
||||||
|
Message: "error creating image file",
|
||||||
|
Code: 1,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
defer imageFile.Close()
|
||||||
|
|
||||||
|
written, err := io.Copy(imageFile, res.Body)
|
||||||
|
if err != nil {
|
||||||
|
return ComicDownloadError{
|
||||||
|
Message: "Unable to save file contents",
|
||||||
|
Code: 1,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if written == 0 {
|
||||||
|
return ComicDownloadError{
|
||||||
|
Message: "Unable to save file contents",
|
||||||
|
Code: 1,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func handleRequest(url string) (*http.Response, error) {
|
||||||
|
// adjust timeout and keep-alive to avoid connection timeout
|
||||||
|
transport := &http.Transport{
|
||||||
|
DisableKeepAlives: false,
|
||||||
|
MaxIdleConnsPerHost: 32,
|
||||||
|
}
|
||||||
|
|
||||||
|
// add cloudflare bypass
|
||||||
|
cfTransport := cloudflarebp.AddCloudFlareByPass(transport)
|
||||||
|
|
||||||
|
// prevents cloudflarebp from occasionally returning the wrong type
|
||||||
|
if converted, ok := cfTransport.(*http.Transport); ok {
|
||||||
|
transport = converted
|
||||||
|
}
|
||||||
|
|
||||||
|
client := &http.Client{
|
||||||
|
Timeout: time.Second * 30,
|
||||||
|
Transport: transport,
|
||||||
|
}
|
||||||
|
|
||||||
|
// mimic generic browser
|
||||||
|
req, err := http.NewRequest("GET", url, nil)
|
||||||
|
if err != nil {
|
||||||
|
return nil, ComicDownloadError{
|
||||||
|
Message: "invalid request",
|
||||||
|
Code: 1,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36")
|
||||||
|
|
||||||
|
res, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, ComicDownloadError{
|
||||||
|
Message: "invalid request",
|
||||||
|
Code: 1,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if res.StatusCode != http.StatusOK {
|
||||||
|
return nil, ComicDownloadError{
|
||||||
|
Message: "bad response",
|
||||||
|
Code: 1,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Comic) Download(concurrency int) []error {
|
||||||
|
// var wg sync.WaitGroup
|
||||||
|
// wg.Add(len(c.Filelist))
|
||||||
|
|
||||||
|
// for i, link := range c.Filelist {
|
||||||
|
// go downloadFile(link, i+1, c)
|
||||||
|
// }
|
||||||
|
|
||||||
|
// wg.Wait()
|
||||||
|
// return nil
|
||||||
|
jobs := make(chan Download)
|
||||||
|
results := make(chan error)
|
||||||
|
|
||||||
|
for worker := 1; worker <= concurrency; worker++ {
|
||||||
|
go workerPool(jobs, results)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, url := range c.Filelist {
|
||||||
|
jobs <- Download{
|
||||||
|
URL: url,
|
||||||
|
Page: i + 1,
|
||||||
|
Comic: c,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var errors []error
|
||||||
|
for i := 0; i < len(c.Filelist); i++ {
|
||||||
|
err := <-results
|
||||||
|
if err != nil {
|
||||||
|
errors = append(errors, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return errors
|
||||||
|
}
|
||||||
|
|
||||||
|
type Download struct {
|
||||||
|
URL string
|
||||||
|
Page int
|
||||||
|
Comic *Comic
|
||||||
|
}
|
||||||
|
|
||||||
|
func workerPool(jobs <-chan Download, results chan<- error) {
|
||||||
|
for job := range jobs {
|
||||||
|
results <- downloadFile(job.URL, job.Page, job.Comic)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func DownloadComicImages(c *Comic, concurrency int) []error {
|
||||||
|
jobs := make(chan Download)
|
||||||
|
results := make(chan error)
|
||||||
|
|
||||||
|
for worker := 1; worker <= concurrency; worker++ {
|
||||||
|
go workerPool(jobs, results)
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, url := range c.Filelist {
|
||||||
|
jobs <- Download{
|
||||||
|
URL: url,
|
||||||
|
Page: i + 1,
|
||||||
|
Comic: c,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var errors []error
|
||||||
|
for i := 0; i < len(c.Filelist); i++ {
|
||||||
|
err := <-results
|
||||||
|
if err != nil {
|
||||||
|
errors = append(errors, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return errors
|
||||||
|
}
|
||||||
19
comic/error.go
Normal file
19
comic/error.go
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package comic
|
||||||
|
|
||||||
|
type ImageParseError struct {
|
||||||
|
Message string
|
||||||
|
Code int
|
||||||
|
}
|
||||||
|
|
||||||
|
type ComicDownloadError struct {
|
||||||
|
Message string
|
||||||
|
Code int
|
||||||
|
}
|
||||||
|
|
||||||
|
func (i ImageParseError) Error() string {
|
||||||
|
return i.Message
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c ComicDownloadError) Error() string {
|
||||||
|
return c.Message
|
||||||
|
}
|
||||||
52
comic/parser.go
Normal file
52
comic/parser.go
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
package comic
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/PuerkitoBio/goquery"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Markup(url string, c chan *goquery.Document) *goquery.Document {
|
||||||
|
res, err := http.Get(url)
|
||||||
|
if err != nil {
|
||||||
|
return &goquery.Document{}
|
||||||
|
}
|
||||||
|
defer res.Body.Close()
|
||||||
|
|
||||||
|
if res.StatusCode != http.StatusOK {
|
||||||
|
return &goquery.Document{}
|
||||||
|
}
|
||||||
|
|
||||||
|
content, err := io.ReadAll(res.Body)
|
||||||
|
if err != nil {
|
||||||
|
return &goquery.Document{}
|
||||||
|
}
|
||||||
|
|
||||||
|
markup, err := goquery.NewDocumentFromReader(strings.NewReader(string(content)))
|
||||||
|
if err != nil {
|
||||||
|
return &goquery.Document{}
|
||||||
|
}
|
||||||
|
|
||||||
|
c <- markup
|
||||||
|
return markup
|
||||||
|
}
|
||||||
|
|
||||||
|
func ParseImageLinks(markup *goquery.Document, c chan []string) ([]string, error) {
|
||||||
|
var links []string
|
||||||
|
markup.Find("img").Each(func(_ int, image *goquery.Selection) {
|
||||||
|
link, _ := image.Attr("src")
|
||||||
|
if !strings.Contains(link, "logo") && (strings.Contains(link, "bp.blogspot.com") || strings.Contains(link, "blogger.googleusercontent") || strings.Contains(link, "covers")) {
|
||||||
|
links = append(links, link)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
c <- links
|
||||||
|
|
||||||
|
if len(links) > 0 {
|
||||||
|
return links, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return links, ImageParseError{Message: "No images found", Code: 1}
|
||||||
|
}
|
||||||
17
go.mod
Normal file
17
go.mod
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
module yoink
|
||||||
|
|
||||||
|
go 1.22.3
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/DaRealFreak/cloudflare-bp-go v1.0.4
|
||||||
|
github.com/PuerkitoBio/goquery v1.9.2
|
||||||
|
github.com/spf13/cobra v1.8.1
|
||||||
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/EDDYCJY/fake-useragent v0.2.0 // indirect
|
||||||
|
github.com/andybalholm/cascadia v1.3.2 // indirect
|
||||||
|
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||||
|
github.com/spf13/pflag v1.0.5 // indirect
|
||||||
|
golang.org/x/net v0.24.0 // indirect
|
||||||
|
)
|
||||||
62
go.sum
Normal file
62
go.sum
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
github.com/DaRealFreak/cloudflare-bp-go v1.0.4 h1:33X8Z0YMV1DEVvL/kYLku+rjb4wF712+VIh3xBoifQ0=
|
||||||
|
github.com/DaRealFreak/cloudflare-bp-go v1.0.4/go.mod h1:oBI9KAKb9FqdoB42uUqHU6pdP+YDWlKjpZRSk8JTuwk=
|
||||||
|
github.com/EDDYCJY/fake-useragent v0.2.0 h1:Jcnkk2bgXmDpX0z+ELlUErTkoLb/mxFBNd2YdcpvJBs=
|
||||||
|
github.com/EDDYCJY/fake-useragent v0.2.0/go.mod h1:5wn3zzlDxhKW6NYknushqinPcAqZcAPHy8lLczCdJdc=
|
||||||
|
github.com/PuerkitoBio/goquery v1.9.2 h1:4/wZksC3KgkQw7SQgkKotmKljk0M6V8TUvA8Wb4yPeE=
|
||||||
|
github.com/PuerkitoBio/goquery v1.9.2/go.mod h1:GHPCaP0ODyyxqcNoFGYlAprUFH81NuRPd0GX3Zu2Mvk=
|
||||||
|
github.com/andybalholm/cascadia v1.3.2 h1:3Xi6Dw5lHF15JtdcmAHD3i1+T8plmv7BQ/nsViSLyss=
|
||||||
|
github.com/andybalholm/cascadia v1.3.2/go.mod h1:7gtRlve5FxPPgIgX36uWBX58OdBsSS6lUvCFb+h7KvU=
|
||||||
|
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||||
|
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||||
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
||||||
|
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||||
|
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
|
||||||
|
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
|
||||||
|
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||||
|
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||||
|
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
|
||||||
|
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||||
|
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||||
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
|
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||||
|
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||||
|
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||||
|
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
|
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||||
|
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||||
|
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||||
|
golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
|
||||||
|
golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w=
|
||||||
|
golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8=
|
||||||
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
|
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||||
|
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||||
|
golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY=
|
||||||
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
|
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
|
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||||
|
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||||
|
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||||
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
|
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
|
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||||
|
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
|
||||||
|
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
|
||||||
|
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
Reference in New Issue
Block a user