提交 4aea5b06 编写于 作者: H hjdhnx

完善drpy模板的urljoin功能和pd

上级 3b9f6692
此差异已折叠。
// import ch from './cheerio.min.js'; // import ch from './cheerio.min.js';
import Uri from './uri.min.js';
// var URI = require('urijs');
// import 模板 from 'https://gitcode.net/qq_32394351/dr_py/-/raw/master/js/模板.js' // import 模板 from 'https://gitcode.net/qq_32394351/dr_py/-/raw/master/js/模板.js'
// var rule =Object.assign(模板.首图2,{ // var rule = Object.assign(模板.首图2,{
// host: 'https://www.zbkk.net', // host: 'https://www.zbkk.net',
// }); // });
...@@ -114,9 +116,26 @@ function clearItem(k){ ...@@ -114,9 +116,26 @@ function clearItem(k){
* @returns {*} * @returns {*}
*/ */
function urljoin(fromPath, nowPath) { function urljoin(fromPath, nowPath) {
return fromPath + nowPath let new_uri = Uri(nowPath, fromPath);
new_uri = new_uri.toString();
// console.log(new_uri);
// return fromPath + nowPath
return new_uri
} }
/**
* 重写pd方法-增加自动urljoin
* @param html
* @param parse
* @returns {*}
*/
function pd(html,parse){
let ret = pdfh(html,parse);
if(typeof(MY_URL)==='undefined'||!MY_URL){
var MY_URL = '';
}
return urljoin(MY_URL,ret)
}
/*** js自封装的方法 ***/ /*** js自封装的方法 ***/
...@@ -317,8 +336,9 @@ function homeVodParse(homeVodObj){ ...@@ -317,8 +336,9 @@ function homeVodParse(homeVodObj){
return '{}' return '{}'
} }
let d = []; let d = [];
console.log(homeVodObj.homeUrl); MY_URL = homeVodObj.homeUrl;
let html = getHtml(homeVodObj.homeUrl); console.log(MY_URL);
let html = getHtml(MY_URL);
try { try {
console.log('double:'+homeVodObj.double); console.log('double:'+homeVodObj.double);
if(homeVodObj.double){ if(homeVodObj.double){
...@@ -417,9 +437,10 @@ function categoryParse(cateObj) { ...@@ -417,9 +437,10 @@ function categoryParse(cateObj) {
} }
let d = []; let d = [];
let url = cateObj.url.replaceAll('fyclass', cateObj.tid).replaceAll('fypage', cateObj.pg); let url = cateObj.url.replaceAll('fyclass', cateObj.tid).replaceAll('fypage', cateObj.pg);
console.log(url); MY_URL = url;
console.log(MY_URL);
try { try {
let html = getHtml(url); let html = getHtml(MY_URL);
if (html) { if (html) {
let list = pdfa(html, p[0]); let list = pdfa(html, p[0]);
list.forEach(it => { list.forEach(it => {
...@@ -457,15 +478,16 @@ function searchParse(searchObj) { ...@@ -457,15 +478,16 @@ function searchParse(searchObj) {
} }
let d = []; let d = [];
let url = searchObj.searchUrl.replaceAll('**', searchObj.wd).replaceAll('fypage', searchObj.pg); let url = searchObj.searchUrl.replaceAll('**', searchObj.wd).replaceAll('fypage', searchObj.pg);
console.log(url); MY_URL = url;
console.log(MY_URL);
try { try {
let html = getHtml(url); let html = getHtml(MY_URL);
if (html) { if (html) {
if(/系统安全验证|输入验证码/.test(html)){ if(/系统安全验证|输入验证码/.test(html)){
let cookie = verifyCode(url); let cookie = verifyCode(MY_URL);
setItem(RULE_CK,cookie); setItem(RULE_CK,cookie);
// obj.headers['Cookie'] = cookie; // obj.headers['Cookie'] = cookie;
html = getHtml(url); html = getHtml(MY_URL);
} }
if(!html.includes(searchObj.wd)){ if(!html.includes(searchObj.wd)){
console.log('搜索结果源码未包含关键字,疑似搜索失败,正为您打印结果源码'); console.log('搜索结果源码未包含关键字,疑似搜索失败,正为您打印结果源码');
...@@ -521,16 +543,17 @@ function detailParse(detailObj){ ...@@ -521,16 +543,17 @@ function detailParse(detailObj){
let fyclass = detailObj.fyclass; let fyclass = detailObj.fyclass;
let tab_exclude = detailObj.tab_exclude; let tab_exclude = detailObj.tab_exclude;
let html = detailObj.html||''; let html = detailObj.html||'';
console.log(url); MY_URL = url;
console.log(MY_URL);
if(p==='*'){ if(p==='*'){
vod.vod_play_from = '道长在线'; vod.vod_play_from = '道长在线';
vod.vod_remarks = detailUrl; vod.vod_remarks = detailUrl;
vod.vod_actor = '没有二级,只有一级链接直接嗅探播放'; vod.vod_actor = '没有二级,只有一级链接直接嗅探播放';
vod.vod_content = url; vod.vod_content = MY_URL;
vod.vod_play_url = '嗅探播放$' + url; vod.vod_play_url = '嗅探播放$' + MY_URL;
}else if(p&&typeof(p)==='object'){ }else if(p&&typeof(p)==='object'){
if(!html){ if(!html){
html = getHtml(url); html = getHtml(MY_URL);
} }
if(p.title){ if(p.title){
let p1 = p.title.split(';'); let p1 = p.title.split(';');
...@@ -628,9 +651,11 @@ console.log(JSON.stringify(vod)); ...@@ -628,9 +651,11 @@ console.log(JSON.stringify(vod));
* @returns {string} * @returns {string}
*/ */
function playParse(playObj){ function playParse(playObj){
MY_URL = playObj.url;
input = MY_URL;
let common_play = { let common_play = {
parse:1, parse:1,
url:playObj.url url:MY_URL
}; };
let lazy_play; let lazy_play;
if(!rule.play_parse||!rule.lazy){ if(!rule.play_parse||!rule.lazy){
...@@ -756,7 +781,6 @@ function detail(vod_url) { ...@@ -756,7 +781,6 @@ function detail(vod_url) {
* @returns {string} * @returns {string}
*/ */
function play(flag, id, flags) { function play(flag, id, flags) {
id = id.startsWith('http')?id:urljoin(rule.host,id);
let playObj = { let playObj = {
url:id, url:id,
flag:flag, flag:flag,
......
// import URI from './uri.min.js';
// import URI from './uri.min.js';
// var URI = require('./uri.min.js');
// npm install urijs
var URI = require('urijs');
var uri = new URI("/relative/path");
// let c = URI.resolve('http://example.com/one', '/two');
// let d = URI.resolve('http://example.com/one', 'http://www.baidu.com');
// console.log(c);
// console.log(d);
var uri2 = URI("../foobar.html", "http://example.org/hello/world.html");
console.log(uri2.toString())
uri2 = URI('http://www.baidu.com', 'http://example.com/one');
console.log(uri2.toString())
uri2 = URI('', 'http://example.com/one');
console.log(uri2.toString())
function urljoin(fromPath, nowPath) {
let new_uri = URI(nowPath, fromPath);
new_uri = new_uri.toString();
// console.log(new_uri);
// return fromPath + nowPath
return new_uri
}
console.log(urljoin('http://example.com/one','/detail/1.html'));
console.log(urljoin('http://example.com/one/path/','detail/1.html'));
console.log(urljoin('http://example.com/one','http://www.baidu.com'));
console.log(urljoin('https://example.com/one','//path/1.png'));
// make path relative
var relUri = uri.relativeTo("/relative/sub/foo/sub/file"); // returns a new URI instance
// relUri == "../../../path"
// absolute URLs are passed through unchanged
let a = URI("http://example.org/world.html").relativeTo("http://google.com/baz");
console.log(a.toString())
// -> "http://example.org/world.html"
// absolute URLs relative to absolute URLs
// may resolve the protocol
URI("http://example.org/world.html")
.clone()
.authority("")
.relativeTo("http://google.com/baz");
// -> "//google.com/world.html"
// equal URLs are relative by empty string
URI("http://www.example.com:8080/dir/file")
.relativeTo('http://www.example.com:8080/dir/file');
// -> ""
// relative on fragment and query string as well
URI("http://www.example.com:8080/dir/file?foo=bar#abcd")
.relativeTo('http://www.example.com:8080/dir/file');
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册