Add /feed/magnet which displays the magnet instead of the torrent link (#1069)
* Add /feed/magnet which displays the magnet instead of the torrent link
Cette révision appartient à :
Parent
d4b36e2489
révision
b59b5c092b
3 fichiers modifiés avec 62 ajouts et 7 suppressions
|
@ -57,6 +57,8 @@ func init() {
|
|||
Router.HandleFunc("/activities", ActivityListHandler).Name("activity_list")
|
||||
Router.HandleFunc("/feed", RSSHandler).Name("feed")
|
||||
Router.HandleFunc("/feed/{page:[0-9]+}", RSSHandler).Name("feed_page")
|
||||
Router.HandleFunc("/feed/magnet", RSSMagnetHandler).Name("feed_magnet")
|
||||
Router.HandleFunc("/feed/magnet/{page:[0-9]+}", RSSMagnetHandler).Name("feed_magnet_page")
|
||||
Router.HandleFunc("/feed/torznab", RSSTorznabHandler).Name("feed_torznab")
|
||||
Router.HandleFunc("/feed/torznab/api", RSSTorznabHandler).Name("feed_torznab")
|
||||
Router.HandleFunc("/feed/torznab/{page:[0-9]+}", RSSTorznabHandler).Name("feed_torznab_page")
|
||||
|
|
|
@ -68,6 +68,53 @@ func RSSHandler(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
|
||||
// RSSMagnetHandler : Controller for displaying rss feeds with magnet URL, accepting common search arguments
|
||||
func RSSMagnetHandler(w http.ResponseWriter, r *http.Request) {
|
||||
defer r.Body.Close()
|
||||
|
||||
// We only get the basic variable for rss based on search param
|
||||
torrents, createdAsTime, title, err := getTorrentList(r)
|
||||
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
feed := &nyaafeeds.RssFeed{
|
||||
Title: title,
|
||||
Link: config.WebAddress() + "/",
|
||||
PubDate: createdAsTime.String(),
|
||||
}
|
||||
feed.Items = make([]*nyaafeeds.RssItem, len(torrents))
|
||||
|
||||
for i, torrent := range torrents {
|
||||
torrentJSON := torrent.ToJSON()
|
||||
feed.Items[i] = &nyaafeeds.RssItem{
|
||||
Title: torrentJSON.Name,
|
||||
MagnetLink: &nyaafeeds.RssMagnetLink{Text: string(torrentJSON.Magnet)},
|
||||
Description: string(torrentJSON.Description),
|
||||
PubDate: torrent.Date.Format(time.RFC822),
|
||||
GUID: config.WebAddress() + "/view/" + strconv.FormatUint(uint64(torrentJSON.ID), 10),
|
||||
Enclosure: &nyaafeeds.RssEnclosure{
|
||||
URL: config.WebAddress() + "/download/" + strings.TrimSpace(torrentJSON.Hash),
|
||||
Length: strconv.FormatUint(uint64(torrentJSON.Filesize), 10),
|
||||
Type: "application/x-bittorrent",
|
||||
},
|
||||
}
|
||||
}
|
||||
// allow cross domain AJAX requests
|
||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
rss, rssErr := feeds.ToXML(feed)
|
||||
if rssErr != nil {
|
||||
http.Error(w, rssErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
_, writeErr := w.Write([]byte(rss))
|
||||
if writeErr != nil {
|
||||
http.Error(w, writeErr.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
// RSSEztvHandler : Controller for displaying rss feed, accepting common search arguments
|
||||
func RSSEztvHandler(w http.ResponseWriter, r *http.Request) {
|
||||
defer r.Body.Close()
|
||||
|
|
|
@ -40,6 +40,11 @@ type RssTextInput struct {
|
|||
Link string `xml:"link"`
|
||||
}
|
||||
|
||||
type RssMagnetLink struct {
|
||||
XMLName xml.Name `xml:"link"`
|
||||
Text string `xml:",cdata"`
|
||||
}
|
||||
|
||||
type RssFeed struct {
|
||||
XMLName xml.Name `xml:"channel"`
|
||||
Xmlns string `xml:"-"`
|
||||
|
@ -66,13 +71,14 @@ type RssFeed struct {
|
|||
}
|
||||
|
||||
type RssItem struct {
|
||||
XMLName xml.Name `xml:"item"`
|
||||
Title string `xml:"title"` // required
|
||||
Link string `xml:"link"` // required
|
||||
Description string `xml:"description"` // required
|
||||
Author string `xml:"author,omitempty"`
|
||||
Category *RssCategory `xml:"category,omitempty"`
|
||||
Comments string `xml:"comments,omitempty"`
|
||||
XMLName xml.Name `xml:"item"`
|
||||
Title string `xml:"title"` // required
|
||||
Link string `xml:"link,omitempty"`
|
||||
MagnetLink *RssMagnetLink `xml:"link,omitempty"`
|
||||
Description string `xml:"description"` // required
|
||||
Author string `xml:"author,omitempty"`
|
||||
Category *RssCategory `xml:"category,omitempty"`
|
||||
Comments string `xml:"comments,omitempty"`
|
||||
Enclosure *RssEnclosure
|
||||
GUID string `xml:"guid,omitempty"` // Id used
|
||||
PubDate string `xml:"pubDate,omitempty"` // created or updated
|
||||
|
|
Référencer dans un nouveau ticket