Skip to content
This repository has been archived by the owner on Oct 18, 2020. It is now read-only.

Commit

Permalink
增加 API Point 选择
Browse files Browse the repository at this point in the history
  • Loading branch information
BFDZ committed Dec 11, 2019
1 parent 347ac63 commit 6bd6fe5
Showing 1 changed file with 174 additions and 134 deletions.
308 changes: 174 additions & 134 deletions static/ptgen.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="PT Gen">
<meta name="author" content="Rhilip">
<meta name="description" content="PT Gen | 电影、动漫、游戏简介生成工具,根据豆瓣、IMDb、Bangumi、Steam、Epic、Indienova链接自动生成简介">
<meta name="keywords" content="电影查询 电影简介生成 电影介绍生成 豆瓣简介 游戏简介生成" />
<meta name="author" content="BFDZ">

<title>PT Gen</title>
<title>PT Gen 简介查询生成工具 | 豆瓣 IMDb Bangumi Steam Epic Indienova</title>

<!-- Bootstrap core CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" integrity="sha256-916EbMg70RQy9LHiGkXzG8hSg9EdNy97GazNG/aiY1w=" crossorigin="anonymous">
Expand Down Expand Up @@ -66,7 +67,7 @@
<div class="form-inline">
<div class="form-group">
<label class="sr-only" for="input_value">Input value</label>
<input type="text" class="form-control" placeholder="名称或豆瓣、IMDb、Bangumi、Steam、Epic、Indienova等资源链接"
<input type="text" class="form-control" placeholder="名称或豆瓣、IMDb、Bangumi、Steam、Epic、Indienova等资源链接"
id="input_value"/>
</div>
<button class="btn btn-success" id="query_btn">查询</button>
Expand All @@ -75,6 +76,12 @@
<input type="checkbox" class="form-control" id="force_douban" checked="checked"/> 通过豆瓣查询
</div>
</div>
<div class="form-inline" id="api_select_div" style="margin-top: 10px; display: none">
<div class="form-group">
<label for="api_select">使用API Point</label>
<select class="form-control" id="api_select"></select>
</div>
</div>
</div>
<hr>
<div id="gen_help" style="display: none"></div>
Expand All @@ -88,51 +95,55 @@
<div id="gen_history">
<h4>更新历史</h4>
<ul class="timeline">
<li>
<a href="#" class="float-right">2019-06-27</a>
<p>增加支持Epic和Indienova简介生成</p>
</li>
<li>
<a href="#" class="float-right">2019-05-15</a>
<p>前端页面和后端API添加豆瓣apikey</p>
</li>
<li>
<a href="#" class="float-right">2019-04-10</a>
<p>1. 增加数据库缓存以及后台自动更新过期信息<br>
2. 上线IMDb格式,如果输入IMDb链接但要输出原格式,请勾选 <kbd>通过豆瓣查询</kbd><br>
3. 增加API请求频率限制,以<code>X-RATELIMIT-*</code>响应头展示。<br>
4. 感谢 <a href="https://www.ourbits.club" target="_blank">OurBits</a> 提供技术以及服务器支持
</p>
</li>
<li>
<a href="#" class="float-right">2019-02-23</a>
<p>修改CDN为jsDelivr</p>
</li>
<li>
<a href="#" class="float-right">2018-6-22</a>
<p>增加前端豆瓣搜索(通过豆瓣API)支持</p>
</li>
<li>
<a href="#" class="float-right">2018-04-17</a>
<p>增加Steam信息生成</p>
</li>
<li>
<a href="#" class="float-right">2018-03-17</a>
<p>上线前端页面</p>
</li>
<li>
<a href="#" class="float-right">2017-10-14</a>
<p>API初版上线,初版支持Douban以及Bangumi简介生成</p>
</li>
<li>
<a href="#timeline_2019_07_09" data-toggle="collapse" class="float-right">2019-07-09</a>
<p id="timeline_2019_07_09" class="collapse in">增加API Point 选择,<b>请注意不同API请求时间或结果可能不同。</b></p>
</li>
<li>
<a href="#timeline_2019_06_27" data-toggle="collapse" class="float-right">2019-06-27</a>
<p id="timeline_2019_06_27" class="collapse">增加 <a href="https://indienova.com/gamedb" target="_blank">indienova GameDB</a><a href="https://www.epicgames.com/" target="_blank">Epic</a> 的整理方法,感谢Issacc和yezi1000。</p>
</li>
<li>
<a href="#timeline_2019_04_10" data-toggle="collapse" class="float-right">2019-04-10</a>
<p id="timeline_2019_04_10" class="collapse">
1. 增加数据库缓存以及后台自动更新过期信息<br>
2. 上线IMDb格式,如果输入IMDb链接但要输出原格式,请勾选 <kbd>通过豆瓣查询</kbd><br>
3. 增加API请求频率限制,以<code>X-RATELIMIT-*</code>响应头展示。<br>
4. 感谢 <a href="https://www.ourbits.club" target="_blank">OurBits</a> 提供技术以及服务器支持
</p>
</li>
<li>
<a href="#timeline_2019_02_23" data-toggle="collapse" class="float-right">2019-02-23</a>
<p id="timeline_2019_02_23" class="collapse">修改CDN为jsDelivr</p>
</li>
<li>
<a href="#timeline_2018_06_22" data-toggle="collapse" class="float-right">2018-06-22</a>
<p id="timeline_2018_06_22" class="collapse">增加前端豆瓣搜索(通过豆瓣API)支持</p>
</li>
<li>
<a href="#timeline_2018_04_17" data-toggle="collapse" class="float-right">2018-04-17</a>
<p id="timeline_2018_04_17" class="collapse">增加Steam信息生成</p>
</li>
<li>
<a href="#timeline_2018_03_17" data-toggle="collapse" class="float-right">2018-03-17</a>
<p id="timeline_2018_03_17" class="collapse">上线前端页面</p>
</li>
<li>
<a href="#timeline_2017_10_14" data-toggle="collapse" class="float-right">2017-10-14</a>
<p id="timeline_2017_10_14" class="collapse">API初版上线,初版支持Douban以及Bangumi简介生成</p>
</li>
</ul>
</div>
</div>
<hr>
<div id="gen_replace">
<h4>相关替代</h4>
此处列出可以替代本平台的用户脚本,以便在 <code>Pt-Gen</code> 失效或返回数据陈旧时使用
<ul style="margin-top: 10px">
<li>豆瓣: <a href="https://greasyfork.org/en/scripts/38878" target="_blank">电影信息查询脚本</a>
<a href="https://greasyfork.org/scripts/329484" target="_blank">豆瓣资源下载大师</a></li>
<li><b><a href="https://ptgen.rhilip.workers.dev/" target="_blank">Rhilip/pt-gen-cfworker</a></b>:构建在Cloudflare Worker上的Pt-Gen分支</li>
<li><b><a href="https://github.com/Rhilip/PT-help" target="_blank">Rhilip/PT-help</a></b> :
<a href="https://api.rhilip.info/ptgen.html" target="_blank">https://api.rhilip.info/ptgen.html</a> ,
Pt-Gen的源项目</li>
<li>豆瓣:<a href="https://greasyfork.org/scripts/329484" target="_blank">豆瓣资源下载大师</a></li>
<li>Bangumi: Bangumi Info Export <a href="https://git.io/fjm3l" target="_blank">脚本</a>
<a href="https://bgm.tv/dev/app/103" target="_blank">应用平台</a></li>
</ul>
Expand All @@ -148,105 +159,134 @@ <h4>相关替代</h4>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js" integrity="sha256-U5ZEeKfGNOja007MMD3YBI0A3OSZOQbeG6z2f2Y0hu8=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/clipboard@2.0.0/dist/clipboard.min.js" integrity="sha256-meF2HJJ2Tcruwz3z4XcxYDRMxKprjdruBHc3InmixCQ=" crossorigin="anonymous"></script>

