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