Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit 2661b99

Browse files
committed
rss support application/x-bittorrent feed
1 parent afd6b85 commit 2661b99

File tree

3 files changed

+305
-285
lines changed

3 files changed

+305
-285
lines changed

server/server_rss.go

+22-6
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,25 @@ import (
44
"encoding/json"
55
"log"
66
"net/http"
7+
"regexp"
78
"sort"
89
"strings"
910
"time"
1011

1112
"github.com/mmcdole/gofeed"
1213
)
1314

15+
var (
16+
magnetExp = regexp.MustCompile(`magnet:[^< ]+`)
17+
)
18+
1419
type rssJSONItem struct {
15-
Name string `json:"name,omitempty"`
16-
Magnet string `json:"magnet,omitempty"`
17-
InfoHash string `json:"hashinfo,omitempty"`
18-
Published string `json:"published,omitempty"`
19-
URL string `json:"url,omitempty"`
20+
Name string `json:"name"`
21+
Magnet string `json:"magnet"`
22+
InfoHash string `json:"hashinfo"`
23+
Published string `json:"published"`
24+
URL string `json:"url"`
25+
Torrent string `json:"torrent"`
2026
publishedParsed *time.Time
2127
}
2228

@@ -107,12 +113,22 @@ func (s *Server) serveRSS(w http.ResponseWriter, r *http.Request) {
107113
} else {
108114
// some sites put it under enclosures
109115
for _, e := range i.Enclosures {
116+
if e.Type == "application/x-bittorrent" {
117+
ritem.Torrent = e.URL
118+
continue
119+
}
110120
if strings.HasPrefix(e.URL, "magnet:") {
111121
ritem.Magnet = e.URL
112122
}
113123
}
114124

115-
if ritem.Magnet == "" {
125+
// find magnet in description
126+
if s := magnetExp.FindString(i.Description); s != "" {
127+
ritem.Magnet = s
128+
}
129+
130+
// not found magnet/torrent, fallback to the link (likely not a magnet feed)
131+
if ritem.Magnet == "" && ritem.InfoHash == "" && ritem.Torrent == "" {
116132
ritem.Magnet = i.Link
117133
}
118134
}

0 commit comments

Comments
 (0)