@@ -22,11 +22,11 @@ Currently there are three libgen domains:
22
22
These domains might change in the future
23
23
*/
24
24
25
- type MirrorType int32
25
+ type Site int32
26
26
27
27
const (
28
- LibgenOld MirrorType = 0
29
- LibgenNew MirrorType = 1
28
+ LibgenOld Site = 0
29
+ LibgenNew Site = 1
30
30
)
31
31
32
32
// Note: Applicable only for libgen.is! (We might need to implemented something like this for libgen.li)
@@ -136,8 +136,8 @@ func getBookDataFromDocumentNew(document *goquery.Document) []Book {
136
136
}
137
137
138
138
// Parse HTML and get the data from the table by parsing and iterating through them.
139
- func getBookDataFromDocument (document * goquery.Document , libgenMirrorType MirrorType ) []Book {
140
- switch libgenMirrorType {
139
+ func getBookDataFromDocument (document * goquery.Document , libgenSite Site ) []Book {
140
+ switch libgenSite {
141
141
case LibgenOld :
142
142
return getBookDataFromDocumentOld (document )
143
143
case LibgenNew :
@@ -154,7 +154,7 @@ func getLinkFromDocumentNew(document *goquery.Document) (string, bool) {
154
154
return document .Find ("#main a" ).First ().Attr ("href" )
155
155
}
156
156
157
- func getDirectDownloadLink (link string , libgenType MirrorType ) string {
157
+ func getDirectDownloadLink (link string , libgenType Site ) string {
158
158
log .Println ("Obtaining direct download link" )
159
159
160
160
resp , err := http .Get (link )
@@ -203,11 +203,11 @@ func getDirectDownloadLink(link string, libgenType MirrorType) string {
203
203
return ""
204
204
}
205
205
206
- func SearchBookByTitle (query string , limit int , libgenMirrorType MirrorType ) ([]Book , error ) {
206
+ func SearchBookByTitle (query string , limit int , libgenSite Site ) ([]Book , error ) {
207
207
log .Println ("Searching for:" , query )
208
208
var e error
209
209
var baseUrl string
210
- switch libgenMirrorType {
210
+ switch libgenSite {
211
211
case LibgenOld :
212
212
baseUrl = "https://libgen.is/search.php"
213
213
case LibgenNew :
@@ -237,7 +237,7 @@ func SearchBookByTitle(query string, limit int, libgenMirrorType MirrorType) ([]
237
237
e = err
238
238
}
239
239
240
- books := getBookDataFromDocument (document , libgenMirrorType )
240
+ books := getBookDataFromDocument (document , libgenSite )
241
241
242
242
if len (books ) >= limit {
243
243
books = books [:limit ]
@@ -247,14 +247,14 @@ func SearchBookByTitle(query string, limit int, libgenMirrorType MirrorType) ([]
247
247
}
248
248
249
249
// DownloadSelection Downloads the file to current working directory
250
- func DownloadSelection (selectedBook Book , libgenType MirrorType ) {
250
+ func DownloadSelection (selectedBook Book , libgenType Site ) {
251
251
log .Println ("Initializing download" )
252
252
link := getDirectDownloadLink (selectedBook .Mirrors [0 ], libgenType )
253
253
req , _ := http .NewRequest ("GET" , link , nil )
254
254
resp , error := http .DefaultClient .Do (req )
255
255
256
256
if error != nil {
257
- log .Fatal ("Failed to download! Please try other mirror " )
257
+ log .Fatal ("Failed to download! Please try the other site " )
258
258
}
259
259
260
260
defer resp .Body .Close ()
0 commit comments