Compare commits
8 Commits
44ca443a7c
...
v1.0.0
| Author | SHA1 | Date | |
|---|---|---|---|
| 07224f9258 | |||
| ab2133a193 | |||
| c2414cf366 | |||
| 4dd5f5ad77 | |||
| dcbd82ec6a | |||
| 59ef434f5b | |||
| 3bf0dd812f | |||
| 6b415b0ef1 |
15
README.md
15
README.md
@@ -1,18 +1,25 @@
|
|||||||
# scrapychan
|
# scrapychan
|
||||||
|
|
||||||
## Description
|
## Description
|
||||||
Scrapychan is a go rewrite of a original [scraperchan](https://git.protron.dev/Doc/scraperchan) that i wrote in Python. There was no reason to rewrite the original program but atleast it is faster and i learned some go.
|
scrapychan is a go rewrite of a original [scraperchan](https://git.protron.dev/Doc/scraperchan) that i wrote in Python. There was no reason to rewrite the original program but atleast it is faster and i learned some go.
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
### Build from source
|
||||||
|
#### Dependencies
|
||||||
|
You just need to have [go](https://go.dev/doc/install) installed
|
||||||
|
|
||||||
|
#### Build
|
||||||
```
|
```
|
||||||
go install https://git.protron.dev/Doc/scrapychan
|
git clone https://git.protron.dev/Doc/scrapychan
|
||||||
|
cd scrapychan
|
||||||
|
go build
|
||||||
|
go install
|
||||||
```
|
```
|
||||||
|
|
||||||
or use the binary's provided in the [release section](https://git.protron.dev/Doc/Scrapychan/releases)
|
### Prebuild binaries
|
||||||
|
or use the binaries provided in the [release section](https://git.protron.dev/Doc/Scrapychan/releases)
|
||||||
|
|
||||||
## How to use
|
## How to use
|
||||||
|
|
||||||
```
|
```
|
||||||
scrapychan -u=<Thread URL> -o=<Destinationpath of media> -v=<true or false to enable verbose logging>
|
scrapychan -u=<Thread URL> -o=<Destinationpath of media> -v=<true or false to enable verbose logging>
|
||||||
```
|
```
|
||||||
|
|||||||
97
main.go
97
main.go
@@ -10,7 +10,52 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
)
|
)
|
||||||
|
func writeDataToDisk(dest *string, board string, verlog *bool, post map[string]interface{}, cdnresbody []byte) {
|
||||||
|
// Save the mediadata to file
|
||||||
|
err := os.WriteFile(*dest + "/" + board + "-" + strconv.Itoa(int(post["tim"].(float64))) + post["ext"].(string), cdnresbody, 0664 )
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
} else if (*verlog) {
|
||||||
|
log.Println("Successfully wrote image/video data to disk")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func getPostData(post map[string]interface{}, board string, verlog *bool) []byte {
|
||||||
|
// Check if post contains media (Video or Image)
|
||||||
|
if post["ext"] != nil {
|
||||||
|
cdnurlstr := "https://i.4cdn.org/" + board + "/" + strconv.Itoa(int(post["tim"].(float64))) + post["ext"].(string)
|
||||||
|
|
||||||
|
// Requesting the media from CDN
|
||||||
|
cdnres, err := http.Get(cdnurlstr)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if respons was valid
|
||||||
|
if cdnres.StatusCode > 299 {
|
||||||
|
log.Fatalf("Response failed with status code: %d and\n", cdnres.StatusCode)
|
||||||
|
} else if (*verlog) {
|
||||||
|
log.Println("Got image/video " + strconv.Itoa(int(post["tim"].(float64))) + post["ext"].(string) + " data")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read data form respons
|
||||||
|
cdnresbody, err := io.ReadAll(cdnres.Body)
|
||||||
|
cdnres.Body.Close()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
} else if (*verlog) {
|
||||||
|
log.Println("Successfully got data from responds body")
|
||||||
|
}
|
||||||
|
return cdnresbody
|
||||||
|
|
||||||
|
} else if (*verlog) {
|
||||||
|
log.Println("Post " + strconv.Itoa(int(post["no"].(float64))) + " didn't include a image or video")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
func main () {
|
func main () {
|
||||||
// Setting up command flags
|
// Setting up command flags
|
||||||
@@ -67,54 +112,26 @@ func main () {
|
|||||||
} else if (*verlog) {
|
} else if (*verlog) {
|
||||||
log.Println("Unmarsheled API responsebody")
|
log.Println("Unmarsheled API responsebody")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
|
||||||
// Iterating the posts from JSON data
|
// Iterating the posts from JSON data
|
||||||
for _, v := range jdata["posts"].([]interface{}) {
|
for _, v := range jdata["posts"].([]interface{}) {
|
||||||
post := v.(map[string]interface{})
|
post := v.(map[string]interface{})
|
||||||
|
|
||||||
// Check if post contains media (Video or Image)
|
wg.Add(1)
|
||||||
if post["ext"] != nil {
|
|
||||||
|
|
||||||
|
|
||||||
cdnurlstr := "https://i.4cdn.org/" + board + "/" + strconv.Itoa(int(post["tim"].(float64))) + post["ext"].(string)
|
|
||||||
|
|
||||||
// Requesting the media from CDN
|
|
||||||
cdnres, err := http.Get(cdnurlstr)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if respons was valid
|
|
||||||
if res.StatusCode > 299 {
|
|
||||||
log.Fatalf("Response failed with status code: %d and\n", res.StatusCode)
|
|
||||||
} else if (*verlog) {
|
|
||||||
log.Println("Got image/video " + strconv.Itoa(int(post["tim"].(float64))) + post["ext"].(string) + " data")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read data form respons
|
|
||||||
cdnresbody, err := io.ReadAll(cdnres.Body)
|
|
||||||
cdnres.Body.Close()
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
} else if (*verlog) {
|
|
||||||
log.Println("Successfully got data from responds body")
|
|
||||||
}
|
|
||||||
|
|
||||||
|
go func() {
|
||||||
// Save the mediadata to file
|
defer wg.Done()
|
||||||
err = os.WriteFile(*dest + "/" + board + "-" + strconv.Itoa(int(post["tim"].(float64))) + post["ext"].(string), cdnresbody, 0664 )
|
if postdata := getPostData(post, board, verlog); postdata != nil {
|
||||||
if err != nil {
|
writeDataToDisk(dest, board, verlog, post, postdata)
|
||||||
log.Fatal(err)
|
|
||||||
} else if (*verlog) {
|
|
||||||
log.Println("Successfully wrote image/video data to disk")
|
|
||||||
}
|
}
|
||||||
|
}()
|
||||||
} else if (*verlog) {
|
|
||||||
log.Println("Post " + strconv.Itoa(int(post["no"].(float64))) + " didn't include a image or video")
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wg.Wait()
|
||||||
|
|
||||||
log.Println("DONE!!!")
|
log.Println("DONE!!!")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user