feat: 脚本parseRss改为实际解析RSS XML,返回items列表
This commit is contained in:
@@ -157,10 +157,39 @@ private Map parseDownloadPage(context) {
|
||||
|
||||
// ==================== RSS ====================
|
||||
|
||||
/** RSS 页面解析:默认不做 XML 解析,由 Java 层 parseRssXml 处理。
|
||||
* 站点如需要自定义 RSS 解析,可覆盖此方法返回 items 列表。 */
|
||||
/** RSS 页面解析:解析 NexusPHP 标准 RSS XML,返回 items 列表 */
|
||||
private Map parseRssPage(context) {
|
||||
return [pageName: 'RSS', matched: true, message: 'RSS 内容由 Java 层解析']
|
||||
def xml = context.content
|
||||
if (!xml) return [pageName: 'RSS', matched: false, message: '无内容']
|
||||
|
||||
// 解析 RSS XML
|
||||
def rss = new XmlSlurper().parseText(xml)
|
||||
def items = []
|
||||
rss.channel.item.each { item ->
|
||||
// 下载链接优先从 enclosure url 获取
|
||||
def dlUrl = ''
|
||||
def size = 0
|
||||
def enclosure = item.enclosure
|
||||
if (enclosure && enclosure.@url) {
|
||||
dlUrl = enclosure.@url.text()
|
||||
try { size = enclosure.@length.toLong() } catch (e) {}
|
||||
}
|
||||
if (!dlUrl) dlUrl = item.link.text()
|
||||
|
||||
def title = item.title.text()
|
||||
|
||||
items << [
|
||||
title: title,
|
||||
detailUrl: item.link.text(),
|
||||
downloadUrl: dlUrl,
|
||||
torrentUrl: dlUrl,
|
||||
size: size,
|
||||
publishDate: item.pubDate.text(),
|
||||
category: item.category.text(),
|
||||
author: item.author.text(),
|
||||
]
|
||||
}
|
||||
return [pageName: 'RSS', matched: !items.isEmpty(), items: items]
|
||||
}
|
||||
|
||||
// ==================== 工具方法 ====================
|
||||
|
||||
Reference in New Issue
Block a user