This repository has been archived by the owner on Apr 3, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GoZippy.go
133 lines (111 loc) · 2.89 KB
/
GoZippy.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
//Inspired from: https://github.com/scotow/zippyst
package main
import (
"bufio"
"fmt"
"github.com/Arion-Kun/GoLaunch"
"github.com/Arion-Kun/GoZippy/FragmentVariants/Utilities"
"log"
"os"
"sync"
)
func main() {
// 1 is the program just being run without launch args since 1 is the program path + name
if len(os.Args) == 1 {
printHelp()
return
}
initializeStartup()
}
const stringEmpty = ""
var links []string
func getFile(launchArg string) {
markDirty = true
filePointer, err := os.Open(GoLaunch.Get(launchArg)[0])
if err != nil && !Silent {
log.Fatal("Unable to open file: ", err)
}
scanner := bufio.NewScanner(filePointer)
scanner.Split(bufio.ScanLines)
for scanner.Scan() {
links = append(links, scanner.Text())
}
if er := scanner.Err(); er != nil && !Silent {
log.Fatal("Error reading file: ", er)
}
// If the file fails to close log the error.
defer func(filePointer *os.File) {
e := filePointer.Close()
if e != nil && !Silent {
log.Fatal("Error closing file: ", e)
}
}(filePointer)
}
func getLinks(launchArg string) {
markDirty = true
containsValue, value := GoLaunch.TryGetValue(launchArg)
if !containsValue {
if !Silent {
log.Fatalln("ERROR: No value found for the launch argument: " + launchArg)
}
return
}
if value == nil {
if !Silent {
println("No link specified. Please follow -L or --link with a link. (Example: ./GoZippy.exe -L 'https://www3.zippyshare.com/v/CDCi2wVT/file.html' )")
}
}
links = append(links, value...)
}
// InspectLink Inspect Process:
// Validate Link
// Parse Link
// Print Link to Output / stdout
// Download Link
func InspectLink(link string, awaiter *sync.WaitGroup) {
if awaiter != nil {
defer awaiter.Done()
}
if !ValidLink(link) && !Silent {
log.Fatalln("Invalid link: " + link)
return
}
rawWebsitePtr, e1 := GetLinkContent(link)
if LogErrorIfNecessary("Error getting link content:", &e1) {
return
}
made, file := Utilities.TryMakeZippyFile(rawWebsitePtr, _GetIterations)
if !made {
return
}
outputLink := file.GetEncodedLink()
fmt.Println(outputLink)
if awaiter == nil {
TryDownload(outputLink)
}
}
// DownloadBuffer I would rather split the buffers than have a single buffer with input links being overridden with output links.
var DownloadBuffer []string
func InspectLinkAndSort(link string, index int, awaiter *sync.WaitGroup) {
defer awaiter.Done()
if !ValidLink(link) && !Silent {
log.Fatalln("Invalid link" + link)
return
}
rawWebsitePtr, e1 := GetLinkContent(link)
if LogErrorIfNecessary("Error getting link content", &e1) {
return
}
made, file := Utilities.TryMakeZippyFile(rawWebsitePtr, _GetIterations)
if !made {
return
}
DownloadBuffer[index] = file.GetEncodedLink()
}
func LogErrorIfNecessary(errorMessage string, err *error) bool {
if *err != nil && !Silent {
_, _ = fmt.Fprintf(os.Stderr, "%s: %s%s%s\n", errorMessage, red, *err, reset)
return true
}
return false
}