Skip to content

Instantly share code, notes, and snippets.

@hondajojo
Created March 12, 2017 12:11
Show Gist options
  • Save hondajojo/b68a9fac678b693ab07c61c1e3bfa737 to your computer and use it in GitHub Desktop.
Save hondajojo/b68a9fac678b693ab07c61c1e3bfa737 to your computer and use it in GitHub Desktop.
function doGet(request) {
var mid = request.parameter.mid;
if (mid && !isNaN(mid)){
var referer = "http://space.bilibili.com/" + mid +"/";
var headers =
{
"User-Agent" : "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.59 Safari/537.36",
"Referer": referer,
"X-Requested-With": "XMLHttpRequest",
};
var options =
{
"headers" : headers
};
var formData = {
"mid":mid,
"_":"1487150142286"
};
var options2 = {
'method' : 'post',
'payload' : formData,
'headers': headers,
};
var post_url = "http://space.bilibili.com/ajax/member/GetInfo"
var post_response = UrlFetchApp.fetch(post_url, options2);
var title = JSON.parse(post_response.getContentText())['data']['name'];
Logger.log(title);
var url = "http://space.bilibili.com/ajax/member/getSubmitVideos?mid=" + mid + "&pagesize=30&tid=0&keyword=&page=1&_=1477138903325"
var response = UrlFetchApp.fetch(url, options);
var data = JSON.parse(response.getContentText())['data']['vlist'];
// var title = data[0]['author'];
// Logger.log(title);
var feed = '<?xml version="1.0" encoding="UTF-8"?>'
+'<feed xmlns="http://www.w3.org/2005/Atom">'
+'<title>'
+ title
+ '的bilibili空间'
+'</title>'
+'<link href="'
+ referer
+'" rel="alternate"/>'
+'<id>'
+ referer
+'</id>'
+'<updated>'+(new Date()).toISOString()+'</updated>';
data.forEach(function(e, i) {
var video_url = 'http://www.bilibili.com/video/av' + e.aid;
var video_content = '<a href="' + video_url + '">' + video_url + '<a>';
var img = "<img src=" + e.pic + " />"
var video_html = '<embed height="415" width="544" quality="high" allowfullscreen="true" type="application/x-shockwave-flash" src="//static.hdslb.com/miniloader.swf" flashvars="aid='+ e.aid +'" pluginspage="//www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash"></embed>'
feed += '<entry>'
+'<title>'+e.title+'</title>'
+'<link href="' + video_url + '" rel="alternate"/>'
+'<updated>'+e.created+'</updated>'
+'<summary>'+e.description+'</summary>'
+'<content type="html"><![CDATA['
+e.description + video_content + img
+ video_html
+']]></content>'
+'<author><name>'+e.author+'</name></author>'
+'</entry>'
});
feed += '</feed>'
Logger.log(feed);
return ContentService.createTextOutput(feed)
.setMimeType(ContentService.MimeType.RSS);
}
return HtmlService.createHtmlOutput("<h2>invalid uid</h2>")
}
@delight09
Copy link

这个脚本有些问题:

  1. http://space.bilibili.com/ajax/member/GetInfo API应该是加强保护了,返回GAS 提取后返回undefined
  2. 对于视频标题包含 '&' '<'等,非法字符的直接输出为非法feed
  3. 对于summary标签,同理。

不过没关系,我重写了大部分解决了以上提到的问题。
https://github.com/delight09/gadgets/blob/master/code-snippets/google-apps-script/bilispace2rss.gs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment