use util to generate magnets
Cette révision appartient à :
Parent
04bd6ff4c5
révision
b922938c27
5 fichiers modifiés avec 18 ajouts et 12 suppressions
|
@ -1,5 +1,12 @@
|
|||
package config
|
||||
|
||||
const (
|
||||
Trackers = "&tr=udp://tracker.coppersurfer.tk:6969&tr=udp://zer0day.to:1337/announce&tr=udp://tracker.leechers-paradise.org:6969&tr=udp://explodie.org:6969&tr=udp://tracker.opentrackr.org:1337&tr=udp://tracker.internetwarriors.net:1337/announce&tr=udp://eddie4.nl:6969/announce&tr=http://mgtracker.org:6969/announce&tr=http://tracker.baka-sub.cf/announce"
|
||||
)
|
||||
var Trackers = []string{
|
||||
"udp://tracker.coppersurfer.tk:6969",
|
||||
"udp://zer0day.to:1337/announce",
|
||||
"udp://tracker.leechers-paradise.org:6969",
|
||||
"udp://explodie.org:6969",
|
||||
"udp://tracker.opentrackr.org:1337",
|
||||
"udp://tracker.internetwarriors.net:1337/announce",
|
||||
"udp://eddie4.nl:6969/announce",
|
||||
"http://mgtracker.org:6969/announce",
|
||||
"http://tracker.baka-sub.cf/announce"}
|
||||
|
|
|
@ -73,7 +73,7 @@ type TorrentsJson struct {
|
|||
/* Model Conversion to Json */
|
||||
|
||||
func (t *Torrents) ToJson() TorrentsJson {
|
||||
magnet := "magnet:?xt=urn:btih:" + strings.TrimSpace(t.Hash) + "&dn=" + t.Name + config.Trackers
|
||||
magnet := util.InfoHashToMagnet(strings.TrimSpace(t.Hash), t.Name, config.Trackers...)
|
||||
b := []CommentsJson{}
|
||||
_ = json.Unmarshal([]byte(util.UnZlib(t.Comments)), &b)
|
||||
res := TorrentsJson{
|
||||
|
|
|
@ -3,7 +3,6 @@ package router
|
|||
import (
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/ewhal/nyaa/util"
|
||||
"github.com/ewhal/nyaa/util/metainfo"
|
||||
"github.com/zeebo/bencode"
|
||||
|
@ -98,7 +97,6 @@ func (f *UploadForm) ExtractInfo(r *http.Request) error {
|
|||
if parseErr != nil {
|
||||
return metainfo.ErrInvalidTorrentFile
|
||||
}
|
||||
fmt.Println(magnetUrl)
|
||||
exactTopic := magnetUrl.Query().Get("xt")
|
||||
if !strings.HasPrefix(exactTopic, "urn:btih:") {
|
||||
return metainfo.ErrInvalidTorrentFile
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
package torrentService
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/ewhal/nyaa/config"
|
||||
"github.com/ewhal/nyaa/db"
|
||||
"github.com/ewhal/nyaa/model"
|
||||
"github.com/ewhal/nyaa/config"
|
||||
"github.com/ewhal/nyaa/util"
|
||||
"github.com/jinzhu/gorm"
|
||||
"errors"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
@ -30,7 +32,7 @@ func GetFeeds() []model.Feed {
|
|||
for rows.Next() {
|
||||
item := model.Feed{}
|
||||
rows.Scan(&item.Id, &item.Name, &item.Hash, &item.Timestamp)
|
||||
magnet := "magnet:?xt=urn:btih:" + strings.TrimSpace(item.Hash) + "&dn=" + item.Name + config.Trackers
|
||||
magnet := util.InfoHashToMagnet(strings.TrimSpace(item.Hash), item.Name, config.Trackers...)
|
||||
item.Magnet = magnet
|
||||
// memory hog
|
||||
result = append(result, item)
|
||||
|
|
|
@ -2,17 +2,16 @@ package util
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
// convert a binary infohash to a magnet uri given a display name and tracker urls
|
||||
func InfoHashToMagnet(ih string, name string, trackers ...url.URL) (str string) {
|
||||
func InfoHashToMagnet(ih string, name string, trackers ...string) (str string) {
|
||||
str = fmt.Sprintf("magnet:?xt=urn:btih:%s", ih)
|
||||
if len(name) > 0 {
|
||||
str += fmt.Sprintf("&dn=%s", name)
|
||||
}
|
||||
for idx := range trackers {
|
||||
str += fmt.Sprintf("&tr=%s", trackers[idx].String())
|
||||
str += fmt.Sprintf("&tr=%s", trackers[idx])
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
Référencer dans un nouveau ticket