<script> // 脚本查询相关
function jsonp(url, arg, fn) {
let srpt = document.createElement('script');
let funName = 'fun_' + Math.random().toString().substr(3);
<script> // 页面信息填充
// TODO Version and Version Log
// TODO Sample
</script>

let queryString = '';
for (let key in arg) {
queryString += key + '=' + arg[key] + '&'
<script> // 脚本查询相关
function jsonp(url, arg, fn) {
let srpt = document.createElement('script');
let funName = 'fun_' + Math.random().toString().substr(3);

let queryString = '';
for (let key in arg) {
queryString += key + '=' + arg[key] + '&'
}
url += '?' + queryString + 'callback=' + funName;

window[funName] = fn;
srpt.src = url;
document.body.appendChild(srpt);
}
url += '?' + queryString + 'callback=' + funName;

window[funName] = fn;
srpt.src = url;
document.body.appendChild(srpt);
}

const doubanEntApiKeys = [
"0dad551ec0f84ed02907ff5c42e8ec70",
"02646d3fb69a52ff072d47bf23cef8fd"
];

function getDoubanEntApiKey() { // 随机获取一个key
return doubanEntApiKeys[Math.floor(Math.random() * doubanEntApiKeys.length)];
}

$(function () {
let query_btn = $("#query_btn");
let gen_help = $("#gen_help");
let gen_out = $("#gen_out");
let out_textarea = $("#movie_info");
let input_btn = $("#input_value");

query_btn.disable = function () {
query_btn.attr("disabled", true);
query_btn.html("查询中");
};

query_btn.enable = function () {
query_btn.removeAttr("disabled");
query_btn.html("查询");
};

input_btn.on('input change',function () {
if (input_btn.val().match(/imdb/)) {
$('#force_douban_div').show();
} else {
$('#force_douban_div').hide();
}
});

query_btn.click(function () {
gen_help.hide();
gen_out.show();
let input_value = input_btn.val();
if (input_value.length === 0) {
alert("空字符,请检查输入");
} else if (/^http/.test(input_value)) {
query_btn.disable();

let param = {
url: input_value
};
if (input_value.match(/imdb/) && $('#force_douban').prop('checked')) {
let sid = input_value.match(/tt\d+/)[0];
param = {
site: 'douban',
sid: sid
}
}

$.getJSON("/infogen", param).success(function (data) {
out_textarea.val(data["success"] === false ? data["error"] : data["format"]);
}).fail(function (jqXHR) {
alert(jqXHR.status === 429 ? 'Met Rate Limit, Retry later~' : "Error occured!");
}).complete(function () {
query_btn.enable();

const doubanEntApiKeys = [
"0dad551ec0f84ed02907ff5c42e8ec70",
"02646d3fb69a52ff072d47bf23cef8fd"
];

const apiList = [
"https://api.nas.ink/infogen",
"https://api.douban.workers.dev",
"https://ptgen.rhilip.workers.dev/",
];

function getDoubanEntApiKey() { // 随机获取一个key
return doubanEntApiKeys[Math.floor(Math.random() * doubanEntApiKeys.length)];
}

$(function () {
let query_btn = $("#query_btn");
let gen_help = $("#gen_help");
let gen_out = $("#gen_out");
let out_textarea = $("#movie_info");
let input_btn = $("#input_value");
let api_select = $('#api_select');

// 填充API_list
api_select.html(function () {
let ret = '';
apiList.forEach((x,i) => {
ret += `<option data-apiid=${i}>${x}</option>`;
});
} else { // Search from Douban
gen_help.show();
gen_out.hide();
jsonp("https://api.douban.com/v2/movie/search", {
q: input_value,
apikey: getDoubanEntApiKey()
}, function (resj) {
gen_help.html(resj.subjects.reduce((accumulator, currentValue) => {
return accumulator += `<tr><td>${currentValue.year}</td><td>${currentValue.subtype}</td><td>${currentValue.title}</td><td><a href='${currentValue.alt}' target='_blank'>${currentValue.alt}</a></td><td><a href='javascript:void(0);' class="gen-search-choose" data-url="${currentValue.alt}">选择</a></td></tr>`;
}, "<table id='gen_help_table' class='table table-striped table-hover'><thead><tr><th>年代</th><th>类别</th><th>标题</th><th>豆瓣链接</th><th>行为</th></tr></thead><tbody>"));
$("a.gen-search-choose").click(function () {
let tag = $(this);
input_btn.val(tag.attr("data-url"));
query_btn.click();
return ret;
});

query_btn.disable = function () {
query_btn.attr("disabled", true);
query_btn.html("查询中");
};

query_btn.enable = function () {
query_btn.removeAttr("disabled");
query_btn.html("查询");
};

input_btn.on('input change',function () {
if (input_btn.val().match(/^http/)) {
$('#api_select_div:hidden').show();
}
if (input_btn.val().match(/imdb/)) {
$('#force_douban_div').show();
} else {
$('#force_douban_div').hide();
}
});

query_btn.click(function () {
gen_help.hide();
gen_out.show();
let input_value = input_btn.val();
if (input_value.length === 0) {
alert("空字符,请检查输入");
} else if (/^http/.test(input_value)) {
query_btn.disable();

let param = {
url: input_value
};
if (input_value.match(/imdb/) && $('#force_douban').prop('checked')) {
let sid = input_value.match(/tt\d+/)[0];
param = {
site: 'douban',
sid: sid
}
}

let api_point = api_select.val();
$.getJSON(api_point, param).success(function (data) {
out_textarea.val(data["success"] === false ? data["error"] : data["format"]);
}).fail(function (jqXHR) {
alert(jqXHR.status === 429 ? 'Met Rate Limit, Retry later~' : "Error occured!");
}).complete(function () {
query_btn.enable();
});
});
}
} else { // Search from Douban
gen_help.show();
gen_out.hide();
jsonp("https://api.douban.com/v2/movie/search", {
q: input_value,
apikey: getDoubanEntApiKey()
}, function (resj) {
gen_help.html(resj.subjects.reduce((accumulator, currentValue) => {
return accumulator += `<tr><td>${currentValue.year}</td><td>${currentValue.subtype}</td><td>${currentValue.title}</td><td><a href='${currentValue.alt}' target='_blank'>${currentValue.alt}</a></td><td><a href='javascript:void(0);' class="gen-search-choose" data-url="${currentValue.alt}">选择</a></td></tr>`;
}, "<table id='gen_help_table' class='table table-striped table-hover'><thead><tr><th>年代</th><th>类别</th><th>标题</th><th>豆瓣链接</th><th>行为</th></tr></thead><tbody>"));
$("a.gen-search-choose").click(function () {
let tag = $(this);
input_btn.val(tag.attr("data-url"));
query_btn.click();
});
});
}
});
});
});
</script>
<script> // 页面复制相关
new ClipboardJS('.btn-clipboard');
</script>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script>
!function(a,b,c,d,e){var f=c.screen,g=encodeURIComponent,h=["ga="+a,"dt="+g(d.title),"dr="+g(d.referrer),"ul="+(e.language||e.browserLanguage||e.userLanguage),"sd="+f.colorDepth+"-bit","sr="+f.width+"x"+f.height,"vp="+Math.max(d.documentElement.clientWidth,c.innerWidth||0)+"x"+Math.max(d.documentElement.clientHeight,c.innerHeight||0),"z="+ +new Date];c.__ga_img=new Image,c.__ga_img.src=b+"?"+h.join("&")}("UA-64016301-5","https://ga.giuem.com",window,document,navigator,location);
</script>
</body>
</html>

0 comments on commit 6bd6fe5

Please sign in to comment.