UNPKG

stremio-addon-client

Version:

Client library for using stremio addons (v3 protocol)

58 lines (50 loc) 1.6 kB
#!/usr/bin/env node const detectFromURL = require('stremio-addon-client').detectFromURL // export GOOGLE_APPLICATION_CREDENTIALS="/home/ivo/Downloads/API Project-03680ff954ef.json" const url = process.argv[2] if (!(url && url.startsWith('http'))) { console.log('usage: ./porn.js <addon URL>') process.exit(1) } const vision = require('@google-cloud/vision') const client = new vision.ImageAnnotatorClient() const scoreMap = { UNKNOWN: 0, VERY_UNLIKELY: 0, UNLIKELY: 0, POSSIBLE: 1, LIKELY: 2, VERY_LIKELY: 3 } const threshold = 1.5 detectFromURL(url) .then(function(res) { const manifest = res.addon.manifest return Promise.all(manifest.catalogs.map( cat => res.addon.get('catalog', cat.type, cat.id) .then(x => x.metas) .catch(err => console.error(err)) )) }) .then(function(results) { const everything = results.reduce((a, b) => a.concat(b), []) const sample = shuffle(everything).slice(0, 20) const posters = sample .filter(x => x && x.poster) .map(x => x.poster) return Promise.all( posters.map( url => client.safeSearchDetection(url).then(x => x[0].safeSearchAnnotation) ) ) }) .then(function(results) { const allScores = results .filter(x => x && x.adult) .map(x => scoreMap[x.adult] || 0) // divide by zero warning const avg = allScores.reduce((a, b) => a+b, 0) / allScores.length //console.log(avg) //console.log(allScores) if (avg >= threshold) console.log('IS PORN') else console.log('is not porn') }) function shuffle(arr) { return arr .map(val => ({ sort: Math.random(), val })) .sort((a, b) => a.sort - b.sort) .map(x => x.val) }