-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbunker.go
139 lines (121 loc) · 3.45 KB
/
bunker.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
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)
}
}