@@ -4,19 +4,25 @@ import (
4
4
"encoding/json"
5
5
"log"
6
6
"net/http"
7
+ "regexp"
7
8
"sort"
8
9
"strings"
9
10
"time"
10
11
11
12
"github.com/mmcdole/gofeed"
12
13
)
13
14
15
+ var (
16
+ magnetExp = regexp .MustCompile (`magnet:[^< ]+` )
17
+ )
18
+
14
19
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"`
20
26
publishedParsed * time.Time
21
27
}
22
28
@@ -107,12 +113,22 @@ func (s *Server) serveRSS(w http.ResponseWriter, r *http.Request) {
107
113
} else {
108
114
// some sites put it under enclosures
109
115
for _ , e := range i .Enclosures {
116
+ if e .Type == "application/x-bittorrent" {
117
+ ritem .Torrent = e .URL
118
+ continue
119
+ }
110
120
if strings .HasPrefix (e .URL , "magnet:" ) {
111
121
ritem .Magnet = e .URL
112
122
}
113
123
}
114
124
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 == "" {
116
132
ritem .Magnet = i .Link
117
133
}
118
134
}
0 commit comments