-
Notifications
You must be signed in to change notification settings - Fork 0
/
gcores.go
83 lines (77 loc) · 1.78 KB
/
gcores.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package main
import (
"encoding/json"
"sort"
"strconv"
"strings"
)
func generateRadios(data [][]byte) []*Radio {
radios := make([]*Radio, len(data))
for i, datum := range data {
var radio Radio
_ = json.Unmarshal(datum, &radio)
radios[i] = &radio
}
sort.Sort(ByPublishAt(radios))
return radios
}
func generateRss(radios []*Radio) *Rss {
rss := defaultRss()
radios = filterChannel(radios)
rss.Channel = generateChannel(radios)
return rss
}
func filterChannel(radios []*Radio) []*Radio {
keywords := []string{"试听", "录音笔"}
filtered := make([]*Radio, 0)
for i := range radios {
radio := radios[i]
title := radio.Title
skip := false
for j := range keywords {
if strings.Contains(title, keywords[j]) {
skip = true
break
}
}
if skip {
continue
}
filtered = append(filtered, radio)
}
return filtered
}
func generateChannel(radios []*Radio) *Channel {
channel := Channel{
Title: "GCores Archive",
Description: "机核网 www.gcores.com (Archive)",
Link: "https://assets.dio.wtf/misc/gcores.xml",
Language: "zh-cn",
Copyright: "www.gcores.com",
Image: &Image{
Url: "http://media.fmit.cn/feed/gadionewlogos.png",
Title: "GCores Archive",
Link: "https://assets.dio.wtf/misc/gcores.xml",
},
}
items := make([]*Item, 0)
for i := range radios {
radio := radios[i]
item := &Item{
Title: radio.Title,
Description: CData{radio.Description},
PubDate: &PubDate{radio.PublishAt},
Enclosure: Enclosure{
Url: radio.Audio,
Type: "audio/mpeg",
Length: strconv.FormatInt(radio.Length, 10),
},
Guid: radio.Audio,
}
item.Itunes(radio.Duration, radio.Thumb)
items = append(items, item)
}
channel.Item = items
channel.Itunes("Games & Hobbies", false)
return &channel
}