-
Notifications
You must be signed in to change notification settings - Fork 1
/
api.js
130 lines (113 loc) · 4.23 KB
/
api.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
"use strict";
// Get image from xkcn.info
var request = require("request");
var converter = require("jp-conversion");
var _ = require('lodash');
class Api {
constructor() {
this._apiId = 'UrwskPfkqQ0DuVry2gYL';
this._affiliateId = "10278-996";
this._url = `https://api.dmm.com/affiliate/v3/`;
}
findActress(name, offset = 1, resultPerPage = 100) {
var hiraganaName = name ? converter.convert(name.toLowerCase()).hiragana : '';
return new Promise((resolve, reject) => {
request({
url: this._url + 'ActressSearch',
qs: {
api_id: this._apiId,
affiliate_id: this._affiliateId,
output: 'json',
offset: offset,
hits: resultPerPage,
keyword: hiraganaName,
sort: '-birthday'
},
method: "GET",
json: true,
}, (err, response, body) => {
if (err) {
reject(err);
return;
}
if (body.result.result_count == 0) {
body.result.actress = [];
}
var actressesWithImage = body.result.actress.filter(actress => actress.imageURL);
// Get actress with image only
var result = actressesWithImage.map(actress => {
return {
id: actress.id,
name: actress.imageURL.large
.replace('http://pics.dmm.co.jp/mono/actjpgs/', '')
.replace('.jpg', '')
.replace(/[0-9]/g, '')
.split('_')
.map(_.capitalize)
.filter(s => isNaN(s))
.join(' '),
japanName: actress.name,
bust: actress.bust,
waist: actress.waist,
hip: actress.hip,
height: actress.height,
birthday: actress.birthday,
imageUrl: actress.imageURL.large.replace('http', 'https'),
siteUrl: actress.listURL.digital
}
});
resolve({
count: body.result.result_count,
total: body.result.total_count,
result: result
});
})
});
}
findVideos(actressId, offset = 1, resultPerPage = 100) {
return new Promise((resolve, reject) => {
request({
url: this._url + 'ItemList',
qs: {
api_id: this._apiId,
affiliate_id: this._affiliateId,
site: 'DMM.R18',
output: 'json',
service: 'digital',
floor: 'videoa',
article: 'actress',
article_id: actressId,
offset: offset,
hits: resultPerPage
},
method: "GET",
json: true,
}, (err, response, body) => {
if (err) {
reject(err);
return;
}
if (body.result.result_count == 0) {
body.result.items = [];
}
var result = body.result.items.map(item => {
return {
name: item.title,
siteUrl: item.URL,
imageUrl: item.imageURL.small.replace('http', 'https'),
date: item.date,
maker: item.iteminfo.maker,
review: item.review,
actress: item.iteminfo.actress
};
});
resolve({
count: body.result.result_count,
total: body.result.total_count,
result: result
});
})
});
}
}
module.exports = new Api();