-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
181 additions
and
12 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,36 @@ | ||
package providers | ||
|
||
import ( | ||
"fapesnap/internal/downloader" | ||
"fapesnap/pkg/providers/bunkr" | ||
"log" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
func InitBunkrCmd() *cobra.Command { | ||
bunkrCmd := &cobra.Command{ | ||
Use: "bunkr", | ||
Short: "Download photos from bunkr", | ||
Run: func(cmd *cobra.Command, _ []string) { | ||
album, _ := cmd.Flags().GetString("album") | ||
|
||
bunkrProvider := bunkr.Provider{Album: album} | ||
bunkrProvider.InitProvider() | ||
|
||
downloader := downloader.Downloader{PhotosProvider: &bunkrProvider} | ||
err := downloader.DownloadPhotos() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
}, | ||
} | ||
|
||
bunkrCmd.Flags().StringP("album", "a", "", "Bunkr album ID") | ||
|
||
if err := bunkrCmd.MarkFlagRequired("album"); err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
return bunkrCmd | ||
} |
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,128 @@ | ||
package bunkr | ||
|
||
import ( | ||
"fmt" | ||
"net/url" | ||
"strings" | ||
|
||
"github.com/gocolly/colly" | ||
) | ||
|
||
type Provider struct { | ||
Album string | ||
ProviderName string | ||
BaseURL string | ||
} | ||
|
||
func (p *Provider) InitProvider() { | ||
p.ProviderName = "bunkr" | ||
p.BaseURL = "https://bunkr.si" | ||
} | ||
|
||
func (p *Provider) GetProviderName() string { | ||
return p.ProviderName | ||
} | ||
|
||
func (p *Provider) GetCollectionName() string { | ||
return p.Album | ||
} | ||
|
||
func (p *Provider) GetPhotoURL(photoID string) (string, error) { | ||
photoPageURL, err := url.JoinPath(p.BaseURL, "i", photoID) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
c := colly.NewCollector() | ||
|
||
photoURL := "" | ||
|
||
c.OnHTML(".lightgallery img", func(e *colly.HTMLElement) { | ||
if src := e.Attr("src"); src != "" { | ||
photoURL = src | ||
} | ||
}) | ||
|
||
c.Visit(photoPageURL) | ||
|
||
if photoURL == "" { | ||
return "", fmt.Errorf("photo not found") | ||
} | ||
|
||
return photoURL, nil | ||
} | ||
|
||
func (p *Provider) GetFileName(src string) string { | ||
parts := strings.Split(src, "/") | ||
|
||
return parts[len(parts)-1] | ||
} | ||
|
||
func (p *Provider) GetPhotos() ([]string, error) { | ||
albumURL, err := url.JoinPath(p.BaseURL, "a", p.Album) | ||
if err != nil { | ||
return []string{}, err | ||
} | ||
|
||
_, err = p.GetRecentPhotoID() | ||
if err != nil { | ||
return []string{}, err | ||
} | ||
|
||
photos := make([]string, 0) | ||
|
||
c := colly.NewCollector() | ||
|
||
c.OnHTML(".grid-images_box-link", func(e *colly.HTMLElement) { | ||
photos = append(photos, getPhotoID(e.Attr("href"))) | ||
}) | ||
|
||
c.Visit(albumURL) | ||
|
||
if len(photos) == 0 { | ||
return []string{}, fmt.Errorf("photos not found") | ||
} | ||
|
||
return photos, nil | ||
} | ||
|
||
func (p *Provider) GetRecentPhotoID() (string, error) { | ||
c := colly.NewCollector() | ||
|
||
albumURL, err := url.JoinPath(p.BaseURL, "a", p.Album) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
recentPhotoID := "" | ||
isFound := false | ||
|
||
c.OnHTML(".grid-images_box-link", func(e *colly.HTMLElement) { | ||
if !isFound { | ||
href := e.Attr("href") | ||
recentPhotoID = getPhotoID(href) | ||
} | ||
}) | ||
|
||
c.Visit(albumURL) | ||
|
||
if recentPhotoID == "" { | ||
return "", fmt.Errorf("album not found") | ||
} | ||
|
||
return recentPhotoID, nil | ||
} | ||
|
||
func getPhotoID(src string) string { | ||
u, err := url.Parse(src) | ||
if err != nil { | ||
return "" | ||
} | ||
|
||
pathParts := strings.Split(u.Path, "/") | ||
|
||
id := pathParts[len(pathParts)-1] | ||
|
||
return id | ||
|
||
} |
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