Fix inability to crawl TPB; TLDR TPB has idiotic devs

master
Urban Guacamole 2 years ago
parent 0bbf642143
commit bf19077ad9

@ -5,6 +5,7 @@ import (
"io/ioutil" "io/ioutil"
"log" "log"
"net/http" "net/http"
"strconv"
) )
func CrawlTPB48hTop() []Torrent { func CrawlTPB48hTop() []Torrent {
@ -32,11 +33,24 @@ func parseApibayJSON(url string) []Torrent {
var resp []ApibayTorrent var resp []ApibayTorrent
err = json.Unmarshal(body, &resp) err = json.Unmarshal(body, &resp)
if err != nil {
var respFromIdiots []ApibayTorrentTheyAreIdiots
err = json.Unmarshal(body, &respFromIdiots)
if err != nil { if err != nil {
log.Println(err) log.Println(err)
return nil return nil
} }
for _, torrByIdiot := range respFromIdiots {
var transl ApibayTorrent
transl.Info_hash = torrByIdiot.Info_hash
transl.Name = torrByIdiot.Name
transl.Size, err = strconv.Atoi(torrByIdiot.Size)
transl.Added, err = strconv.Atoi(torrByIdiot.Added)
resp = append(resp, transl)
}
}
var torrents []Torrent var torrents []Torrent
for _, apibayTorr := range resp { for _, apibayTorr := range resp {
torrents = append(torrents, Torrent{apibayTorr.Info_hash, apibayTorr.Name, apibayTorr.Size}) torrents = append(torrents, Torrent{apibayTorr.Info_hash, apibayTorr.Name, apibayTorr.Size})
@ -46,9 +60,15 @@ func parseApibayJSON(url string) []Torrent {
// ApibayTorrent Structure returned from apibay. For unmarshaling from JSON. Not all fields that are returned from Apibay are in this struct; YAGNI // ApibayTorrent Structure returned from apibay. For unmarshaling from JSON. Not all fields that are returned from Apibay are in this struct; YAGNI
type ApibayTorrent struct { type ApibayTorrent struct {
ID int
Info_hash string Info_hash string
Name string Name string
Size int Size int
Added int Added int
} }
type ApibayTorrentTheyAreIdiots struct {
Info_hash string
Name string
Size string
Added string
}

Loading…
Cancel
Save