Skip to content

Instantly share code, notes, and snippets.

@Answeror
Last active July 14, 2017 11:51
Show Gist options
  • Select an option

  • Save Answeror/34fd6a535090ca85a2fc to your computer and use it in GitHub Desktop.

Select an option

Save Answeror/34fd6a535090ca85a2fc to your computer and use it in GitHub Desktop.
Bangumi私信订阅

Bangumi私信订阅

这个gist由torabot自动抓取并生成Atom feed.

使用方法

注意: 请确保你fork之后的gist是private的. 公开你的cookie是一件危险的事情. 别人可能利用它来滥用你的Bangumi账户! Torabot的作者保证不会使用你的cookie做这个gist功能以外的事情. 如果你不信任torabot, 请忽略这个gist.

Fork这个gist, 修改headers.json里的"please_change_this_value"为你的cookie里的对应值. 如果你使用Chrome, 可以按下CTRL+SHIFT+J, 然后在Resources选项卡中找到Cookies项, 用其中的chii_auth对应的值替换"please_change_this_value"即可.

然后将 http://torabot.com/m/gist/<gist_id> 填入torabot的feed订阅. Bangumi收到私信后一般10分钟内即可收到torabot发来的通知邮件. 其中gist_id是你fork的gist编号, 比如 https://gist.github.com/Answeror/34fd6a535090ca85a2fc 的编号就是 34fd6a535090ca85a2fc

注意你必须使用torabot订阅该feed, 才能保证feed持续更新. 如果你不想使用torabot, 也可以在订阅后使用你喜欢的rss阅读器订阅 http://torabot.com/m/gist/<gist_id>

<?xml version='1.0' encoding='UTF-8'?>
<xsl:stylesheet
version='1.0'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
xmlns:re='http://exslt.org/regular-expressions'
extension-element-prefixes='re'
>
<xsl:output method='xml' encoding='UTF-8'/>
<xsl:template match='/'>
<feed xml:lang='zh-CN' xmlns='http://www.w3.org/2005/Atom'>
<id>bgm.tv/pm</id>
<link rel='alternate' type='text/html' href='http://bgm.tv/pm'/>
<title>bgm.tv/pm</title>
<xsl:apply-templates select='//table[@class="topic_list"]'/>
</feed>
</xsl:template>
<xsl:template match='table'>
<xsl:for-each select='.//tr[td[contains(@class, "pm_")]]'>
<xsl:variable name='date' select='.//small[@class="grey"]'/>
<xsl:variable name='year' select='re:replace($date, "(\d+)-(\d+)-(\d+)", "", "\1")'/>
<xsl:variable name='month' select='re:replace($date, "(\d+)-(\d+)-(\d+)", "", "\2")'/>
<xsl:variable name='day' select='re:replace($date, "(\d+)-(\d+)-(\d+)", "", "\3")'/>
<xsl:variable name='time' select='concat($year, "-", format-number($month, "00"), "-", format-number($day, "00"), "T00:00:00Z")'/>
<xsl:variable name='content' select='.//span[@class="tip"]'/>
<entry>
<id><xsl:value-of select='.//input[@type="checkbox"]/@value'/></id>
<published><xsl:value-of select='$time'/></published>
<updated><xsl:value-of select='$time'/></updated>
<link rel='alternate' type='text/html'>
<xsl:attribute name='href'>
<xsl:value-of select='.//a[1]/@href'/>
</xsl:attribute>
</link>
<title><xsl:value-of select='normalize-space(.//a[1])'/></title>
<summary><xsl:value-of select='$content'/></summary>
<content type='text'><xsl:value-of select='$content'/></content>
<author>
<name><xsl:value-of select='.//a[2]'/></name>
<url><xsl:value-of select='.//a[2]/@href'/></url>
</author>
</entry>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
{
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
"Accept-Encoding": "gzip,deflate,sdch",
"Accept-Language": "en-US,en;q=0.8,zh-CN;q=0.6,zh;q=0.4,zh-TW;q=0.2,ja;q=0.2",
"Cache-Control": "max-age=0",
"Connection": "keep-alive",
"Cookie": "chii_auth=please_change_this_value; chii_cookietime=2592000",
"Host": "bgm.tv",
"Referer": "http://bgm.tv/",
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36"
}
{
"targets": [
{
"name": "request_headers",
"type": "json_file",
"input": {
"name": "headers.json"
}
},
{
"name": "update_cookie",
"type": "request",
"input": {
"request": {
"uri": "http://bgm.tv",
"headers": "{{ target.request_headers }}"
}
}
},
{
"name": "set_cookie",
"type": "set_cookie",
"input": {
"request": {
"uri": "http://bgm.tv/pm",
"headers": "{{ target.request_headers }}"
},
"set_cookie": "{{ target.update_cookie.headers['Set-Cookie'] }}"
}
},
{
"name": "get_html",
"type": "request",
"input": {
"request": "{{ target.set_cookie }}"
}
},
{
"name": "decode",
"type": "base64_decode",
"input": {
"text": "{{ target.get_html.body }}"
}
},
{
"name": "transform",
"type": "xslt",
"options": {
"xslt": "bgm.xslt"
},
"input": {
"text": "{{ target.decode }}",
"type": "html"
}
}
],
"files": [
{
"name": "bgm.xslt",
"path": "../targets/test/bgm.xslt"
},
{
"name": "headers.json",
"path": "./headers.json"
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment