Skip to content

Commit

Permalink
Search actresses by images (#122)
Browse files Browse the repository at this point in the history
* add search actress by image

* update version

* update test case

* fix coverage.yml

* fix test cases

* remove smalltest

* remove smalltest
  • Loading branch information
TheodoreKrypton authored Oct 2, 2020
1 parent 58834e5 commit 647134c
Show file tree
Hide file tree
Showing 18 changed files with 153 additions and 98 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: smalltest
name: coverage

on: [push, pull_request]

Expand Down
10 changes: 0 additions & 10 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,3 @@ jobs:
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Setup Github Registry URL
uses: actions/setup-node@v1
with:
registry-url: 'https://npm.pkg.github.com'

- name: Publish to Github Packages
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
20 changes: 0 additions & 20 deletions .github/workflows/smalltest.yml

This file was deleted.

8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@

## 简介/Introduction

这是一个用来搜索日本 AV 相关信息的 NodeJS App,目前提供一个基于WebSocket的Web客户端页面。
这是一个用来搜索日本 AV 相关信息的 NodeJS app,目前提供一个基于WebSocket的Web客户端页面。

这个App从多个网站爬取信息,但多数目标网站在一些特定地区都被禁止访问。为了更好的使用体验,建议将这个库运行在互联网管制较少的地区,如美国,日本等。
这个app从多个网站爬取信息,但多数目标网站在一些特定地区都被禁止访问。为了更好的使用体验,建议将这个库运行在互联网管制较少的地区,如美国,日本等。


---

This is a NodeJS App for searching Japanese AVs related information. This project temporarily only provides a WebSocket based web page as interface.
This is a NodeJS app for searching Japanese AVs related information. This project temporarily only provides a WebSocket based web page as interface.

This App fetches information from various websites, but most of them are blocked in some regions. To experience a better travel, please host the service in somewhere having lesser Internet restrictions, like the USA, Japan, etc.
This app fetches information from various websites, but most of them are blocked in some regions. To experience a better travel, please host the service in somewhere having lesser Internet restrictions, like the USA, Japan, etc.

## Quick Start

Expand Down
10 changes: 10 additions & 0 deletions bin/javpy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const yargs = require('yargs');
const { exec } = require('child_process');
const os = require('os');
const auth = require('../src/server/authenticate');
const server = require('../src/server');

const { argv } = yargs
Expand All @@ -17,6 +18,11 @@ const { argv } = yargs
default: true,
type: 'bool',
})
.option('public', {
description: 'public mode does not require authentications',
default: false,
type: 'bool',
})
.help()
.alias('help', 'h');

Expand All @@ -32,4 +38,8 @@ const openBrowser = () => {
}
};

if (argv.public === 'true') {
auth.setPublic();
}

server.run(argv.port, argv.browser === 'false' ? undefined : openBrowser);
33 changes: 28 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "javpy",
"version": "0.7.8",
"version": "0.7.9",
"description": "Enjoy driving on a Javascriptive (originally Pythonic) way to Japanese AV!",
"scripts": {
"dev": "node ./bin/javpy.js --browser=false",
"dev": "node ./bin/javpy.js --browser=false --public=true",
"test": "mocha ./test/test.js --timeout 60000",
"coverage": "nyc --reporter=lcov mocha --timeout 60000 && codecov -t ${CODECOV_TOKEN}",
"build": "pkg . --out-path=./build/",
Expand Down Expand Up @@ -36,9 +36,11 @@
"bunyan-sfdx-no-dtrace": "^1.8.2",
"cors": "^2.8.5",
"express": "^4.17.1",
"form-data": "^3.0.0",
"ip-range-check": "^0.2.0",
"js-sha256": "^0.9.0",
"jsdom": "^16.3.0",
"memfs": "^3.2.0",
"unzip-stream": "^0.3.0",
"ws": "^7.3.1",
"yargs": "^16.0.3"
Expand All @@ -50,4 +52,4 @@
"bin": {
"javpy": "./bin/javpy.js"
}
}
}
2 changes: 2 additions & 0 deletions src/functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const { searchMagnet } = require('./searchMagnet');
const { getActressProfile } = require('./getActressProfile');
const { getAliases } = require('./getAliases');
const { getBrief } = require('./getBrief');
const { searchActressByImage } = require('./searchActressByImage');

