-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslideshare.go
61 lines (52 loc) · 1.12 KB
/
slideshare.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
package main
import (
"bytes"
"flag"
"fmt"
"io"
"os"
"github.com/mohan3d/slideshare-go/slideshare"
)
func selectQuality(q string) slideshare.Quality {
// defaults to high quality
quality := slideshare.QualityFull
switch q {
case "normal":
quality = slideshare.QualityNormal
case "low":
quality = slideshare.QualitySmall
}
return quality
}
func download(url, quality, path string) {
var buf bytes.Buffer
err := slideshare.DefaultSlideshareDownloader.Download(
url,
selectQuality(quality),
&buf,
)
if err != nil {
panic(err)
}
output, err := os.Create(path)
if err != nil {
panic(err)
}
defer output.Close()
_, err = io.Copy(output, &buf)
if err != nil {
panic(err)
}
}
func main() {
url := flag.String("url", "", "slideshare url to be downloaded")
path := flag.String("path", "", "path to save the pdf")
quality := flag.String("quality", "high", "quality of pdf it should be \"high\", \"normal\" or \"low\"")
flag.Parse()
if !(*url != "" && *path != "") {
fmt.Println("A valid slideshare url and save path must be provided")
flag.Usage()
os.Exit(1)
}
download(*url, *quality, *path)
}