-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
196 lines (173 loc) · 6.24 KB
/
index.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
const { proxy, config } = require('internal')
const ent = require('ent')
const namedQueue = require('named-queue')
const ytdl = require('youtube-dl')
const needle = require('needle')
const defaults = {
name: 'YouPorn',
prefix: 'myouporn_',
host: 'youporn',
icon: 'https://blog.youporn.com/wp-content/uploads/2012/02/youporn-logo.png'
}
var url = {
catalog: page => {
return 'http://www.metaporn.com/tube/' + defaults.host + '/' + (page || 1)
},
search: (query, start, limit) => {
return 'https://www.pornmd.com/straight/' + encodeURIComponent(query) + '?source=' + defaults.host + '&start=' + (start || 0) + '&ajax=true&limit=' + (limit || 24) + '&format=json'
}
}
function pornMetaObj(el, url, oldId) {
let img = el.thumb || el.thumbnail
if (img)
img = proxy.addProxy(img, { headers: { referer: img } })
return {
backgroundShape: 'contain',
id: oldId || (defaults.prefix + '_' + (url || el.url).replace(':', '|')),
name: ent.decode(el.fulltitle || el.title || ' '),
poster: img,
posterShape: 'landscape',
background: img,
genre: [ 'Porn' ],
isFree: 1,
type: 'tv'
}
}
function normalizeTime(duration) {
if (parseInt(duration).toString() == duration) {
return parseInt(duration)
} else {
let timeParts = duration.trim().split(' ').reverse()
let total = parseInt(timeParts[0])
timeParts.shift()
let amplifier = 60
timeParts.forEach(el => {
total += parseInt(el) * amplifier
amplifier *= amplifier
})
return total
}
}
function normalizeResults(proxy, res) {
return res.map(el => {
let img
if (el.thumb)
img = (el.thumb.startsWith('\/\/') ? 'http:' : '') + el.thumb
return {
id: el.id || el.video_id,
title: el.title,
type: 'tv',
thumb: img || null,
duration: normalizeTime(el.duration),
url: (el.url ? 'http://www.metaporn.com' + el.url : 'https://www.pornmd.com' + el.link).split('\/').join('/'),
tags: []
}
// (el.related || el.keywords).forEach(tag => { newRes[newRes.length -1].tags.push(tag.name) })
})
}
const videoQueue = new namedQueue((task, cb) => {
var video = ytdl(task.id, ['-j'])
video.on('error', err => {
cb(err || new Error(defaults.name + ' - Youtube-dl Error: Could Not Parse'))
})
video.on('info', info => {
if (info.url || info.formats)
cb(null, info)
else
cb(new Error('Youtube-dl Error: No URL in Response'))
})
}, Infinity)
function IsJsonString(str) { try { str = JSON.parse(str) } catch (e) { return false }; return str }
const { addonBuilder, getInterface, getRouter } = require('stremio-addon-sdk')
const builder = new addonBuilder({
id: 'org.' + defaults.name.toLowerCase().replace(/[^a-z]+/g,''),
version: '1.0.0',
name: defaults.name,
description: 'Porn videos from ' + defaults.name,
resources: ['meta', 'stream', 'catalog'],
types: ['porn', 'tv'],
idPrefixes: [defaults.prefix],
icon: defaults.icon,
catalogs: [
{
id: defaults.prefix + 'catalog',
type: 'porn',
name: defaults.name,
extra: [{ name: 'search' }, { name: 'skip' }]
}
]
})
builder.defineCatalogHandler(args => {
return new Promise((resolve, reject) => {
const extra = args.extra || {}
if (extra && extra.search) {
const limit = 24
needle.get(url.search(extra.search, 0, limit), (err, resp, res) => {
if (res && res.videos && res.videos.length)
resolve({ metas: normalizeResults(proxy, res.videos).map(el => pornMetaObj(el)) })
else reject(defaults.name + ' - No Response Body 2')
})
} else {
const skip = parseInt(extra.skip || 0)
const limit = 96
const page = skip / limit + 1
needle.get(url.catalog(page), { follow_max: 5 }, (err, resp, res) => {
res = IsJsonString(res)
if (res && res.videos && res.videos.length) {
console.log(res.videos)
resolve({ metas: normalizeResults(proxy, res.videos).map(el => pornMetaObj(el)) })
} else reject(defaults.name + ' - No Response Body 1')
})
}
})
})
builder.defineMetaHandler(args => {
return new Promise((resolve, reject) => {
var metaUrl = args.id.replace(defaults.prefix + '_', '').replace('|', ':')
videoQueue.push({ id: metaUrl }, (err, resp) => {
if (!err && resp)
resolve({ meta: pornMetaObj(resp, null, args.id) })
else
reject(defaults.name + ' - Could not get Youtube-dl Meta')
})
})
})
builder.defineStreamHandler(args => {
return new Promise((resolve, reject) => {
var metaUrl = args.id.replace(defaults.prefix + '_', '').replace('|', ':')
videoQueue.push({ id: metaUrl }, (err, resp) => {
if (!err && resp) {
let streams
if (resp.formats) {
streams = resp.formats.map(el => {
return {
availability: 1,
url: el.url,
title: el.format_id ? el.format_id : el.height ? (el.height + 'p') : '360p',
tag: [(el.ext || 'mp4')],
isFree: 1,
id: args.id
}
})
} else {
var el = resp
streams = [{
availability: 1,
url: el.url,
title: el.format_id && isNaN(el.format_id) ? el.format_id : el.height ? (el.height + 'p') : '360p',
tag: [(el.ext || 'mp4')],
isFree: 1,
id: args.id
}]
}
if (streams && streams.length)
resolve({ streams })
else
reject(defaults.name + ' - No stream results from Youtube-dl')
} else
reject(defaults.name + ' - Could not get Youtube-dl Meta')
})
})
})
const addonInterface = getInterface(builder)
module.exports = getRouter(addonInterface)