-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
65 lines (52 loc) · 1.79 KB
/
main.go
File metadata and controls
65 lines (52 loc) · 1.79 KB
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
package main
import (
"context"
"flag"
"fmt"
"log"
"net/http"
"os"
"google.golang.org/api/option"
"google.golang.org/api/youtube/v3"
)
const CAKO_IO_URL = "https://cako.io/"
var YOUTUBE_DATA_API_KEY string
var ytService *youtube.Service
func main() {
fmt.Printf("\ncako.io cli\n\n")
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Command line interface for crawling "+
"and locally serving pages from cako.io\n\n")
fmt.Fprintf(os.Stderr, "Usage: \n")
flag.PrintDefaults()
}
page := flag.String("page", "all/", "Crawl specified page name only")
outDir := flag.String("outDir", "./saved/", "Output directory to save files")
password := flag.String("password", "", "Password for private site access")
skipExisting := flag.Bool("skipExisting", false, "Skip crawling pages already in output directory")
skipAssets := flag.Bool("skipAssets", false, "Only crawl html files")
checkLinks := flag.Bool("checkLinks", false, "Only check links for reachability (do not archive files).")
ytDataApiKey := flag.String("youtubeDataApiKey", "",
"YouTube Data API key for verifying YouTube video availability.")
serve := flag.Bool("serve", false, "Serve locally saved files")
flag.Parse()
if *serve {
fmt.Printf("serving on http://localhost:8080\n")
http.Handle("/", http.FileServer(http.Dir(*outDir)))
log.Fatal(http.ListenAndServe(":8080", nil))
}
if *ytDataApiKey != "" {
YOUTUBE_DATA_API_KEY = *ytDataApiKey
} else {
YOUTUBE_DATA_API_KEY = os.Getenv("YOUTUBE_DATA_API_KEY")
}
if YOUTUBE_DATA_API_KEY != "" {
s, err := youtube.NewService(context.Background(),
option.WithAPIKey(YOUTUBE_DATA_API_KEY))
if err != nil {
log.Fatalf("Could not create YouTube client: %v", err)
}
ytService = s
}
Crawl(CAKO_IO_URL+*page, *outDir, *password, *skipExisting, *skipAssets, *checkLinks)
}