module.exports = {
searchByActress,
Expand All @@ -14,4 +15,5 @@ module.exports = {
getActressProfile,
getAliases,
getBrief,
searchActressByImage,
};
22 changes: 22 additions & 0 deletions src/functions/searchActressByImage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const sources = require('../sources');
const utils = require('./utils');

const searchActressByImage = async (ws, reqId, { image }) => {
let something = false;
await Promise.allSettled([sources.xslist].map(
(source) => source.searchActressByImage(image).then((response) => {
if (!response) {
return;
}
something = true;
ws.send(JSON.stringify({ response, reqId }));
}),
));
if (!something) {
utils.notFound(ws, reqId);
}
};

module.exports = {
searchActressByImage,
};
8 changes: 7 additions & 1 deletion src/server/authenticate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ const ipRangeCheck = require('ip-range-check');
const sha256 = require('js-sha256');
const config = require('./config');

let publicMode = false;
const setPublic = () => {
publicMode = true;
};

const tokens = new Set();
let hashedPassword = '';
if (config.config['hashed-password']) {
Expand All @@ -15,11 +20,12 @@ const addToken = (token) => {
};
const checkPassword = (password) => hashedPassword === password;
const checkIP = (ip) => ipRangeCheck(ip, config.config['ip-whitelist']);
const checkToken = (token) => tokens.has(token);
const checkToken = (token) => publicMode || tokens.has(token);

module.exports = {
checkPassword,
checkToken,
checkIP,
addToken,
setPublic,
};
5 changes: 4 additions & 1 deletion src/server/wsDispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ const auth = require('./authenticate');
const { logger } = require('./log');

const dispatch = (ws, msg) => {
logger.info({ ws: msg });
if (!msg.message || !msg.message.args || !msg.message.args.image) {
logger.info({ ws: msg });
}

try {
const { message, reqId, userpass } = msg;
Expand All @@ -22,6 +24,7 @@ const dispatch = (ws, msg) => {
get_aliases: functions.getAliases,
get_actress_profile: functions.getActressProfile,
get_brief: functions.getBrief,
search_actress_by_image: functions.searchActressByImage,
};

if (routes[api]) {
Expand Down
2 changes: 2 additions & 0 deletions src/sources/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const javhdporn = require('./javhdporn');
const javbus = require('./javbus');
const javlibrary = require('./javlibrary');
const javdb = require('./javdb');
const xslist = require('./xslist');

module.exports = {
javmost,
Expand All @@ -20,4 +21,5 @@ module.exports = {
javbus,
javlibrary,
javdb,
xslist,
};
2 changes: 0 additions & 2 deletions src/sources/javdoe.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ const requester = utils.requester('https://javdoe.tv');

const searchByCode = async (code) => {
const rsp = await requester.get(encodeURI(`/search.html?q=${code}`));
console.log(rsp.data);
const dom = new JSDOM(rsp.data, { runScripts: 'dangerously' }).window.document;
const player = dom.querySelector('#player');
console.log(player.innerHTML);

};

Expand Down
Empty file removed src/sources/javland.js
Empty file.
18 changes: 4 additions & 14 deletions src/sources/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,8 @@ const axios = require('axios');
const http = require('http');
const https = require('https');
const { default: Axios } = require('axios');
const { JSDOM } = require('jsdom');

let ua = null;

const getUserAgent = async () => {
if (!ua) {
const rsp = await Axios.get('https://user-agents.net/browsers/chromium');
const dom = new JSDOM(rsp.data).window.document;
ua = dom.querySelector('.agents_list').querySelector('li').textContent;
}
return ua;
};
const ua = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/85.0.4183.59 Chrome/85.0.4183.59 Safari/537.36';

module.exports = {
requester: (baseUrl) => {
Expand All @@ -25,15 +15,15 @@ module.exports = {

const makeConfig = (config) => {
if (!config) {
return { headers: { 'User-Agent': getUserAgent() } };
return { headers: { 'User-Agent': ua } };
}

if (!config.headers) {
return { headers: { 'User-Agent': getUserAgent() }, ...config };
return { headers: { 'User-Agent': ua }, ...config };
}

if (!config.headers['User-Agent']) {
return { ...config, headers: { 'User-Agent': getUserAgent(), ...config.headers } };
return { ...config, headers: { 'User-Agent': ua, ...config.headers } };
}
return config;
};
Expand Down
15 changes: 13 additions & 2 deletions src/sources/warashiAsianPornstarsFr.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,19 @@ const getNameInCard = (name, card) => {
return null;
}

if (!card.textContent.toLowerCase().includes(name)) {
return null;
const content = card.textContent.toLowerCase();

if (!content.includes(name)) {
const tokens = name.split(/\s+/);
if (tokens.length === 2) {
const [firstName, lastName] = tokens;
console.log(`${lastName} ${firstName}`);
console.log(content);
console.log(content.includes(`${lastName} ${firstName}`));
if (!content.includes(`${lastName} ${firstName}`)) {
return null;
}
}
}

const title = card.querySelector('p').textContent.toLowerCase();
Expand Down
Loading

0 comments on commit 647134c

Please sign in to comment.