-
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
10 changed files
with
263 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
package main | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"io" | ||
"net/http" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/anaskhan96/soup" | ||
) | ||
|
||
type BunkrAlbum struct { | ||
AlbumName string | ||
AlbumURL string | ||
ImageUrls []string | ||
VideoUrls []string | ||
} | ||
|
||
// Read the "bunkrlinks.txt" file and return the links | ||
func ReadBunkrDownloadFile(fpath string) []string { | ||
// Open the file | ||
file, err := os.Open(fpath) | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer file.Close() | ||
|
||
// Read the file | ||
links := []string{} | ||
scanner := bufio.NewScanner(file) | ||
for scanner.Scan() { | ||
links = append(links, scanner.Text()) | ||
} | ||
return links | ||
} | ||
|
||
// Get all images and videos from a Bunkr album | ||
// albumUrl: The URL of the album | ||
func GetBunkrAlbum(albumUrl string) BunkrAlbum { | ||
// Make a GET request to the main page url | ||
resp, err := http.Get(albumUrl) | ||
|
||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
defer resp.Body.Close() | ||
|
||
currentAlbum := BunkrAlbum{ | ||
AlbumURL: albumUrl, | ||
} | ||
|
||
// Read the response body | ||
body, err := io.ReadAll(resp.Body) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
// Get all links from the page | ||
medialinks := []string{} | ||
doc := soup.HTMLParse(string(body)) | ||
links := doc.FindAll("a") | ||
for _, link := range links { | ||
// Save link if it contains a type of "https://bunkrrr.org/v" or "https://bunkrrr.org/i" | ||
if strings.Contains(link.Attrs()["href"], "https://bunkrrr.org/v") || | ||
strings.Contains(link.Attrs()["href"], "https://bunkrrr.org/i") { | ||
medialinks = append(medialinks, link.Attrs()["href"]) | ||
} | ||
} | ||
|
||
for _, link := range medialinks { | ||
println("Found link ", link) | ||
} | ||
|
||
// Every of the links link to a page with the download link | ||
for _, link := range medialinks { | ||
resp, err := http.Get(link) | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer resp.Body.Close() | ||
body, err := io.ReadAll(resp.Body) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
// Get all video html tags | ||
doc := soup.HTMLParse(string(body)) | ||
videos := doc.FindAll("video") | ||
for _, video := range videos { | ||
source := video.Find("source") | ||
videourl := source.Attrs()["src"] | ||
videotype := source.Attrs()["type"] | ||
println("Adding video of type ", videotype, " with url ", videourl) | ||
currentAlbum.VideoUrls = append(currentAlbum.VideoUrls, videourl) | ||
} | ||
|
||
// Find all image html tags with link of "*.bunkr.ru" | ||
images := doc.FindAll("img") | ||
for _, image := range images { | ||
imageurl := image.Attrs()["src"] | ||
if strings.Contains(imageurl, ".bunkr.ru") { | ||
println("Adding image with url ", imageurl) | ||
currentAlbum.ImageUrls = append(currentAlbum.ImageUrls, imageurl) | ||
} | ||
} | ||
|
||
} | ||
return currentAlbum | ||
} | ||
|
||
// Download a file from a URL and save it to a path | ||
// album: The album to download | ||
// path: The parent directory to save the album | ||
func DownloadBunkrAlbum(album BunkrAlbum, path string) { | ||
println("Downloading album ", album.AlbumURL) | ||
path = filepath.Join(path, strings.Split(album.AlbumURL, "/")[4]) | ||
// Create the directory for the album | ||
os.MkdirAll(path, os.ModePerm) | ||
|
||
downloadpath := "" // Temporary variable to store the download path | ||
for i, image := range album.ImageUrls { | ||
downloadpath = filepath.Join(path, fmt.Sprintf("%d.jpg", i)) | ||
println("Downloading image ", image) | ||
downloadFile(image, downloadpath) | ||
} | ||
for i, video := range album.VideoUrls { | ||
// Get the format of the video | ||
// The format is the last part of the URL | ||
// Example: https://bunkrrr.org/v/1234.mp4 | ||
format := strings.Split(video, ".") | ||
downloadpath = filepath.Join(path, fmt.Sprintf("%d.%s", i, format[len(format)-1])) | ||
println("Downloading video ", video) | ||
downloadFile(video, downloadpath) | ||
} | ||
} |
Empty file.
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,2 @@ | ||
https://bunkr.si/a/Yyi82pb0 | ||
https://bunkr.fi/a/kNfpAHc9 |
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
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 |
---|---|---|
@@ -1,7 +1,21 @@ | ||
github.com/anaskhan96/soup v1.2.5 h1:V/FHiusdTrPrdF4iA1YkVxsOpdNcgvqT1hG+YtcZ5hM= | ||
github.com/anaskhan96/soup v1.2.5/go.mod h1:6YnEp9A2yywlYdM4EgDz9NEHclocMepEtku7wg6Cq3s= | ||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/phpdave11/gofpdi v1.0.14-0.20211212211723-1f10f9844311 h1:zyWXQ6vu27ETMpYsEMAsisQ+GqJ4e1TPvSNfdOPF0no= | ||
github.com/phpdave11/gofpdi v1.0.14-0.20211212211723-1f10f9844311/go.mod h1:vBmVV0Do6hSBHC8uKUQ71JGW+ZGQq74llk/7bXwjDoI= | ||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= | ||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= | ||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= | ||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
github.com/signintech/gopdf v0.27.0 h1:GEpWcZ2Gdk74+eHYINXWjs51j10r63/HxIFL9X5S7r0= | ||
github.com/signintech/gopdf v0.27.0/go.mod h1:d23eO35GpEliSrF22eJ4bsM3wVeQJTjXTHq5x5qGKjA= | ||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= | ||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= | ||
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa h1:F+8P+gmewFQYRk6JoLQLwjBCTu3mcIURZfNkVweuRKA= | ||
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= | ||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | ||
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= | ||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
Empty file.
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
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